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

Closed
opened 2026-11-28 10:25:17 +00:00 by AnastasisKon · 6 comments
AnastasisKon commented 2026-11-28 10:25:17 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T10:25:17Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6663387734 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T10:25:17Z. --- 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 commented 2026-11-28 10:25:18 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T10:25:18Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7237885510 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589#issuecomment-7237885510). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T10:25:18Z. --- /claim
github-actions[bot] commented 2026-11-28 10:25:27 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T10:25:27Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7237887153 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589#issuecomment-7237887153). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T10:25:27Z. --- Claimed by @AnastasisKon. Open a draft pull request with `Refs #589` in its description within 24 hours, or the claim expires.
AnastasisKon commented 2026-11-28 12:37:11 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T12:37:11Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7239352109 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589#issuecomment-7239352109). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T12:37:11Z. --- /release - done: PR #590 pins `seh::Context::set_from_thread_state` and the FXSAVE accessors. Carried in my fork's `main` (69146296), gate green.
AnastasisKon commented 2026-11-28 12:41:49 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T12:41:49Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7239404500 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589#issuecomment-7239404500). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T12:41:49Z. --- /release - done: PR #590 pins `seh::Context::set_from_thread_state` and the FXSAVE accessors. Carried in my fork's `main` (69146296), gate green.
github-actions[bot] commented 2026-11-28 12:41:58 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T12:41:58Z.


Released. This issue is free to claim.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7239406067 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589#issuecomment-7239406067). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T12:41:58Z. --- Released. This issue is free to claim.
AnastasisKon commented 2026-11-28 17:06:03 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T17:06:03Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7242753915 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/589#issuecomment-7242753915). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T17:06:03Z. --- The tests this asks for are in the tree already (the mapping, the FXSAVE accessors, the clock scaling and `normalise` are all pinned); closing.
Sign in to join this conversation.
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
LakshanSivakumar/Native-Victory-macOS#589
No description provided.