From d9d6264bb2cd9fa58f1cacf40b7ba88bb6d01330 Mon Sep 17 00:00:00 2001 From: Chris Koos Date: Sat, 31 Oct 2026 15:02:30 -0700 Subject: [PATCH] Default shadow storage to on when running under Wine --- runtime/platform/linux.c | 2 ++ runtime/platform/platform.h | 1 + runtime/platform/win32.c | 5 +++++ runtime/vk_memory.c | 4 ++-- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/platform/linux.c b/runtime/platform/linux.c index 23a9f7fd..136b43c4 100644 --- a/runtime/platform/linux.c +++ b/runtime/platform/linux.c @@ -1247,6 +1247,8 @@ int plat_os_version(char *out, size_t cap) { return snprintf(out, cap, "%s (Linux %s)", name, u.release) < (int)cap; } +int plat_is_wine(void) { return 0; } + int plat_stderr_path(char *out, size_t cap) { struct stat st; if (fstat(2, &st) || !S_ISREG(st.st_mode)) return 0; diff --git a/runtime/platform/platform.h b/runtime/platform/platform.h index df232d22..3d7e0ac6 100644 --- a/runtime/platform/platform.h +++ b/runtime/platform/platform.h @@ -350,6 +350,7 @@ uint32_t plat_thread_id(void); // id of the calling t int plat_font_path(const char *lang, char *out, size_t cap); // The operating system and its build ("Windows 10.0.28000") into out; 0 when unknown. int plat_os_version(char *out, size_t cap); +int plat_is_wine(void); // 1 when the Windows build runs under Wine; 0 elsewhere // The file the process's stderr (the log) goes to, as a UTF-8 path; 0 when stderr is not a file (a console, a pipe). int plat_stderr_path(char *out, size_t cap); diff --git a/runtime/platform/win32.c b/runtime/platform/win32.c index e785095f..9586fb17 100644 --- a/runtime/platform/win32.c +++ b/runtime/platform/win32.c @@ -1128,6 +1128,11 @@ int plat_os_version(char *out, size_t cap) { return 1; } +int plat_is_wine(void) { + HMODULE nt = GetModuleHandleW(L"ntdll.dll"); + return nt && GetProcAddress(nt, "wine_get_version") != NULL; +} + int plat_stderr_path(char *out, size_t cap) { HANDLE h = GetStdHandle(STD_ERROR_HANDLE); wchar_t w[WPATH]; diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index fba5677a..39ec43e3 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -827,7 +827,7 @@ static int query_stamp(uint64_t lo, uint64_t hi, uint32_t g) { // - GPU -> guest: the replay notes each GPU write into CPU-visible memory at record time (vk_mem_gpu_pending) and // reports it at the fence (vk_gpu_written), which copies those bytes back into guest memory. Until then the CPU // copies skip them: a page the CPU and the GPU both write keeps the GPU's bytes. -// TOTK_SHADOW=1/0 forces the mode on or off; the default is on for Linux. +// TOTK_SHADOW=1/0 forces the mode on or off; the default is on for Linux and Wine. typedef struct { uint64_t lo, hi; } SRange; static PlatMutex shadow_lock = PLAT_MUTEX_INIT; // after pool_lock; before gen_lock static PoolRec **stouch; // shadow_lock: pools resolved since the last sync @@ -1187,7 +1187,7 @@ static void mirror_mode(int discrete) { if (freeze_idle < 0) freeze_idle = 0; const char *sh = cfg_get("TOTK_SHADOW"); #ifdef _WIN32 - shadow_on = sh && *sh && strcmp(sh, "0"); + shadow_on = sh && *sh ? strcmp(sh, "0") != 0 : plat_is_wine(); #else shadow_on = !sh || !*sh || strcmp(sh, "0"); #endif