upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/xgameruntime_test.cpp
diff options
context:
space:
mode:
authorVonsek <45567075+Vonsek@users.noreply.github.com>2026-11-22 15:51:40 +0100
committerVonsek <45567075+Vonsek@users.noreply.github.com>2026-11-22 15:51:40 +0100
commitdf91c6624b69ee4e6c6eeca20ed68d331ed0e728 (patch)
tree323c88b9df89bf8abaa2b98d10808474ab675dc2 /runtime/test/xgameruntime_test.cpp
parentb40d8039a98f57b26bd05860febbabbe59b97873 (diff)
parent6a6704df1592e1dc4a3215ddf1423a78adb52045 (diff)
Merge main into test/valu-int-misc (#1492)
Conflicted files: runtime/test/shaders/check.py, scripts/run_gpu_tests.py AI-assisted.
Diffstat (limited to 'runtime/test/xgameruntime_test.cpp')
-rw-r--r--runtime/test/xgameruntime_test.cpp34
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
102HMODULE g_teardown_rt_mod = nullptr;
103FARPROC(WINAPI* g_teardown_get_proc)(HMODULE, LPCSTR) = nullptr;
104BOOL(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.
109void 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) {