Loader: a fault on an SSE4a site another thread just replaced runs again as the jump #4195

Closed
transbinaryunicorn-sys wants to merge 1 commit from upstream-pr/4195 into main
transbinaryunicorn-sys commented 2026-11-30 17:19:21 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by transbinaryunicorn-sys on 2026-11-30T17:19:21Z.


Fixes the 0xc000001d crash at an already-patched SSE4a site reported in #1428.

The race

Two threads that fault on the same insertq/extrq both enter console_insn::emulate(). The first handler replaces the instruction with a jmp to its stub (patch_sse4a → patch(), atomic via cmpxchg16b, and patch() already handles "another thread's fault at the same place"). But if the second handler reads the bytes at rip only after that, decode() finds the jmp, sees no console-only instruction, and emulate() returns 0, so it never gets to patch(). The exception goes unhandled, at a site whose code starts e9:

unhandled exception 0xc000001d at victory-image-...-p2f9ea84c.dll+0x27c8f2 (code e9 69 3a a0 ff 90 90 ...)
unhandled exception 0xc000001d at victory-image-...-p2f9ea84c.dll+0x5084782 (code e9 b9 ba bf fa 90 ...)

The fix

When decode() finds nothing, check whether the bytes at rip are a jmp rel32 into one of our STUBS regions (is_our_jump). If so, another thread just replaced the instruction: return CONTINUE_EXECUTION without moving rip, so the thread runs the jump into the stub. Any other unknown instruction still returns 0 as before, so real illegal instructions and the other vectored handlers are unaffected. The path logs once.

Tested

Xeon w7-3465X (28C/56T, Intel, no SSE4a), RTX 5090, Linux (Wine), Series X image:

VICTORY_PATCH_SSE4A result when the prologue starts
before on (default) crash, 2 of 2 runs (+0x27c8f2, +0x5084782)
before =0 no crash, but over a million emulated instructions in ~13 min
this PR on (default) no crash; logs a console CPU instruction another thread replaced meanwhile: run again as the jump ... at=0x...4782, the same site as the second crash above

Builds clean on top of current main. Only crates/victory-loader/src/console_insn.rs changes (+24/−1).

Many cores without SSE4a (Intel, many threads hitting the same insertq at once when the prologue loads) make this likely; on 6–8 core machines it is probably rare, which may be why it hasn't shown up before.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HTKMrPY51kbJiQAEkckA8e

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5570178237 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4195). Originally posted by [transbinaryunicorn-sys](https://github.com/transbinaryunicorn-sys) on 2026-11-30T17:19:21Z. --- Fixes the `0xc000001d` crash at an already-patched SSE4a site reported in #1428. ### The race Two threads that fault on the same `insertq`/`extrq` both enter `console_insn::emulate()`. The first handler replaces the instruction with a `jmp` to its stub (`patch_sse4a` → `patch()`, atomic via `cmpxchg16b`, and `patch()` already handles "another thread's fault at the same place"). But if the second handler reads the bytes at `rip` only **after** that, `decode()` finds the `jmp`, sees no console-only instruction, and `emulate()` returns 0, so it never gets to `patch()`. The exception goes unhandled, at a site whose code starts `e9`: ``` unhandled exception 0xc000001d at victory-image-...-p2f9ea84c.dll+0x27c8f2 (code e9 69 3a a0 ff 90 90 ...) unhandled exception 0xc000001d at victory-image-...-p2f9ea84c.dll+0x5084782 (code e9 b9 ba bf fa 90 ...) ``` ### The fix When `decode()` finds nothing, check whether the bytes at `rip` are a `jmp rel32` into one of our `STUBS` regions (`is_our_jump`). If so, another thread just replaced the instruction: return `CONTINUE_EXECUTION` without moving `rip`, so the thread runs the jump into the stub. Any other unknown instruction still returns 0 as before, so real illegal instructions and the other vectored handlers are unaffected. The path logs once. ### Tested Xeon w7-3465X (28C/56T, Intel, **no SSE4a**), RTX 5090, Linux (Wine), Series X image: | | `VICTORY_PATCH_SSE4A` | result when the prologue starts | |---|---|---| | before | on (default) | crash, 2 of 2 runs (`+0x27c8f2`, `+0x5084782`) | | before | `=0` | no crash, but over a million emulated instructions in ~13 min | | **this PR** | on (default) | **no crash**; logs `a console CPU instruction another thread replaced meanwhile: run again as the jump ... at=0x...4782`, the same site as the second crash above | Builds clean on top of current main. Only `crates/victory-loader/src/console_insn.rs` changes (+24/−1). Many cores without SSE4a (Intel, many threads hitting the same `insertq` at once when the prologue loads) make this likely; on 6–8 core machines it is probably rare, which may be why it hasn't shown up before. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01HTKMrPY51kbJiQAEkckA8e
trustno1-coder commented 2026-12-01 18:45:58 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:45:58Z.


Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321500853 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4195#issuecomment-7321500853). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:45:58Z. --- Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

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
trustno1-coder/VIctory-NVIDIA!4195
No description provided.