From 1a5b65a38e8d0846537f948beb9e43b0b74c0252 Mon Sep 17 00:00:00 2001 From: piyonchu <156166227+piyonchu@users.noreply.github.com> Date: Wed, 25 Nov 2026 03:43:44 +0700 Subject: [PATCH] runtime/shims: shim Win32 localization, priority-boost, and named-pipe APIs (RT-WIN32-ENV-LOC-PIPE) --- runtime/CMakeLists.txt | 17 +++ runtime/README.md | 9 ++ runtime/shims/win32_env.cpp | 261 ++++++++++++++++++++++++++++++++ runtime/test/win32_env_test.cpp | 161 ++++++++++++++++++++ scripts/build_runtime.ps1 | 2 +- 5 files changed, 449 insertions(+), 1 deletion(-) create mode 100644 runtime/shims/win32_env.cpp create mode 100644 runtime/test/win32_env_test.cpp diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index a1939ba461..6723344f89 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -250,6 +250,7 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME) shims/xapu_queue.cpp shims/xapu_chad.cpp shims/dstorage.cpp + shims/win32_env.cpp ) # These sources use __try to handle access violations. MSVC always catches them; clang-cl needs asynchronous # exceptions (as for tiny_dll below). A source file property also applies to dstorage_test. @@ -635,6 +636,17 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME) target_compile_options(console_registry_test PRIVATE /W4 /permissive- /utf-8) target_link_options(console_registry_test PRIVATE /OPT:NOREF) + # Win32 localization, process priority boost, and named pipe shims. + add_executable(win32_env_test + test/win32_env_test.cpp + shims/win32_env.cpp + shims/registry.cpp + ) + target_include_directories(win32_env_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/shims) + target_compile_definitions(win32_env_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX) + target_compile_options(win32_env_test PRIVATE /W4 /permissive- /utf-8) + target_link_options(win32_env_test PRIVATE /OPT:NOREF) + # Synthetic tests for the atomic API reference lifecycle. add_executable(api_ref_state_test test/api_ref_state_test.cpp) target_include_directories(api_ref_state_test PRIVATE @@ -1812,6 +1824,11 @@ if(BUILD_TESTING) if(WIN32 AND TARGET console_registry_test) add_test(NAME console_registry COMMAND console_registry_test) endif() + if(WIN32 AND TARGET win32_env_test) + add_test(NAME win32_env COMMAND win32_env_test) + add_test(NAME win32_env_override COMMAND win32_env_test --expect-override) + set_tests_properties(win32_env_override PROPERTIES ENVIRONMENT "LEONIDA_GEO=jp;LEONIDA_LOCALE=en-GB") + endif() if(WIN32 AND TARGET api_ref_state_test) add_test(NAME api_ref_state COMMAND api_ref_state_test) set_tests_properties(api_ref_state PROPERTIES TIMEOUT 30) diff --git a/runtime/README.md b/runtime/README.md index b8c2c87898..d9408d0a61 100644 --- a/runtime/README.md +++ b/runtime/README.md @@ -331,6 +331,15 @@ document names. | `LEONIDA_TRACE_XGAMESAVE` | unset | *Diagnostic.* `1` logs one `[rt] xgamesave:` line to stderr per `XGameSave*` and `XGameSaveFiles*` call (`shims/xgameruntime_gamesave.cpp`): the call, its handles, container and blob names, sizes and HRESULT, after `t=ms tid=`. An async call also logs when its job is scheduled, when its work runs (with how long it waited on the queue), when it completes and when the title collects it with the `...Result` call. Blob contents are never logged. Read once per process; unset, a call costs one load. | | `LEONIDA_STACKS` | unset | Comma-separated whole seconds after the title's entry point is called (e.g. `90,180`). At each time `--run` suspends every other thread in turn just long enough to copy its context and stack, then unwinds the copy (title frames through the unwind tables the loader registers) and prints to stderr `[rt] stacks t= thread ():` and up to 40 `#i module+0xRVA` frames, innermost first; a chain identical to an earlier thread's prints `same as thread `. | +### Win32 localization overrides (`shims/win32_env.cpp`) + +Read once per process by `shims/win32_env.cpp`; unset or invalid values fall back to the host (`US` / `en-US` if the host call fails). + +| variable | default | what it changes | +|---|---|---| +| `LEONIDA_GEO` | unset | Overrides `GetUserDefaultGeoName`: accepts 2 ASCII letters (uppercased, e.g. `jp` -> `JP`) or 3 ASCII digits (`001`..`999`). | +| `LEONIDA_LOCALE` | unset | Overrides `GetUserDefaultLocaleName` and `LocaleNameToLCID(nullptr, ...)`: accepts an ASCII tag up to `LOCALE_NAME_MAX_LENGTH - 1` characters (`A-Z`, `a-z`, `0-9`, `-`, `_`, e.g. `en-GB`). | + ### Switches of the D3D12 layer for a retail boot Read once per process, by the Vulkan D3D12 layer (`shims/d3d12_vulkan_device.cpp`) unless the row names another file. diff --git a/runtime/shims/win32_env.cpp b/runtime/shims/win32_env.cpp new file mode 100644 index 0000000000..a372dad2ca --- /dev/null +++ b/runtime/shims/win32_env.cpp @@ -0,0 +1,261 @@ +// Win32 localization, process priority-boost, and named-pipe shims for mapped executables. +// +// game_scarlett_master.exe imports GetUserDefaultGeoName (api-ms-win-core-localization-l1-2-3.dll), +// GetUserDefaultLocaleName / LocaleNameToLCID (api-ms-win-core-localization-l1-2-0.dll), SetProcessPriorityBoost +// (api-ms-win-core-processthreads-l1-1-2.dll), and WaitNamedPipeW / SetNamedPipeHandleState +// (api-ms-win-core-namedpipe-l1-1-0.dll). Bound straight to the host: +// - SetProcessPriorityBoost(GetCurrentProcess(), ...) mutates the host gta6rt scheduler priority-boost policy; +// - GetUserDefaultGeoName (Win10 1709+) can be absent on older hosts or Wine; +// - GetUserDefaultLocaleName and LocaleNameToLCID(nullptr, ...) reflect arbitrary host locales with no override; +// - WaitNamedPipeW(nullptr, ...) faults on Windows 11, while WaitNamedPipeA(nullptr, ...) fails with +// ERROR_BAD_PATHNAME and SetNamedPipeHandleState(nullptr, ...) fails with ERROR_INVALID_HANDLE. +#include + +#include +#include +#include +#include +#include + +#include "shims.h" + +namespace rt::win32_env { +namespace { + +using GetUserDefaultGeoNameFn = int(WINAPI*)(LPWSTR, int); + +INIT_ONCE g_init_once = INIT_ONCE_STATIC_INIT; +GetUserDefaultGeoNameFn g_host_get_geo_name = nullptr; +bool g_has_geo_override = false; +wchar_t g_geo_override[8]{}; +bool g_has_locale_override = false; +wchar_t g_locale_override[LOCALE_NAME_MAX_LENGTH]{}; +std::atomic g_guest_priority_boost_disabled{false}; + +bool is_valid_geo_code(const char* text, size_t len) { + if (len == 2) { + return std::isalpha(static_cast(text[0])) && + std::isalpha(static_cast(text[1])); + } + if (len == 3) { + return std::isdigit(static_cast(text[0])) && + std::isdigit(static_cast(text[1])) && + std::isdigit(static_cast(text[2])); + } + return false; +} + +bool is_valid_locale_tag(const char* text, size_t len) { + if (len == 0 || len >= LOCALE_NAME_MAX_LENGTH) return false; + for (size_t i = 0; i < len; ++i) { + const unsigned char c = static_cast(text[i]); + if (!std::isalnum(c) && c != '-' && c != '_') return false; + } + return true; +} + +BOOL CALLBACK init_env_once(PINIT_ONCE, PVOID, PVOID*) { + if (const HMODULE kb = GetModuleHandleW(L"kernelbase.dll")) { + g_host_get_geo_name = reinterpret_cast(GetProcAddress(kb, "GetUserDefaultGeoName")); + } + if (!g_host_get_geo_name) { + if (const HMODULE k32 = GetModuleHandleW(L"kernel32.dll")) { + g_host_get_geo_name = + reinterpret_cast(GetProcAddress(k32, "GetUserDefaultGeoName")); + } + } + + char geo_buf[16]{}; + const DWORD geo_len = GetEnvironmentVariableA("LEONIDA_GEO", geo_buf, static_cast(sizeof(geo_buf))); + if (geo_len > 0 && geo_len < sizeof(geo_buf) && is_valid_geo_code(geo_buf, geo_len)) { + for (DWORD i = 0; i < geo_len; ++i) { + const char c = geo_buf[i]; + g_geo_override[i] = static_cast( + (c >= 'a' && c <= 'z') ? (c - 32) : c); + } + g_geo_override[geo_len] = L'\0'; + g_has_geo_override = true; + } + + char loc_buf[LOCALE_NAME_MAX_LENGTH]{}; + const DWORD loc_len = GetEnvironmentVariableA("LEONIDA_LOCALE", loc_buf, static_cast(sizeof(loc_buf))); + if (loc_len > 0 && loc_len < sizeof(loc_buf) && is_valid_locale_tag(loc_buf, loc_len)) { + for (DWORD i = 0; i < loc_len; ++i) g_locale_override[i] = static_cast(loc_buf[i]); + g_locale_override[loc_len] = L'\0'; + g_has_locale_override = true; + } + + BOOL host_disabled = FALSE; + if (::GetProcessPriorityBoost(GetCurrentProcess(), &host_disabled)) { + g_guest_priority_boost_disabled.store(host_disabled != FALSE, std::memory_order_relaxed); + } + return TRUE; +} + +void ensure_initialized() { InitOnceExecuteOnce(&g_init_once, init_env_once, nullptr, nullptr); } + +int write_wide_zstring(const wchar_t* src, LPWSTR dst, int cap, bool allow_zero_cap_query) { + if (cap < 0 || (!dst && cap > 0)) { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + const int needed = static_cast(std::wcslen(src) + 1); + if (!dst) { + if (allow_zero_cap_query) return needed; + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return 0; + } + if (cap < needed) { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return 0; + } + std::wmemcpy(dst, src, static_cast(needed)); + return needed; +} + +int WINAPI get_user_default_geo_name(LPWSTR geo_name, int geo_name_count) { + ensure_initialized(); + if (geo_name_count < 0 || (!geo_name && geo_name_count > 0)) { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + if (g_has_geo_override) { + return write_wide_zstring(g_geo_override, geo_name, geo_name_count, /*allow_zero_cap_query=*/true); + } + if (g_host_get_geo_name) { + const int r = g_host_get_geo_name(geo_name, geo_name_count); + if (r > 0 || GetLastError() == ERROR_INSUFFICIENT_BUFFER) return r; + } + return write_wide_zstring(L"US", geo_name, geo_name_count, /*allow_zero_cap_query=*/true); +} + +int WINAPI get_user_default_locale_name(LPWSTR locale_name, int locale_name_count) { + ensure_initialized(); + if (locale_name_count < 0 || (!locale_name && locale_name_count > 0)) { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + if (g_has_locale_override) { + return write_wide_zstring(g_locale_override, locale_name, locale_name_count, /*allow_zero_cap_query=*/false); + } + if (!locale_name) { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return 0; + } + const int r = ::GetUserDefaultLocaleName(locale_name, locale_name_count); + if (r > 0 || GetLastError() == ERROR_INSUFFICIENT_BUFFER || GetLastError() == ERROR_INVALID_PARAMETER) return r; + return write_wide_zstring(L"en-US", locale_name, locale_name_count, /*allow_zero_cap_query=*/false); +} + +LCID WINAPI locale_name_to_lcid(LPCWSTR name, DWORD flags) { + ensure_initialized(); + if (!name && g_has_locale_override) { + return ::LocaleNameToLCID(g_locale_override, flags); + } + return ::LocaleNameToLCID(name, flags); +} + +bool is_current_process_handle(HANDLE process) { + if (!process) return false; + if (process == GetCurrentProcess()) return true; + return GetProcessId(process) == GetCurrentProcessId(); +} + +BOOL WINAPI set_process_priority_boost(HANDLE process, BOOL disable_priority_boost) { + ensure_initialized(); + if (!process) { + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + if (is_current_process_handle(process)) { + g_guest_priority_boost_disabled.store(disable_priority_boost != FALSE, std::memory_order_relaxed); + return TRUE; + } + return ::SetProcessPriorityBoost(process, disable_priority_boost); +} + +BOOL WINAPI get_process_priority_boost(HANDLE process, PBOOL disable_priority_boost) { + ensure_initialized(); + if (!process) { + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + if (!disable_priority_boost) { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + if (is_current_process_handle(process)) { + *disable_priority_boost = g_guest_priority_boost_disabled.load(std::memory_order_relaxed) ? TRUE : FALSE; + return TRUE; + } + return ::GetProcessPriorityBoost(process, disable_priority_boost); +} + +BOOL WINAPI wait_named_pipe_w(LPCWSTR named_pipe_name, DWORD timeout) { + if (!named_pipe_name) { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + return ::WaitNamedPipeW(named_pipe_name, timeout); +} + +BOOL WINAPI wait_named_pipe_a(LPCSTR named_pipe_name, DWORD timeout) { + if (!named_pipe_name) { + SetLastError(ERROR_BAD_PATHNAME); + return FALSE; + } + return ::WaitNamedPipeA(named_pipe_name, timeout); +} + +BOOL WINAPI set_named_pipe_handle_state(HANDLE named_pipe, LPDWORD mode, LPDWORD max_collection_count, + LPDWORD collect_data_timeout) { + if (!named_pipe || named_pipe == INVALID_HANDLE_VALUE) { + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + return ::SetNamedPipeHandleState(named_pipe, mode, max_collection_count, collect_data_timeout); +} + +} // namespace +} // namespace rt::win32_env + +namespace { + +using namespace rt::win32_env; + +#define LOC_GEO_API(dll) {dll, "GetUserDefaultGeoName", reinterpret_cast(&get_user_default_geo_name)} + +#define LOC_LOCALE_API(dll) \ + {dll, "GetUserDefaultLocaleName", reinterpret_cast(&get_user_default_locale_name)}, \ + {dll, "LocaleNameToLCID", reinterpret_cast(&locale_name_to_lcid)} + +#define PRIORITY_BOOST_API(dll) \ + {dll, "SetProcessPriorityBoost", reinterpret_cast(&set_process_priority_boost)}, \ + {dll, "GetProcessPriorityBoost", reinterpret_cast(&get_process_priority_boost)} + +#define NAMED_PIPE_API(dll) \ + {dll, "WaitNamedPipeW", reinterpret_cast(&wait_named_pipe_w)}, \ + {dll, "WaitNamedPipeA", reinterpret_cast(&wait_named_pipe_a)}, \ + {dll, "SetNamedPipeHandleState", reinterpret_cast(&set_named_pipe_handle_state)} + +} // namespace + +SHIM_TABLE(win32_env, + LOC_GEO_API("kernel32.dll"), + LOC_GEO_API("kernelbase.dll"), + LOC_GEO_API("api-ms-win-core-localization-l1-2-3.dll"), + LOC_LOCALE_API("kernel32.dll"), + LOC_LOCALE_API("kernelbase.dll"), + LOC_LOCALE_API("api-ms-win-core-localization-l1-2-0.dll"), + LOC_LOCALE_API("api-ms-win-core-localization-l1-2-1.dll"), + LOC_LOCALE_API("api-ms-win-core-localization-l1-2-2.dll"), + LOC_LOCALE_API("api-ms-win-core-localization-l1-2-3.dll"), + PRIORITY_BOOST_API("kernel32.dll"), + PRIORITY_BOOST_API("kernelbase.dll"), + PRIORITY_BOOST_API("api-ms-win-core-processthreads-l1-1-0.dll"), + PRIORITY_BOOST_API("api-ms-win-core-processthreads-l1-1-1.dll"), + PRIORITY_BOOST_API("api-ms-win-core-processthreads-l1-1-2.dll"), + NAMED_PIPE_API("kernel32.dll"), + NAMED_PIPE_API("kernelbase.dll"), + NAMED_PIPE_API("api-ms-win-core-namedpipe-l1-1-0.dll"), +); diff --git a/runtime/test/win32_env_test.cpp b/runtime/test/win32_env_test.cpp new file mode 100644 index 0000000000..6be831489d --- /dev/null +++ b/runtime/test/win32_env_test.cpp @@ -0,0 +1,161 @@ +// Tests for runtime/shims/win32_env.cpp through rt::shims::find. +#include + +#include +#include +#include + +#include "shims.h" + +namespace { + +using GetGeoFn = int(WINAPI*)(LPWSTR, int); +using GetLocaleFn = int(WINAPI*)(LPWSTR, int); +using LocaleToLcidFn = LCID(WINAPI*)(LPCWSTR, DWORD); +using SetBoostFn = BOOL(WINAPI*)(HANDLE, BOOL); +using GetBoostFn = BOOL(WINAPI*)(HANDLE, PBOOL); +using WaitPipeWFn = BOOL(WINAPI*)(LPCWSTR, DWORD); +using WaitPipeAFn = BOOL(WINAPI*)(LPCSTR, DWORD); +using SetPipeStateFn = BOOL(WINAPI*)(HANDLE, LPDWORD, LPDWORD, LPDWORD); + +int g_checks = 0; +int g_failures = 0; + +void check(bool condition, const char* what) { + ++g_checks; + std::printf("%s %s\n", condition ? "PASS" : "FAIL", what); + if (!condition) ++g_failures; +} + +template +Fn resolve(const char* dll, const char* name) { + return reinterpret_cast(rt::shims::find(dll, name)); +} + +void test_registry_coverage() { + check(resolve("api-ms-win-core-localization-l1-2-3.dll", "GetUserDefaultGeoName") != nullptr, + "GetUserDefaultGeoName resolves"); + check(resolve("api-ms-win-core-localization-l1-2-0.dll", "GetUserDefaultLocaleName") != nullptr, + "GetUserDefaultLocaleName resolves"); + check(resolve("api-ms-win-core-localization-l1-2-0.dll", "LocaleNameToLCID") != nullptr, + "LocaleNameToLCID resolves"); + check(resolve("api-ms-win-core-processthreads-l1-1-2.dll", "SetProcessPriorityBoost") != nullptr, + "SetProcessPriorityBoost resolves"); + check(resolve("kernel32.dll", "GetProcessPriorityBoost") != nullptr, + "GetProcessPriorityBoost resolves"); + check(resolve("api-ms-win-core-namedpipe-l1-1-0.dll", "WaitNamedPipeW") != nullptr, + "WaitNamedPipeW resolves"); + check(resolve("api-ms-win-core-namedpipe-l1-1-0.dll", "SetNamedPipeHandleState") != nullptr, + "SetNamedPipeHandleState resolves"); +} + +void test_localization(bool expect_overrides) { + auto get_geo = resolve("api-ms-win-core-localization-l1-2-3.dll", "GetUserDefaultGeoName"); + auto get_locale = resolve("api-ms-win-core-localization-l1-2-0.dll", "GetUserDefaultLocaleName"); + auto to_lcid = resolve("api-ms-win-core-localization-l1-2-0.dll", "LocaleNameToLCID"); + + SetLastError(0); + check(get_geo(nullptr, 2) == 0 && GetLastError() == ERROR_INVALID_PARAMETER, + "GetUserDefaultGeoName rejects nullptr with positive count"); + wchar_t small_geo[2]{}; + SetLastError(0); + check(get_geo(small_geo, 1) == 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER, + "GetUserDefaultGeoName reports ERROR_INSUFFICIENT_BUFFER for undersized buffer"); + + const int geo_needed = get_geo(nullptr, 0); + check(geo_needed >= 3, "GetUserDefaultGeoName(nullptr, 0) returns required length"); + wchar_t geo[16]{}; + const int geo_written = get_geo(geo, 16); + check(geo_written == geo_needed && geo[0] != L'\0', "GetUserDefaultGeoName fills non-empty region code"); + if (expect_overrides) { + check(std::wcscmp(geo, L"JP") == 0, "GetUserDefaultGeoName honors and uppercases LEONIDA_GEO override"); + } + + SetLastError(0); + check(get_locale(nullptr, 4) == 0 && GetLastError() == ERROR_INVALID_PARAMETER, + "GetUserDefaultLocaleName rejects nullptr with positive count"); + wchar_t tiny_loc[2]{}; + SetLastError(0); + check(get_locale(tiny_loc, 1) == 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER, + "GetUserDefaultLocaleName reports ERROR_INSUFFICIENT_BUFFER on cap=1"); + wchar_t loc[LOCALE_NAME_MAX_LENGTH]{}; + const int loc_written = get_locale(loc, LOCALE_NAME_MAX_LENGTH); + check(loc_written > 1 && loc[0] != L'\0', "GetUserDefaultLocaleName fills non-empty locale"); + if (expect_overrides) { + check(std::wcscmp(loc, L"en-GB") == 0, "GetUserDefaultLocaleName honors LEONIDA_LOCALE override"); + check(to_lcid(nullptr, 0) == to_lcid(L"en-GB", 0), + "LocaleNameToLCID(nullptr) matches overridden user locale"); + } else { + check(to_lcid(L"en-US", 0) == 0x0409, "LocaleNameToLCID resolves en-US to 0x0409"); + } +} + +void test_process_priority_boost() { + auto set_boost = resolve("api-ms-win-core-processthreads-l1-1-2.dll", "SetProcessPriorityBoost"); + auto get_boost = resolve("kernel32.dll", "GetProcessPriorityBoost"); + + BOOL host_before = FALSE; + check(::GetProcessPriorityBoost(GetCurrentProcess(), &host_before) != FALSE, + "host GetProcessPriorityBoost baseline readable"); + + BOOL val = FALSE; + SetLastError(0); + check(!set_boost(nullptr, TRUE) && GetLastError() == ERROR_INVALID_HANDLE, + "SetProcessPriorityBoost rejects null handle"); + SetLastError(0); + check(!get_boost(nullptr, &val) && GetLastError() == ERROR_INVALID_HANDLE, + "GetProcessPriorityBoost rejects null handle"); + SetLastError(0); + check(!get_boost(GetCurrentProcess(), nullptr) && GetLastError() == ERROR_INVALID_PARAMETER, + "GetProcessPriorityBoost rejects null out pointer"); + + check(set_boost(GetCurrentProcess(), !host_before) != FALSE, + "SetProcessPriorityBoost accepts GetCurrentProcess()"); + check(get_boost(GetCurrentProcess(), &val) != FALSE && val == (!host_before ? TRUE : FALSE), + "GetProcessPriorityBoost returns guest-configured state"); + + BOOL host_after = FALSE; + check(::GetProcessPriorityBoost(GetCurrentProcess(), &host_after) != FALSE && host_after == host_before, + "host process priority-boost state remains untouched by guest calls"); + + check(set_boost(GetCurrentProcess(), host_before) != FALSE, + "SetProcessPriorityBoost toggles cleanly"); +} + +void test_named_pipes() { + auto wait_w = resolve("api-ms-win-core-namedpipe-l1-1-0.dll", "WaitNamedPipeW"); + auto wait_a = resolve("kernel32.dll", "WaitNamedPipeA"); + auto set_state = resolve("api-ms-win-core-namedpipe-l1-1-0.dll", "SetNamedPipeHandleState"); + + SetLastError(0); + check(!wait_w(nullptr, 0) && GetLastError() == ERROR_INVALID_PARAMETER, "WaitNamedPipeW rejects nullptr cleanly"); + SetLastError(0); + check(!wait_a(nullptr, 0) && GetLastError() == ERROR_BAD_PATHNAME, + "WaitNamedPipeA rejects nullptr with ERROR_BAD_PATHNAME"); + SetLastError(0); + check(!wait_w(L"\\\\.\\pipe\\leonida_nonexistent_test_pipe", 0) && GetLastError() == ERROR_FILE_NOT_FOUND, + "WaitNamedPipeW reports ERROR_FILE_NOT_FOUND on missing pipe"); + + DWORD mode = PIPE_READMODE_BYTE; + SetLastError(0); + check(!set_state(nullptr, &mode, nullptr, nullptr) && GetLastError() == ERROR_INVALID_HANDLE, + "SetNamedPipeHandleState rejects nullptr cleanly"); + SetLastError(0); + check(!set_state(INVALID_HANDLE_VALUE, &mode, nullptr, nullptr) && GetLastError() == ERROR_INVALID_HANDLE, + "SetNamedPipeHandleState rejects INVALID_HANDLE_VALUE cleanly"); +} + +} // namespace + +int main(int argc, char** argv) { + bool expect_overrides = false; + for (int i = 1; i < argc; ++i) { + if (std::strcmp(argv[i], "--expect-override") == 0) expect_overrides = true; + } + test_registry_coverage(); + test_localization(expect_overrides); + test_process_priority_boost(); + test_named_pipes(); + std::printf("%d check(s), %d failure(s)\n", g_checks, g_failures); + return g_failures ? 1 : 0; +} diff --git a/scripts/build_runtime.ps1 b/scripts/build_runtime.ps1 index d386ba0525..db84a7d809 100644 --- a/scripts/build_runtime.ps1 +++ b/scripts/build_runtime.ps1 @@ -86,7 +86,7 @@ $build || exit /b 1 Write-Warning "CMake and Ninja weren't found (neither VS C++ CMake tools nor native PATH tools): building with cl.exe directly, without the GameInput shim (SDL3) and without the Rust XMA2 decoder (XMA voices are silent). Install CMake + Ninja or VS's CMake tools component to get it." $xtaskqueueDir = Join-Path $root "third_party\xtaskqueue" $xtaskqueueFiles = "Source\Task\TaskQueue.cpp", "Source\Task\AsyncLib.cpp", "Source\Task\ThreadPool_win32.cpp", "Source\Task\WaitTimer_win32.cpp" | ForEach-Object { "`"$xtaskqueueDir\$_`"" } - $files = "src\main.cpp", "src\thread_stacks.cpp", "src\bcpack.cpp", "src\host_cpu.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\console_registry.cpp", "shims\file_system.cpp", "shims\xmem.cpp", "shims\xg_xs.cpp", "shims\acphal.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_pso_stream.cpp", "shims\d3d12_xs_rootsig.cpp", "shims\xgameruntime.cpp", "shims\xgameruntime_user.cpp", "shims\xgameruntime_gamesave.cpp", "shims\xgameruntime_store.cpp", "shims\xgameruntime_offline.cpp", "shims\winhttp_offline.cpp", "shims\ws2_offline.cpp", "shims\library_loader.cpp", "shims\process.cpp", "shims\lifecycle.cpp", "shims\xbox_bvh_builder.cpp", "shims\com_shim.cpp", "shims\silent_audio.cpp", "shims\bcrypt_rng.cpp", "shims\xapu_queue.cpp", "shims\xapu_chad.cpp", "shims\dstorage.cpp" | ForEach-Object { "`"$src\$_`"" } + $files = "src\main.cpp", "src\thread_stacks.cpp", "src\bcpack.cpp", "src\host_cpu.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\console_registry.cpp", "shims\file_system.cpp", "shims\xmem.cpp", "shims\xg_xs.cpp", "shims\acphal.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_pso_stream.cpp", "shims\d3d12_xs_rootsig.cpp", "shims\xgameruntime.cpp", "shims\xgameruntime_user.cpp", "shims\xgameruntime_gamesave.cpp", "shims\xgameruntime_store.cpp", "shims\xgameruntime_offline.cpp", "shims\winhttp_offline.cpp", "shims\ws2_offline.cpp", "shims\library_loader.cpp", "shims\process.cpp", "shims\lifecycle.cpp", "shims\xbox_bvh_builder.cpp", "shims\com_shim.cpp", "shims\silent_audio.cpp", "shims\bcrypt_rng.cpp", "shims\xapu_queue.cpp", "shims\xapu_chad.cpp", "shims\dstorage.cpp", "shims\win32_env.cpp" | ForEach-Object { "`"$src\$_`"" } $includes = "/I `"$src\src`" /I `"$src\shims`" /I `"$src\shims\xtaskqueue`" /I `"$xtaskqueueDir\Include`" /I `"$xtaskqueueDir\Source\Task`" /I `"$xtaskqueueDir\Source\Common`"" $opt = if ($Debug) { "/Od /MDd" } else { "/O2 /MD" } $body = @"