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

Closed
github-bot wants to merge 1 commit from github-bot/gh-4195 into main AGit
Owner

@⁠transbinaryunicorn-sys on GitHub · 2026-11-30 17:19 UTC · original
transbinaryunicorn-sys:fix-sse4a-race → main · +24 −1 · 1 files · 1 commits · closed without merging

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

**@⁠transbinaryunicorn-sys** on GitHub · 2026-11-30 17:19 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4195) `transbinaryunicorn-sys:fix-sse4a-race` → `main` · +24 −1 · 1 files · 1 commits · closed without merging 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
Two threads that fault on the same `insertq`/`extrq` both enter emulate().
The first one's handler replaces the instruction with a `jmp` to its stub
(patch_sse4a, atomically with cmpxchg16b). If the second handler reads the
bytes only after that, decode() finds the `jmp`, knows no console-only
instruction there and returns 0, and the title dies with an unhandled
0xc000001d at a site whose code starts `e9` (#1428).

Now, when decode() finds nothing, a `jmp rel32` into one of our STUBS
regions means exactly that: the handler returns CONTINUE_EXECUTION without
moving rip, and the thread runs the jump. Any other unknown instruction is
left to the other handlers as before. Logged once.

Seen on a Xeon w7-3465X (28C/56T, no SSE4a) when the prologue starts:
without this, 2 of 2 runs crashed at +0x27c8f2 / +0x5084782 with
VICTORY_PATCH_SSE4A on (only VICTORY_PATCH_SSE4A=0 avoided it, at over a
million emulated instructions in 13 minutes). With it, the same moment
logs "replaced meanwhile ... at=...4782" and the run goes on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HTKMrPY51kbJiQAEkckA8e
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 18:08:25 +00:00
github-bot closed this pull request 2026-12-01 18:50:33 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:45 UTC · original

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.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:45 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4195#issuecomment-7321500853) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!4196
No description provided.