From 81677234b736649bda6f60b0fa9806edc1c8644f Mon Sep 17 00:00:00 2001 From: milk4sale <53350507+milk4sale@users.noreply.github.com> Date: Tue, 24 Nov 2026 10:10:42 -0600 Subject: [PATCH] Tests: seven runtime tests say what Wine's libraries answer and still check the shim (TEST-WINE-RUNTIME-TESTS) Under Wine these tests failed on what Wine's own libraries do, not on the shim or the loader they are there to check: - bcrypt_rng, bcrypt_rng_seeded: the shim hands back the host's status for an algorithm it does not serve, and Wine's bcrypt answers 0xC0000002 for an unknown name where Microsoft's answers STATUS_NOT_FOUND. The test now compares the shim with the host, asked directly, and checks the value itself wherever the host is not Wine. - gameinput_host: Wine's GameInput.dll loads and its GameInputCreate answers E_NOTIMPL. The import binding is still checked; the calls into the library are skipped there. - root_sig: Wine's deserializer refuses a container whose checksum is zeroed. The host is asked about the cleared copy directly, and Wine's refusal, and only Wine's, skips that one check. - run_startup_cmdline: the native control cannot hold through an emulator, because Wine's ucrtbase has __argc, __argv and __wargv set before process attach. It is reported and not required when a RUNNER is set; the run through gta6rt is checked on every host. - dstorage: the guard page is the middle one of three, so it cannot start at the reading thread's StackBase, where Wine drops the guard without raising anything. No host check. - xmem: Wine raises no fault on the first write to a SEC_RESERVE view and keeps reporting MEM_RESERVE, so xmem's first-touch handler never runs. There the page is committed with rt::xmem::commit_physical_range and the bytes written before must still be there. host_wine.h gets is_wine(), the host check with nothing printed. docs/linux.md lists the measured differences and docs/testing.md points to it. Tests and docs only. Co-Authored-By: Claude Fable 5.2 --- docs/linux.md | 32 ++++++++++++++ docs/testing.md | 5 ++- runtime/test/bcrypt_rng_test.cpp | 29 ++++++++++++- runtime/test/check_startup_cmdline.cmake | 10 ++++- runtime/test/dstorage_test.cpp | 9 +++- runtime/test/gameinput_host_test.cpp | 53 +++++++++++++++++------- runtime/test/host_wine.h | 9 +++- runtime/test/root_sig_test.cpp | 24 ++++++++--- runtime/test/xmem_test.cpp | 22 +++++++++- 9 files changed, 163 insertions(+), 30 deletions(-) diff --git a/docs/linux.md b/docs/linux.md index e7ca27455f..9785fbcd0d 100644 --- a/docs/linux.md +++ b/docs/linux.md @@ -83,6 +83,38 @@ Runtime workflow. The stage writes `/gta6rt.sh`, which starts `gta6rt.exe` [testing.md](testing.md#the-windows-runtime-on-linux-under-wine-or-proton) has the test runs under Wine and Proton and what fails there. +### What Wine answers differently + +Every import the loader does not shim binds to the host's DLLs, and under Wine those are Wine's own. A few of them +answer differently from what the runtime's tests see on Windows. Measured on 2026-11-24 with wine-staging 11.21, a +clang-cl and xwin build and an RTX 4070 Ti. A test that meets one of these prints a `SKIP` line saying what the host +did, or avoids the difference on every host, and still checks the shim or the loader: + +- **bcrypt**: `BCryptOpenAlgorithmProvider` answers `0xC0000002` for an algorithm name it does not know, where + Windows answers `STATUS_NOT_FOUND`. The shim hands the host's status back, so `bcrypt_rng` compares the two. +- **GameInput**: Wine's `GameInput.dll` loads, and its `GameInputCreate` answers `E_NOTIMPL`. `gameinput_host` checks + the import binding and skips the calls; a boot needs the SDL3-backed shim ([gameinput.md](gameinput.md)). +- **Root signatures**: `D3D12CreateRootSignatureDeserializer` refuses a container whose checksum is zeroed + (`E_INVALIDARG`) and accepts the same container with its checksum intact; Windows accepts both. `root_sig` skips + that one check. +- **C runtime startup**: Wine's `ucrtbase` has `__argc`, `__argv` and `__wargv` set before process attach. The + fixture of `run_startup_cmdline` expects them unset there, as on Windows, so its native control does not hold + through an emulator and is not required; the run through `gta6rt` is checked on every host. +- **Reserve-only section views**: the first write to a `SEC_RESERVE` view goes through with no fault, and + `VirtualQuery` keeps reporting `MEM_RESERVE` for the page until something commits it. On Windows that write faults + and the XMem shim commits the page in its handler, which therefore never runs under Wine: a page the title has + written is usable there and still reported as reserved. `xmem` commits it with `rt::xmem::commit_physical_range`, + the call the runtime makes before it imports title memory, and checks that the bytes written before are kept. +- **Guard pages**: a `PAGE_GUARD` page that starts exactly at the reading thread's `StackBase` loses its guard with + nothing raised; one page higher, the exception arrives. `dstorage` keeps its guard page inside an allocation of + its own, on every host. + +Two more differences still failed tests on that date. A file handle opened with `MAXIMUM_ALLOWED` reads and cannot +write (`WriteFile` fails with error 6), and the file-system shim passes that mask to the host: six checks of +`file_system`. The adapter `EnumWarpAdapter` returns is the hardware one, and `D3D12CreateDevice` on it succeeds at +feature level 11_0 and answers `E_INVALIDARG` at 12_0 and 12_1: `device_proxy` and `device_proxy_trace` stop at device +creation. + ### Why there is no native Linux `gta6rt` A native (ELF) loader is not a matter of build flags: diff --git a/docs/testing.md b/docs/testing.md index 04a5af1805..e4ed471882 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -278,8 +278,9 @@ returns the hardware adapter, so "WARP" is vkd3d-proton on the GPU. Most tests t skip that comparison under Wine and Proton (`runtime/test/host_wine.h`), and most of them still check the layer against Microsoft's answers recorded in the test (`d3d12_subresource_copy` and `d3d12_private_data` keep theirs in `d3d12_subresource_copy_answers.h` and `d3d12_private_data_answers.h`). -A few still compare with the host (`root_sig`, `device_proxy`, and some of `d3d12_vulkan_device`'s cases), so some -of those fail for that reason. +A few still compare with the host (`device_proxy`, and some of `d3d12_vulkan_device`'s cases), so some of those fail +for that reason. [linux.md](linux.md#what-wine-answers-differently) lists what Wine's other libraries answer +differently and which tests skip a check for it. ### Run a Windows CI artifact under Wine diff --git a/runtime/test/bcrypt_rng_test.cpp b/runtime/test/bcrypt_rng_test.cpp index ffdd701559..7e9093fcd6 100644 --- a/runtime/test/bcrypt_rng_test.cpp +++ b/runtime/test/bcrypt_rng_test.cpp @@ -10,6 +10,7 @@ using NTSTATUS = LONG; #include #include +#include "host_wine.h" #include "shims.h" namespace rt::bcrypt_rng { @@ -42,6 +43,12 @@ Fn resolve(const char* name) { return reinterpret_cast(rt::shims::find("bcrypt.dll", name)); } +// The host's own BCryptOpenAlgorithmProvider, found the way the shim finds it. Null on a host with no bcrypt.dll. +OpenAlgFn host_open_algorithm_provider() { + const HMODULE bcrypt = LoadLibraryExW(L"bcrypt.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); + return bcrypt ? reinterpret_cast(GetProcAddress(bcrypt, "BCryptOpenAlgorithmProvider")) : nullptr; +} + void test_registry_coverage() { check(resolve("BCryptOpenAlgorithmProvider") != nullptr, "BCryptOpenAlgorithmProvider resolves"); check(resolve("BCryptGenRandom") != nullptr, "BCryptGenRandom resolves"); @@ -58,8 +65,26 @@ void test_provider_handles_and_validation() { "BCryptOpenAlgorithmProvider rejects null out handle"); check(open_alg(&h, nullptr, nullptr, 0) == kStatusInvalidParameter, "BCryptOpenAlgorithmProvider rejects null algorithm id"); - check(open_alg(&h, L"LEONIDA_NO_SUCH_ALG", nullptr, 0) == kStatusNotFound, - "BCryptOpenAlgorithmProvider reports STATUS_NOT_FOUND for unknown algorithm"); + // An algorithm the shim does not serve is the host's to answer, and the shim hands the host's status back (with + // no host bcrypt it says STATUS_NOT_FOUND itself). Microsoft's bcrypt answers STATUS_NOT_FOUND for a name it does + // not know and Wine's answers 0xC0000002 (STATUS_NOT_IMPLEMENTED, wine-staging 11.21), so the shim is compared + // with the host, asked directly, and the value itself is checked wherever the host is not Wine. + NTSTATUS host_unknown = kStatusNotFound; + if (const OpenAlgFn host_open = host_open_algorithm_provider()) { + BCRYPT_ALG_HANDLE host_handle = nullptr; + host_unknown = host_open(&host_handle, L"LEONIDA_NO_SUCH_ALG", nullptr, 0); + } + const NTSTATUS shim_unknown = open_alg(&h, L"LEONIDA_NO_SUCH_ALG", nullptr, 0); + check(shim_unknown < 0 && shim_unknown == host_unknown && h == nullptr, + "BCryptOpenAlgorithmProvider reports the host's failure for an unknown algorithm"); + if (hostwine::is_wine() && host_unknown != kStatusNotFound) { + std::printf("SKIP BCryptOpenAlgorithmProvider reports STATUS_NOT_FOUND for unknown algorithm (Wine's bcrypt " + "answers 0x%08lX)\n", + static_cast(host_unknown)); + } else { + check(shim_unknown == kStatusNotFound, + "BCryptOpenAlgorithmProvider reports STATUS_NOT_FOUND for unknown algorithm"); + } check(open_alg(&h, BCRYPT_RNG_ALGORITHM, nullptr, 0) == kStatusSuccess && h != nullptr, "BCryptOpenAlgorithmProvider opens BCRYPT_RNG_ALGORITHM"); diff --git a/runtime/test/check_startup_cmdline.cmake b/runtime/test/check_startup_cmdline.cmake index d2c315f032..a8f03ebc3e 100644 --- a/runtime/test/check_startup_cmdline.cmake +++ b/runtime/test/check_startup_cmdline.cmake @@ -5,11 +5,19 @@ foreach(mode args no_args fail_init) elseif(mode STREQUAL "fail_init") set(args fail-init) endif() + # The native run is the control: it shows that what the fixture expects at process attach is what Microsoft's UCRT + # does. Through an emulator (RUNNER, the cross build's Wine) the C runtime is the emulator's own, and Wine's ucrtbase + # has __argc, __argv and __wargv set before process attach (wine-staging 11.21), so the control cannot hold there: + # it is reported and not required. The run through the loader below is checked on every host. if(NOT mode STREQUAL "fail_init") execute_process(COMMAND ${RUNNER} "${GUEST}" ${args} TIMEOUT 90 RESULT_VARIABLE native_code OUTPUT_VARIABLE native_output ERROR_VARIABLE native_error) if(NOT native_code STREQUAL "0" OR NOT native_output MATCHES "tiny_startup_cmdline: PASS") - message(FATAL_ERROR "Native startup command line (${mode}) returned ${native_code}\n${native_output}\n${native_error}") + if("${RUNNER}" STREQUAL "") + message(FATAL_ERROR "Native startup command line (${mode}) returned ${native_code}\n${native_output}\n${native_error}") + endif() + message(STATUS "SKIP the native control (${mode}): it returned ${native_code} through ${RUNNER}, " + "whose C runtime is not Microsoft's") endif() endif() execute_process( diff --git a/runtime/test/dstorage_test.cpp b/runtime/test/dstorage_test.cpp index 1e8ea73183..58fe0d3aed 100644 --- a/runtime/test/dstorage_test.cpp +++ b/runtime/test/dstorage_test.cpp @@ -921,7 +921,12 @@ void test_stats_timing(Env& env) { if (!q) return; IDStorageStatusArrayX* s = make_status(env, 1); GuardHold hold; - hold.page = static_cast(VirtualAlloc(nullptr, 4096, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)); + // The guard page is the middle one of three, so the page below it is this allocation's own. An allocation of one + // page can land right above the queue worker's stack, and Wine drops the guard of a page that starts at the + // reading thread's StackBase without raising anything (wine-staging 11.21): the copy then never stops here. + auto* const pages = + static_cast(VirtualAlloc(nullptr, 3 * 4096, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)); + hold.page = pages ? pages + 4096 : nullptr; hold.entered = CreateEventW(nullptr, TRUE, FALSE, nullptr); hold.release = CreateEventW(nullptr, TRUE, FALSE, nullptr); if (!hold.page || !hold.entered || !hold.release) { @@ -964,7 +969,7 @@ void test_stats_timing(Env& env) { g_hold = nullptr; CloseHandle(hold.entered); CloseHandle(hold.release); - VirtualFree(hold.page, 0, MEM_RELEASE); + VirtualFree(pages, 0, MEM_RELEASE); s->Release(); q->Release(); } diff --git a/runtime/test/gameinput_host_test.cpp b/runtime/test/gameinput_host_test.cpp index cdd0710558..f7923a4d3e 100644 --- a/runtime/test/gameinput_host_test.cpp +++ b/runtime/test/gameinput_host_test.cpp @@ -8,13 +8,18 @@ // GetGamepadState must succeed on the reading; the test passes with or without one. // Skips (exit 77) only where Windows itself cannot load GameInput.dll (asked before mapping, with LoadLibraryExW). // When the DLL is there, an import that binds to nothing is a failure, not a skip. No game files. +// +// Wine has a GameInput.dll of its own that loads and implements nothing: its GameInputCreate answers E_NOTIMPL +// (wine-staging 11.21). There the import binding is still checked, and the calls into the library are skipped. #include +#include #include #include #include #include +#include "host_wine.h" #include "pe_loader.h" namespace { @@ -51,6 +56,18 @@ int main(int argc, char** argv) { return 1; } + // Asked of the host's DLL directly and before anything is mapped, for the same reason: what is skipped must not + // depend on the loader's answer. On Windows nothing is asked, and every failure below stays a failure. + bool host_is_a_stub = false; + if (hostwine::is_wine()) { + using CreateFn = HRESULT(WINAPI*)(IUnknown**); + if (const auto create = reinterpret_cast(GetProcAddress(host_gameinput, "GameInputCreate"))) { + IUnknown* input = nullptr; + host_is_a_stub = create(&input) == E_NOTIMPL; + if (input) input->Release(); + } + } + try { rt::Loader loader(fixture.parent_path()); rt::Module& m = loader.load(fixture); @@ -65,21 +82,27 @@ int main(int argc, char** argv) { } check(seen == 1 && binding == rt::Binding::Host, "the GameInput.dll import binds to the host's copy"); - loader.initialise(); - const auto probe = reinterpret_cast(m.exports.at("gameinput_host_probe")); - long create_hr = -1, reading_hr = -1; - unsigned long long timestamp = 0; - int state_ok = 0; - const int created = probe(&create_hr, ×tamp, &reading_hr, &state_ok); - std::printf(" create hr=0x%08lX, timestamp=%llu, reading hr=0x%08lX\n", static_cast(create_hr), - timestamp, static_cast(reading_hr)); - check(created == 1 && create_hr == 0, "GameInputCreate succeeds from mapped code"); - check(timestamp != 0, "GetCurrentTimestamp returns a time"); - const bool pad = created == 1 && reading_hr == 0; - check(pad || static_cast(reading_hr) == kReadingNotFound, - "GetCurrentReading says either 'reading' or 'no reading found'"); - std::printf(" gamepad reading: %s\n", pad ? "yes (a gamepad is attached)" : "none (no gamepad attached)"); - if (pad) check(state_ok == 1, "GetGamepadState succeeds on a real reading"); + if (host_is_a_stub) { + std::printf("SKIP the calls into GameInput.dll (Wine's has no implementation: GameInputCreate answers " + "E_NOTIMPL)\n"); + } else { + loader.initialise(); + const auto probe = reinterpret_cast(m.exports.at("gameinput_host_probe")); + long create_hr = -1, reading_hr = -1; + unsigned long long timestamp = 0; + int state_ok = 0; + const int created = probe(&create_hr, ×tamp, &reading_hr, &state_ok); + std::printf(" create hr=0x%08lX, timestamp=%llu, reading hr=0x%08lX\n", + static_cast(create_hr), timestamp, static_cast(reading_hr)); + check(created == 1 && create_hr == 0, "GameInputCreate succeeds from mapped code"); + check(timestamp != 0, "GetCurrentTimestamp returns a time"); + const bool pad = created == 1 && reading_hr == 0; + check(pad || static_cast(reading_hr) == kReadingNotFound, + "GetCurrentReading says either 'reading' or 'no reading found'"); + std::printf(" gamepad reading: %s\n", + pad ? "yes (a gamepad is attached)" : "none (no gamepad attached)"); + if (pad) check(state_ok == 1, "GetGamepadState succeeds on a real reading"); + } } catch (const std::exception& e) { std::printf("FAIL unexpected exception: %s\n", e.what()); ++g_failures; diff --git a/runtime/test/host_wine.h b/runtime/test/host_wine.h index c647b8877f..db6e6e0bca 100644 --- a/runtime/test/host_wine.h +++ b/runtime/test/host_wine.h @@ -12,8 +12,15 @@ namespace hostwine { -inline bool host_is_wine() { +// Whether the host is Wine, with nothing printed: for the tests of other host libraries (bcrypt, GameInput, the +// memory manager), which say themselves what Wine answers differently. +inline bool is_wine() { static const bool wine = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "wine_get_version") != nullptr; + return wine; +} + +inline bool host_is_wine() { + const bool wine = is_wine(); static bool said = false; if (wine && !said) std::printf("host D3D12 is Wine's, not Microsoft's: comparisons with the host are skipped\n"); said = true; diff --git a/runtime/test/root_sig_test.cpp b/runtime/test/root_sig_test.cpp index ac65075eed..84138aade6 100644 --- a/runtime/test/root_sig_test.cpp +++ b/runtime/test/root_sig_test.cpp @@ -11,6 +11,7 @@ #include #include "d3d12_xs_rootsig.h" +#include "host_wine.h" #include "shims.h" namespace { @@ -559,11 +560,24 @@ void test_deserializer() { check(rewrote && out.size() == zero_hash.size() && std::memcmp(out.data() + 4, kZero, 16) == 0, "blob helper rewrites an all-zero-checksum Xbox blob and keeps its zero checksum"); - ID3D12RootSignatureDeserializer* shim_zero = nullptr; - const HRESULT hr_zero = deserialize(zero_hash.data(), zero_hash.size(), IID_PPV_ARGS(&shim_zero)); - check(SUCCEEDED(hr_zero) && shim_zero && shim_zero->GetRootSignatureDesc()->Flags == 0, - "shim deserializer accepts an all-zero-checksum Xbox blob with the high byte cleared"); - if (shim_zero) shim_zero->Release(); + // The shim forwards the cleared copy, so it can accept the blob only where the host takes a zero checksum. + // Microsoft's deserializer does. Wine's (vkd3d) refuses a container whose checksum is zeroed with E_INVALIDARG + // and takes the same one with its checksum intact (wine-staging 11.21), so the host is asked about the cleared + // copy directly, and Wine's refusal, and only Wine's, skips the check. + ID3D12RootSignatureDeserializer* host_zero = nullptr; + const HRESULT hr_host_zero = + D3D12CreateRootSignatureDeserializer(out.data(), out.size(), IID_PPV_ARGS(&host_zero)); + if (host_zero) host_zero->Release(); + if (FAILED(hr_host_zero) && hostwine::is_wine()) { + std::printf("SKIP shim deserializer accepts an all-zero-checksum Xbox blob with the high byte cleared " + "(Wine's deserializer refuses a zero checksum)\n"); + } else { + ID3D12RootSignatureDeserializer* shim_zero = nullptr; + const HRESULT hr_zero = deserialize(zero_hash.data(), zero_hash.size(), IID_PPV_ARGS(&shim_zero)); + check(SUCCEEDED(hr_zero) && shim_zero && shim_zero->GetRootSignatureDesc()->Flags == 0, + "shim deserializer accepts an all-zero-checksum Xbox blob with the high byte cleared"); + if (shim_zero) shim_zero->Release(); + } } } diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp index bf5bd36389..ae1bb16921 100644 --- a/runtime/test/xmem_test.cpp +++ b/runtime/test/xmem_test.cpp @@ -22,6 +22,7 @@ #include #include +#include "host_wine.h" #include "shims.h" #include "startup_trace.h" #include "xmem.h" @@ -334,6 +335,21 @@ bool reserved_only(const void* address) { return VirtualQuery(address, &info, sizeof(info)) && info.State == MEM_RESERVE; } +// Whether the write the caller has just made to the mapped page at `page` left it committed. On Windows a +// reserve-only view raises on its first touch and xmem's handler commits the page. Wine lets that write through with +// no fault and goes on reporting MEM_RESERVE for the view (wine-staging 11.21), so the handler never runs there: +// under Wine the page is committed here, through the call the runtime makes before it hands title memory to the GPU, +// and what was written must still be there. The checks that follow then see a committed view on both hosts. +bool committed_by_first_touch(const void* page) { + MEMORY_BASIC_INFORMATION info{}; + if (VirtualQuery(page, &info, sizeof(info)) && info.State == MEM_COMMIT) return true; + if (!hostwine::is_wine()) return false; + std::printf("SKIP the first touch commits the page (Wine raises no fault on a reserve-only view); " + "committed with commit_physical_range\n"); + const uint32_t written = read_u32(page, 0); + return rt::xmem::commit_physical_range(page, kPage64k) && read_u32(page, 0) == written; +} + struct PhysicalApi { XMemVirtualAllocFn virtual_alloc; XMemAllocatePhysicalPagesFn allocate; @@ -369,9 +385,10 @@ void test_physical_pages(const PhysicalApi& api) { check(api.map(window, kPages, pages) == window, "XMemMapPhysicalPages returns the address it mapped"); for (uint64_t i = 0; i < kPages; ++i) fill_page(window + i * kPage64k, 0x1000u * static_cast(i + 1)); { + const bool committed = committed_by_first_touch(window); MEMORY_BASIC_INFORMATION info{}; VirtualQuery(window, &info, sizeof(info)); - check(info.State == MEM_COMMIT && info.Type == MEM_MAPPED && info.Protect == PAGE_READWRITE, + check(committed && info.State == MEM_COMMIT && info.Type == MEM_MAPPED && info.Protect == PAGE_READWRITE, "a mapped page is a read-write view with the window's protection"); } @@ -713,9 +730,10 @@ void test_write_combine_window(const PhysicalApi& api) { if (mapped) { // Physical pages are committed on first touch, so the view is written before it is queried. *static_cast(window) = 1; + const bool committed = committed_by_first_touch(window); MEMORY_BASIC_INFORMATION info{}; VirtualQuery(window, &info, sizeof(info)); - check(info.State == MEM_COMMIT && info.Protect == PAGE_READWRITE, + check(committed && info.State == MEM_COMMIT && info.Protect == PAGE_READWRITE, "the page mapped there is a plain read-write view"); fill_page(window, 0x77000000u); check(page_holds(window, 0x77000000u), "the page in the write-combine window holds data");