fix(build): export the Windows dynamic loader test executable

This commit is contained in:
tototomate123 2026-10-11 11:50:44 +02:00
parent 19b0359f13
commit 4a62b6220b
2 changed files with 12 additions and 4 deletions

View File

@ -163,11 +163,10 @@ if(BUILD_TESTING)
target_link_libraries(guest_dynamic_loader_tests PRIVATE libkernel libc)
configure_windows_unwind(guest_dynamic_loader_tests)
add_dependencies(guest_dynamic_loader_tests guest_module_fixture)
set_target_properties(guest_dynamic_loader_tests PROPERTIES ENABLE_EXPORTS ON)
if(WIN32)
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/GuestDynamicLoader.def" CONTENT "EXPORTS\nGuestDefaultScopeOnly\n")
target_sources(guest_dynamic_loader_tests PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/GuestDynamicLoader.def")
else()
set_target_properties(guest_dynamic_loader_tests PROPERTIES ENABLE_EXPORTS ON)
endif()
add_test(NAME guest_dynamic_loader COMMAND guest_dynamic_loader_tests $<TARGET_FILE_NAME:guest_module_fixture>)
set_tests_properties(guest_dynamic_loader PROPERTIES

View File

@ -1,12 +1,14 @@
#include "prx/libc/include/general/VabiMacros.hpp"
#include <cstdlib>
#include <cstdint>
#include <cstdio>
#include <filesystem>
#include <fstream>
#ifndef _WIN32
#include <dlfcn.h>
#endif
#include <stdexcept>
#include <source_location>
#include <thread>
extern "C" {
int APS5_VABI sceKernelDlsym(std::int32_t, const char*, void**);
@ -17,7 +19,11 @@ char* APS5_VABI dlerror_nid_postfix();
int APS5_VABI _sceKernelRtldThreadAtexitIncrement_nid_postfix(const void*);
int APS5_VABI _sceKernelRtldThreadAtexitDecrement_nid_postfix(const void*);
}
static void Require(bool value) { if (!value) std::abort(); }
static void Require(bool value, const std::source_location& location = std::source_location::current()) {
if (value) return;
std::fprintf(stderr, "guest_dynamic_loader: failed at %s:%u\n", location.file_name(), location.line());
std::abort();
}
extern "C" int APS5_VABI GuestDefaultScopeOnly(int a, int b) { return a * b; }
template<typename TFunction>
static bool ThrowsRuntimeError(TFunction function) {
@ -37,7 +43,9 @@ int main(int argc, char** argv) {
Require(dlopen_nid_postfix("anyps5-missing-module-for-test.prx", 2) == nullptr);
Require(dlerror_nid_postfix() != nullptr);
void* mainSymbol = nullptr;
Require(sceKernelDlsym(0, "GuestDefaultScopeOnly", &mainSymbol) == 0 && mainSymbol != nullptr);
const int mainResult = sceKernelDlsym(0, "GuestDefaultScopeOnly", &mainSymbol);
std::fprintf(stderr, "sceKernelDlsym(0, GuestDefaultScopeOnly): result=0x%08x, symbol=%p\n", static_cast<unsigned>(mainResult), mainSymbol);
Require(mainResult == 0 && mainSymbol != nullptr);
using MainFunction = int (APS5_VABI *)(int, int);
Require(reinterpret_cast<MainFunction>(mainSymbol)(6, 7) == 42);
Require(sceKernelDlsym(0, "anyps5_missing_main_symbol", &mainSymbol) == static_cast<int>(0x80020003u));
@ -117,4 +125,5 @@ int main(int argc, char** argv) {
Require(dlsym_nid_postfix(nullptr, "malloc") == nullptr);
Require(::dlclose(host) == 0);
#endif
std::puts("guest_dynamic_loader: all checks passed");
}