diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 07:08:00 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 07:08:00 -0500 |
| commit | 81f26eefc8f36fcb302c0ca0cd6a73e3511a5b87 (patch) | |
| tree | edf6a2144ba4427e967d75a6ff64790b9a7a7a1e /runtime | |
| parent | 79dd9fc067dcbf52c3f9bf0b62cba17e91765c5e (diff) | |
| parent | eef61a04c09eb5c3bccb1b79d21e2934f4941ddd (diff) | |
Merge pull request #1517 from Dominik
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | runtime/test/check_loaded_gdk.cmake | 14 | ||||
| -rw-r--r-- | runtime/test/fixtures/tiny_gdk_load.cpp | 71 |
3 files changed, 95 insertions, 0 deletions
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 466113a3d..5a175fd94 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt | |||
| @@ -365,6 +365,13 @@ if(BUILD_TESTING) | |||
| 365 | set_target_properties(tiny_async PROPERTIES | 365 | set_target_properties(tiny_async PROPERTIES |
| 366 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/fixtures/game/$<CONFIG>" | 366 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/fixtures/game/$<CONFIG>" |
| 367 | ) | 367 | ) |
| 368 | # Reaches xgameruntime.dll through LoadLibraryW/GetProcAddress, as xgameruntime.lib's thunks do (no import). | ||
| 369 | add_executable(tiny_gdk_load test/fixtures/tiny_gdk_load.cpp) | ||
| 370 | target_compile_definitions(tiny_gdk_load PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX) | ||
| 371 | target_compile_options(tiny_gdk_load PRIVATE /W4 /permissive- /utf-8) | ||
| 372 | set_target_properties(tiny_gdk_load PROPERTIES | ||
| 373 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/fixtures/game/$<CONFIG>" | ||
| 374 | ) | ||
| 368 | add_executable(tiny_game test/fixtures/tiny_game.cpp) | 375 | add_executable(tiny_game test/fixtures/tiny_game.cpp) |
| 369 | target_link_libraries(tiny_game PRIVATE xgameruntime_stub) | 376 | target_link_libraries(tiny_game PRIVATE xgameruntime_stub) |
| 370 | target_compile_definitions(tiny_game PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX _CRT_SECURE_NO_WARNINGS) # plain fopen, as games use | 377 | target_compile_definitions(tiny_game PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX _CRT_SECURE_NO_WARNINGS) # plain fopen, as games use |
| @@ -556,6 +563,9 @@ if(BUILD_TESTING) | |||
| 556 | add_test(NAME run_tiny_async COMMAND ${CMAKE_COMMAND} | 563 | add_test(NAME run_tiny_async COMMAND ${CMAKE_COMMAND} |
| 557 | "-DLOADER=$<TARGET_FILE:gta6rt>" "-DGUEST=$<TARGET_FILE:tiny_async>" | 564 | "-DLOADER=$<TARGET_FILE:gta6rt>" "-DGUEST=$<TARGET_FILE:tiny_async>" |
| 558 | "-DRUNNER=${CMAKE_CROSSCOMPILING_EMULATOR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/test/check_loaded_async.cmake") | 565 | "-DRUNNER=${CMAKE_CROSSCOMPILING_EMULATOR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/test/check_loaded_async.cmake") |
| 566 | add_test(NAME run_tiny_gdk_load COMMAND ${CMAKE_COMMAND} | ||
| 567 | "-DLOADER=$<TARGET_FILE:gta6rt>" "-DGUEST=$<TARGET_FILE:tiny_gdk_load>" | ||
| 568 | "-DRUNNER=${CMAKE_CROSSCOMPILING_EMULATOR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/test/check_loaded_gdk.cmake") | ||
| 559 | # The stand-in game passes only with its own arguments; with others it exits 1, which --run passes through. | 569 | # The stand-in game passes only with its own arguments; with others it exits 1, which --run passes through. |
| 560 | add_test(NAME run_tiny_game COMMAND gta6rt --run $<TARGET_FILE:tiny_game> -- hello 42) | 570 | add_test(NAME run_tiny_game COMMAND gta6rt --run $<TARGET_FILE:tiny_game> -- hello 42) |
| 561 | add_test(NAME run_tiny_game_exit_code COMMAND gta6rt --run $<TARGET_FILE:tiny_game> -- wrong args) | 571 | add_test(NAME run_tiny_game_exit_code COMMAND gta6rt --run $<TARGET_FILE:tiny_game> -- wrong args) |
diff --git a/runtime/test/check_loaded_gdk.cmake b/runtime/test/check_loaded_gdk.cmake new file mode 100644 index 000000000..0df68a1d8 --- /dev/null +++ b/runtime/test/check_loaded_gdk.cmake | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | # Run the run-time GDK load fixture (tiny_gdk_load) under the loader and check its verdict from outside, as | ||
| 2 | # check_loaded_async.cmake does: under Wine an exit status alone can look successful even when the guest failed. | ||
| 3 | get_filename_component(guest_dir "${GUEST}" DIRECTORY) | ||
| 4 | get_filename_component(guest_name "${GUEST}" NAME) | ||
| 5 | execute_process( | ||
| 6 | COMMAND ${RUNNER} "${LOADER}" --run "${guest_name}" | ||
| 7 | WORKING_DIRECTORY "${guest_dir}" | ||
| 8 | TIMEOUT 90 | ||
| 9 | RESULT_VARIABLE code OUTPUT_VARIABLE output ERROR_VARIABLE output) | ||
| 10 | string(REPLACE "\r\n" "\n" output "${output}") | ||
| 11 | if(NOT code STREQUAL "0" OR NOT output MATCHES "(^|\n)tiny_gdk_load: PASS(\n|$)" | ||
| 12 | OR NOT output MATCHES "(^|\n)game exited with code 0(\n|$)") | ||
| 13 | message(FATAL_ERROR "Loaded GDK run-time fixture returned ${code}\n${output}") | ||
| 14 | endif() | ||
diff --git a/runtime/test/fixtures/tiny_gdk_load.cpp b/runtime/test/fixtures/tiny_gdk_load.cpp new file mode 100644 index 000000000..780b10edb --- /dev/null +++ b/runtime/test/fixtures/tiny_gdk_load.cpp | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | // A mapped program that reaches the GDK runtime the way xgameruntime.lib's thunks do: it has no import of | ||
| 2 | // xgameruntime.dll, loads it with LoadLibraryW and looks the five run-time entry points up with GetProcAddress | ||
| 3 | // (measured in the package's libHttpClient.GDK.dll and XCurl.dll, docs/runtime_imports.md "Run-time loaded | ||
| 4 | // modules"). Run under `gta6rt --run`, its own kernel32 imports are bound by the loader, so LoadLibraryW and | ||
| 5 | // GetProcAddress must reach runtime/shims/library_loader.cpp and the offline xgameruntime shim. Run on its own, | ||
| 6 | // LoadLibraryW goes to Windows and either fails or loads the PC's Gaming Services runtime, and this never prints | ||
| 7 | // PASS. Ordinary test code; no game data. | ||
| 8 | #include <windows.h> | ||
| 9 | |||
| 10 | #include <cstdio> | ||
| 11 | |||
| 12 | namespace { | ||
| 13 | |||
| 14 | struct Options { // InitializeApiImplEx2's fourth argument (xodus-gaming/xgameruntime-docs) | ||
| 15 | UINT32 unknown; // documented as always 1 | ||
| 16 | BOOL is_inline; | ||
| 17 | const char* game_config; | ||
| 18 | }; | ||
| 19 | |||
| 20 | using InitEx2 = HRESULT(WINAPI*)(ULONG, ULONG, char, const Options*); | ||
| 21 | using Query = HRESULT(WINAPI*)(const GUID*, REFIID, void**); | ||
| 22 | using Uninit = HRESULT(WINAPI*)(); | ||
| 23 | |||
| 24 | int fail(const char* stage, unsigned long value) { | ||
| 25 | std::printf("tiny_gdk_load: FAIL %s (0x%08lx)\n", stage, value); | ||
| 26 | return 1; | ||
| 27 | } | ||
| 28 | |||
| 29 | } // namespace | ||
| 30 | |||
| 31 | int main() { | ||
| 32 | HMODULE runtime = LoadLibraryW(L"xgameruntime.dll"); | ||
| 33 | if (!runtime) return fail("LoadLibraryW(xgameruntime.dll)", GetLastError()); | ||
| 34 | // The loader shim hands out a pseudo-handle for a module it owns: not an image the host loaded. | ||
| 35 | HMODULE host_view = nullptr; | ||
| 36 | if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, L"xgameruntime.dll", &host_view) && host_view == runtime) | ||
| 37 | return fail("xgameruntime.dll came from the host loader, not the shims", 0); | ||
| 38 | |||
| 39 | const char* names[] = {"InitializeApiImpl", "InitializeApiImplEx", "InitializeApiImplEx2", "UninitializeApiImpl", | ||
| 40 | "QueryApiImpl"}; | ||
| 41 | for (const char* name : names) | ||
| 42 | if (!GetProcAddress(runtime, name)) return fail(name, GetLastError()); | ||
| 43 | SetLastError(0); | ||
| 44 | if (GetProcAddress(runtime, "NoSuchRuntimeFunction") || GetLastError() != ERROR_PROC_NOT_FOUND) | ||
| 45 | return fail("an unserved name is NULL with ERROR_PROC_NOT_FOUND", GetLastError()); | ||
| 46 | |||
| 47 | auto init = reinterpret_cast<InitEx2>(GetProcAddress(runtime, "InitializeApiImplEx2")); | ||
| 48 | auto query = reinterpret_cast<Query>(GetProcAddress(runtime, "QueryApiImpl")); | ||
| 49 | auto uninit = reinterpret_cast<Uninit>(GetProcAddress(runtime, "UninitializeApiImpl")); | ||
| 50 | const Options options{1, FALSE, nullptr}; | ||
| 51 | HRESULT hr = init(0, 0, 0x02, &options); | ||
| 52 | if (hr != S_OK) return fail("InitializeApiImplEx2", static_cast<unsigned long>(hr)); | ||
| 53 | |||
| 54 | // XThreadingImpl, the first class XCurl.dll references (docs/runtime_imports.md); not provided offline yet. | ||
| 55 | const GUID threading = {0x073b7dcb, 0x1fcf, 0x4030, {0x94, 0xbe, 0xe3, 0xc9, 0xeb, 0x62, 0x34, 0x28}}; | ||
| 56 | void* out = reinterpret_cast<void*>(1); | ||
| 57 | hr = query(&threading, threading, &out); | ||
| 58 | if (hr != static_cast<HRESULT>(0x80070032) || out != nullptr) | ||
| 59 | return fail("QueryApiImpl refuses an unprovided class and clears its out pointer", static_cast<unsigned long>(hr)); | ||
| 60 | hr = uninit(); | ||
| 61 | if (hr != S_OK) return fail("UninitializeApiImpl", static_cast<unsigned long>(hr)); | ||
| 62 | |||
| 63 | // Host modules still come from the host. | ||
| 64 | HMODULE k32 = LoadLibraryW(L"kernel32.dll"); | ||
| 65 | if (!k32 || GetProcAddress(k32, "GetTickCount") != GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetTickCount")) | ||
| 66 | return fail("kernel32.dll from the host", GetLastError()); | ||
| 67 | if (!FreeLibrary(runtime)) return fail("FreeLibrary(xgameruntime.dll)", GetLastError()); | ||
| 68 | |||
| 69 | std::puts("tiny_gdk_load: PASS"); | ||
| 70 | return 0; | ||
| 71 | } | ||