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 <noreply@anthropic.com>
This commit is contained in:
Ivan John Ozimchuk
2026-11-23 12:27:13 +02:00
parent 55df81be1d
commit 22d21f0519
+7 -1
View File
@@ -328,7 +328,13 @@ pub fn run_main(m: &Arc<MappedModule>) -> 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);