diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 08:38:40 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 08:38:40 -0500 |
| commit | 4e0abc668cf46c1fdce9c4c8fd59b57258d2cab4 (patch) | |
| tree | 75aca1742bfba0d7619daa40aa6a635ca93f090d /runtime/test | |
| parent | 230c0f63dccdda8840fc3247f5aacacee8188791 (diff) | |
| parent | f90a9ead2c150ad519f2bcfe27fa038c70fa95e7 (diff) | |
Merge pull request #1713 from totonii
Diffstat (limited to 'runtime/test')
| -rw-r--r-- | runtime/test/xgameruntime_test.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/runtime/test/xgameruntime_test.cpp b/runtime/test/xgameruntime_test.cpp index 755b64381..ac36f40d9 100644 --- a/runtime/test/xgameruntime_test.cpp +++ b/runtime/test/xgameruntime_test.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <atomic> | 10 | #include <atomic> |
| 11 | #include <cstdint> | 11 | #include <cstdint> |
| 12 | #include <cstdio> | 12 | #include <cstdio> |
| 13 | #include <cstdlib> | ||
| 13 | #include <cstring> | 14 | #include <cstring> |
| 14 | 15 | ||
| 15 | #include <XAsync.h> | 16 | #include <XAsync.h> |
| @@ -98,6 +99,31 @@ HRESULT CALLBACK provider(XAsyncOp op, const XAsyncProviderData* data) { | |||
| 98 | } | 99 | } |
| 99 | } | 100 | } |
| 100 | 101 | ||
| 102 | HMODULE g_teardown_rt_mod = nullptr; | ||
| 103 | FARPROC(WINAPI* g_teardown_get_proc)(HMODULE, LPCSTR) = nullptr; | ||
| 104 | BOOL(WINAPI* g_teardown_free_lib)(HMODULE) = nullptr; | ||
| 105 | |||
| 106 | // Registered with std::atexit before check_run_time_load() constructs any function-local statics in library_loader. | ||
| 107 | // LIFO atexit order means this runs after those statics would have been destroyed, simulating mapped-DLL | ||
| 108 | // DLL_PROCESS_DETACH or earlier atexit handlers calling GetProcAddress/FreeLibrary on a pseudo-handle during exit. | ||
| 109 | void check_late_teardown() { | ||
| 110 | if (!g_teardown_rt_mod || !g_teardown_get_proc || !g_teardown_free_lib) return; | ||
| 111 | if (g_teardown_get_proc(g_teardown_rt_mod, "UninitializeApiImpl") == nullptr) { | ||
| 112 | std::fprintf(stderr, "FAIL late teardown GetProcAddress on pseudo-handle\n"); | ||
| 113 | std::_Exit(1); | ||
| 114 | } | ||
| 115 | SetLastError(0); | ||
| 116 | if (g_teardown_get_proc(g_teardown_rt_mod, "LateTeardownMissingSymbol") != nullptr || | ||
| 117 | GetLastError() != ERROR_PROC_NOT_FOUND) { | ||
| 118 | std::fprintf(stderr, "FAIL late teardown unserved GetProcAddress on pseudo-handle\n"); | ||
| 119 | std::_Exit(1); | ||
| 120 | } | ||
| 121 | if (g_teardown_free_lib(g_teardown_rt_mod) != TRUE) { | ||
| 122 | std::fprintf(stderr, "FAIL late teardown FreeLibrary on pseudo-handle\n"); | ||
| 123 | std::_Exit(1); | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 101 | // xgameruntime.lib's thunks don't import the runtime: they LoadLibraryW(L"xgameruntime.dll") and GetProcAddress five | 127 | // xgameruntime.lib's thunks don't import the runtime: they LoadLibraryW(L"xgameruntime.dll") and GetProcAddress five |
| 102 | // names (measured in the package's libHttpClient.GDK.dll and XCurl.dll). Drive that path through the loader shims, | 128 | // names (measured in the package's libHttpClient.GDK.dll and XCurl.dll). Drive that path through the loader shims, |
| 103 | // bound by the api set XCurl.dll imports them from, as a mapped image would be. | 129 | // bound by the api set XCurl.dll imports them from, as a mapped image would be. |
| @@ -136,6 +162,9 @@ void check_run_time_load() { | |||
| 136 | SetLastError(0); | 162 | SetLastError(0); |
| 137 | check(get_proc(rt_mod, "NoSuchRuntimeFunction") == nullptr && GetLastError() == ERROR_PROC_NOT_FOUND, | 163 | check(get_proc(rt_mod, "NoSuchRuntimeFunction") == nullptr && GetLastError() == ERROR_PROC_NOT_FOUND, |
| 138 | "an unserved name is NULL with ERROR_PROC_NOT_FOUND, as from a real module"); | 164 | "an unserved name is NULL with ERROR_PROC_NOT_FOUND, as from a real module"); |
| 165 | SetLastError(0); | ||
| 166 | check(get_proc(rt_mod, nullptr) == nullptr && GetLastError() == ERROR_PROC_NOT_FOUND, | ||
| 167 | "a null proc name is NULL with ERROR_PROC_NOT_FOUND"); | ||
| 139 | 168 | ||
| 140 | struct Options { | 169 | struct Options { |
| 141 | uint32_t unknown; | 170 | uint32_t unknown; |
| @@ -162,6 +191,10 @@ void check_run_time_load() { | |||
| 162 | "GetProcAddress on a host module is the host's"); | 191 | "GetProcAddress on a host module is the host's"); |
| 163 | check(free_lib(rt_mod) == TRUE && load_w(L"xgameruntime.dll") == rt_mod, | 192 | check(free_lib(rt_mod) == TRUE && load_w(L"xgameruntime.dll") == rt_mod, |
| 164 | "FreeLibrary on the runtime succeeds and keeps it loaded"); | 193 | "FreeLibrary on the runtime succeeds and keeps it loaded"); |
| 194 | |||
| 195 | g_teardown_rt_mod = rt_mod; | ||
| 196 | g_teardown_get_proc = get_proc; | ||
| 197 | g_teardown_free_lib = free_lib; | ||
| 165 | } | 198 | } |
| 166 | 199 | ||
| 167 | } // namespace | 200 | } // namespace |
| @@ -262,6 +295,7 @@ int main() { | |||
| 262 | check(init() == S_OK, "XGameRuntimeInitialize works again after balanced uninitialize calls"); | 295 | check(init() == S_OK, "XGameRuntimeInitialize works again after balanced uninitialize calls"); |
| 263 | uninit(); | 296 | uninit(); |
| 264 | 297 | ||
| 298 | std::atexit(check_late_teardown); | ||
| 265 | check_run_time_load(); | 299 | check_run_time_load(); |
| 266 | 300 | ||
| 267 | if (g_failures) { | 301 | if (g_failures) { |