Pin seh::Context::set_from_thread_state and the FXSAVE accessors with unit tests #593

Closed
opened 2026-11-28 10:29:04 +00:00 by github-bot · 6 comments
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 10:25 UTC · original

The Windows x64 CONTEXT decoder in crates/victory-loader/src/native/seh/context.rs has no tests: only the struct size/offset asserts are pinned.

Context::set_from_thread_state maps Darwin's x86_thread_state64 (21 u64 words) into the CONTEXT gpr order (rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8-r15, rip, eflags, cs, fs, gs) and fixes ds/es/ss to 0x2B. The xmm/xmm_mut/set_mxcsr accessors over the FXSAVE image are also untested.

Add unit tests: a distinct value per thread-state word, asserting each gpr slot, rip, the eflags truncation to u32, the three segments read from the state, ds/es/ss = 0x2B; and set_mxcsr writing both mx_csr and the little-endian bytes in flt[1][8..12], plus xmm(i) addressing flt[10 + i]. Pure mapping, no Mach calls; runs under cargo test --target x86_64-apple-darwin -p victory-loader. No behaviour change.

**@⁠AnastasisKon** on GitHub · 2026-11-28 10:25 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589) The Windows x64 `CONTEXT` decoder in `crates/victory-loader/src/native/seh/context.rs` has no tests: only the struct size/offset asserts are pinned. `Context::set_from_thread_state` maps Darwin's `x86_thread_state64` (21 u64 words) into the `CONTEXT` gpr order (rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8-r15, rip, eflags, cs, fs, gs) and fixes ds/es/ss to 0x2B. The `xmm`/`xmm_mut`/`set_mxcsr` accessors over the FXSAVE image are also untested. Add unit tests: a distinct value per thread-state word, asserting each gpr slot, rip, the eflags truncation to u32, the three segments read from the state, ds/es/ss = 0x2B; and `set_mxcsr` writing both `mx_csr` and the little-endian bytes in `flt[1][8..12]`, plus `xmm(i)` addressing `flt[10 + i]`. Pure mapping, no Mach calls; runs under `cargo test --target x86_64-apple-darwin -p victory-loader`. No behaviour change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 10:29:04 +00:00
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 10:25 UTC · original

/claim

**@⁠AnastasisKon** on GitHub · 2026-11-28 10:25 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589#issuecomment-7237885510) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-28 10:25 UTC · original

Claimed by @⁠AnastasisKon. Open a draft pull request with Refs #589 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-28 10:25 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589#issuecomment-7237887153) Claimed by @⁠AnastasisKon. Open a draft pull request with `Refs #589` in its description within 24 hours, or the claim expires.
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 12:37 UTC · original

/release - done: PR #594 pins seh::Context::set_from_thread_state and the FXSAVE accessors. Carried in my fork's main (69146296), gate green.

**@⁠AnastasisKon** on GitHub · 2026-11-28 12:37 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589#issuecomment-7239352109) /release - done: PR #594 pins `seh::Context::set_from_thread_state` and the FXSAVE accessors. Carried in my fork's `main` (69146296), gate green.
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 12:41 UTC · original

/release - done: PR #594 pins seh::Context::set_from_thread_state and the FXSAVE accessors. Carried in my fork's main (69146296), gate green.

**@⁠AnastasisKon** on GitHub · 2026-11-28 12:41 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589#issuecomment-7239404500) /release - done: PR #594 pins `seh::Context::set_from_thread_state` and the FXSAVE accessors. Carried in my fork's `main` (69146296), gate green.
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-28 12:41 UTC · original

Released. This issue is free to claim.

**@⁠github-actions[bot]** on GitHub · 2026-11-28 12:41 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589#issuecomment-7239406067) Released. This issue is free to claim.
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 17:06 UTC · original

The tests this asks for are in the tree already (the mapping, the FXSAVE accessors, the clock scaling and normalise are all pinned); closing.

**@⁠AnastasisKon** on GitHub · 2026-11-28 17:06 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589#issuecomment-7242753915) The tests this asks for are in the tree already (the mapping, the FXSAVE accessors, the clock scaling and `normalise` are all pinned); closing.
This discussion has been locked. Commenting is limited to contributors.
No description provided.