Loader: under Wine, PEB.ImageBaseAddress keeps the real main image #92

Merged
ozimchuk merged 1 commit from upstream-pr/93 into main 2026-11-23 11:02:41 +00:00
ozimchuk commented 2026-11-23 10:42:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ozimchuk on 2026-11-23T10:42:49Z.


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 dies in ntdll with an access violation (a read at address 0x6e).

Under Wine (ntdll exports wine_get_version) the field is now left alone, and a log line says so. Nothing changes on Windows.

Known cost under Wine: GetModuleHandle(NULL) answers xcl.exe there, not the title. The test title's check for it passes here; a title that reads resources from its own image through a NULL module may need more.

Validation

Linux, Wine with vkd3d-proton, GNU toolchain build, main at 1f82be3:

build test title (xcl run <testgame> -- --hello)
main + the other Wine fix (#92) only access violation in ntdll when the title's first thread starts, 0 checks run
main + this change + #92 47 [PASS], 2 [FAIL] on an AMD iGPU (RADV) and on an RTX 5060 Ti

The two failing checks are not about this change (xmem working-set statistics; the console window "not cloaked" under Wine). The run needs a locally patched vkd3d-proton for reasons that have nothing to do with this change either (it asserts on objects whose vtable XCL replaced); that is a separate topic. Not run on Windows.

AI-assisted.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:6557487115 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/93). Originally posted by [ozimchuk](https://github.com/ozimchuk) on 2026-11-23T10:42:49Z. --- `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 dies in ntdll with an access violation (a read at address `0x6e`). Under Wine (ntdll exports `wine_get_version`) the field is now left alone, and a log line says so. Nothing changes on Windows. **Known cost under Wine:** `GetModuleHandle(NULL)` answers `xcl.exe` there, not the title. The test title's check for it passes here; a title that reads resources from its own image through a NULL module may need more. ## Validation Linux, Wine with vkd3d-proton, GNU toolchain build, `main` at `1f82be3`: | build | test title (`xcl run <testgame> -- --hello`) | |---|---| | `main` + the other Wine fix (#92) only | access violation in ntdll when the title's first thread starts, 0 checks run | | `main` + this change + #92 | 47 `[PASS]`, 2 `[FAIL]` on an AMD iGPU (RADV) and on an RTX 5060 Ti | The two failing checks are not about this change (`xmem` working-set statistics; the console window "not cloaked" under Wine). The run needs a locally patched vkd3d-proton for reasons that have nothing to do with this change either (it asserts on objects whose vtable XCL replaced); that is a separate topic. Not run on Windows. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:57:07 +00:00
ivall commented 2026-11-24 07:00:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T11:03:08Z.


Merged. On Windows nothing changes (wine_get_version is not exported), and the test title and games run as before. Noted the GetModuleHandle(NULL) cost under Wine in the log line. Checked on Windows 11 with an RX 9070 (RDNA4, MSVC build): cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), natively and with XCL_SPLIT_WAVE64=1. Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7098953251 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/93#issuecomment-7098953251). Originally posted by [ivall](https://github.com/ivall) on 2026-11-23T11:03:08Z. --- Merged. On Windows nothing changes (`wine_get_version` is not exported), and the test title and games run as before. Noted the `GetModuleHandle(NULL)` cost under Wine in the log line. Checked on Windows 11 with an RX 9070 (RDNA4, MSVC build): `cargo test --workspace` green with the retail samples (shader pack, console DLLs, texture archive), natively and with `XCL_SPLIT_WAVE64=1`. Thanks!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!92
No description provided.