Skip to content

Commit f9504fc

Browse files
Fix Windows CI: revert to CONTEXT_CONTROL for GetThreadContext/SetThreadContext
CONTEXT_FULL was corrupting the target thread's register state because SetThreadContext would overwrite all integer and floating-point registers with the captured (but potentially stale) values. Since our preempt_asm assembly already saves and restores ALL registers (GPRs, XMMs, RFLAGS), we only need CONTEXT_CONTROL to redirect RIP/RSP to preempt_asm. The previous coroutine_preemptive timeout with CONTEXT_CONTROL was caused by the monitor retrying preemption on already-preempted threads (the double-preemption bug fixed in commit 445f5ea). With that fix in place, CONTEXT_CONTROL is correct and sufficient. Agent-Logs-Url: https://github.com/acl-dev/open-coroutine/sessions/9f2a2552-802a-4dff-8448-e97277e5ac70 Co-authored-by: loongs-zhang <38336731+loongs-zhang@users.noreply.github.com>
1 parent bca37d9 commit f9504fc

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

core/src/monitor.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,17 @@ impl Monitor {
245245
let mut context: CONTEXT = std::mem::zeroed();
246246
cfg_if::cfg_if! {
247247
if #[cfg(target_arch = "x86_64")] {
248-
// CONTEXT_FULL for AMD64: saves control + integer + floating-point
249-
// registers. Using CONTEXT_FULL (not just CONTEXT_CONTROL) ensures
250-
// all register state is properly round-tripped through
251-
// GetThreadContext/SetThreadContext, avoiding subtle issues in
252-
// release builds where CONTEXT_CONTROL alone may not capture
253-
// enough state for correct preemption.
254-
context.ContextFlags = 0x0010_000B;
248+
// CONTEXT_CONTROL for AMD64: only captures/restores control
249+
// registers (RIP, RSP, RBP, RFLAGS, segment registers).
250+
// We only need to modify RIP and RSP to redirect the thread
251+
// to preempt_asm. The assembly itself saves and restores all
252+
// other registers (GPRs, XMMs, RFLAGS). Using CONTEXT_FULL
253+
// here would clobber registers that are in-use by the target
254+
// thread, causing SetThreadContext to corrupt thread state.
255+
context.ContextFlags = 0x0010_0001;
255256
} else if #[cfg(target_arch = "x86")] {
256-
// CONTEXT_FULL for i386
257-
context.ContextFlags = 0x0001_000B;
257+
// CONTEXT_CONTROL for i386
258+
context.ContextFlags = 0x0001_0001;
258259
}
259260
}
260261

0 commit comments

Comments
 (0)