diff --git a/docs/linux.md b/docs/linux.md index f051ca84a..477d3a154 100644 --- a/docs/linux.md +++ b/docs/linux.md @@ -89,6 +89,38 @@ unless you add the `x86_64-pc-windows-msvc` Rust target or pass a prebuilt stati `-DLEONIDA_XMA2_DECODER_LIB=`, built yourself from this checkout's `runtime/xma_decoder` with the command in [runtime/xma_decoder/README.md](../runtime/xma_decoder/README.md). +### 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` skips the reported state and protection there and + checks that the page is a read-write view that holds what was written. +- **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 ffe729d24..c0a2b00ba 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -330,8 +330,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 ffdd70155..7e9093fcd 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 d2c315f03..a8f03ebc3 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 4c1bb7d2f..44cc480a0 100644 --- a/runtime/test/dstorage_test.cpp +++ b/runtime/test/dstorage_test.cpp @@ -1007,7 +1007,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) { @@ -1050,7 +1055,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 cdd071055..f7923a4d3 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 c647b8877..db6e6e0bc 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 b4b1e812e..55b693746 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 { @@ -621,13 +622,35 @@ 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(); + } - if (versioned) { + // The versioned entry point forwards the same cleared copy to the host's versioned deserializer, which under + // Wine refuses the zero checksum too, so that one is asked the same way. + ID3D12VersionedRootSignatureDeserializer* host_v_zero = nullptr; + const HRESULT hr_host_v_zero = + D3D12CreateVersionedRootSignatureDeserializer(out.data(), out.size(), IID_PPV_ARGS(&host_v_zero)); + if (host_v_zero) host_v_zero->Release(); + if (versioned && FAILED(hr_host_v_zero) && hostwine::is_wine()) { + std::printf("SKIP versioned shim accepts an all-zero-checksum Xbox blob with the high byte cleared " + "(Wine's deserializer refuses a zero checksum)\n"); + } else if (versioned) { ID3D12VersionedRootSignatureDeserializer* v_zero = nullptr; const HRESULT v_hr_zero = versioned(zero_hash.data(), zero_hash.size(), IID_PPV_ARGS(&v_zero)); const auto* desc = v_zero ? v_zero->GetUnconvertedRootSignatureDesc() : nullptr;