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 <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2020-02-06 11:17:27 -08:00 committed by Anas Nashif
commit 0e32f4dab0

View file

@ -206,6 +206,9 @@ z_x86_switch:
popq %rax
movq %rax, _thread_offset_to_rip(%rsi)
pushfq
popq %rax
movq %rax, _thread_offset_to_rflags(%rsi)
movq %rsp, _thread_offset_to_rsp(%rsi)
movq %rbx, _thread_offset_to_rbx(%rsi)
movq %rbp, _thread_offset_to_rbp(%rsi)