Skip to content

Commit 0e32f4d

Browse files
Andy Rossnashif
authored andcommitted
arch/x86_64: Save RFLAGS during arch_switch()
The context switch implementation forgot to save the current flag state of the old thread, so on resume the flags would be restored to whatever value they had at the last interrupt preemption or thread initialization. In practice this guaranteed that the interrupt enable bit would always be wrong, becuase obviously new threads and preempted ones have interrupts enabled, while arch_switch() is always called with them masked. This opened up a race between exit from arch_switch() and the final exit path in z_swap(). The other state bits weren't relevant -- the oddball ones aren't used by Zephyr, and as arch_switch() on this architecture is a function call the compiler would have spilled the (caller-save) comparison result flags anyway. Signed-off-by: Andy Ross <[email protected]>
1 parent eefd3da commit 0e32f4d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

arch/x86/core/intel64/locore.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ z_x86_switch:
206206

207207
popq %rax
208208
movq %rax, _thread_offset_to_rip(%rsi)
209+
pushfq
210+
popq %rax
211+
movq %rax, _thread_offset_to_rflags(%rsi)
209212
movq %rsp, _thread_offset_to_rsp(%rsi)
210213
movq %rbx, _thread_offset_to_rbx(%rsi)
211214
movq %rbp, _thread_offset_to_rbp(%rsi)

0 commit comments

Comments
 (0)