From 22d21f051982193e73b118fad030e33dde25f1a2 Mon Sep 17 00:00:00 2001 From: Ivan John Ozimchuk <3846306+ozimchuk@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:27:13 +0200 Subject: [PATCH] Loader: under Wine, PEB.ImageBaseAddress keeps the real main image run_main writes the title's base into PEB.ImageBaseAddress so that GetModuleHandle(NULL) answers the title. Wine's loader looks that address up in its own module list whenever a thread starts (loader_init: get_modref(Peb->ImageBaseAddress)) and uses the result unchecked. A manually mapped image is not in that list, so the title's first thread died in ntdll with an access violation at address 0x6e. Under Wine (ntdll exports wine_get_version) the field is now left alone and a log line says so. GetModuleHandle(NULL) then answers xcl.exe there, not the title. Nothing changes on Windows. Co-Authored-By: Claude Fable 5.2 --- crates/xcl/src/loader.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/loader.rs b/crates/xcl/src/loader.rs index 3e2723b..016b5e3 100644 --- a/crates/xcl/src/loader.rs +++ b/crates/xcl/src/loader.rs @@ -328,7 +328,13 @@ pub fn run_main(m: &Arc) -> u32 { }; unsafe { // PEB.ImageBaseAddress → GetModuleHandle(NULL), resources with NULL module, … - *(peb().add(0x10) as *mut usize) = m.base; + use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress}; + let wine = GetProcAddress(GetModuleHandleA(c"ntdll.dll".as_ptr() as *const u8), c"wine_get_version".as_ptr() as *const u8).is_some(); + if wine { + crate::xlog_info!("Wine: PEB.ImageBaseAddress left alone (its loader needs the real main image there)"); + } else { + *(peb().add(0x10) as *mut usize) = m.base; + } run_tls_callbacks(m, 1); } READY.store(true, Ordering::Release);