In _thread_enter_uts, fix eflags saving bug.
In _thread_switch, set current thread pointer in kse mailbox only after all registers copied out of thread mailbox, kernel will do upcall at trap time, if set current thread pointer before loading all registers from thread mailbox, at trap time, the thread mailbox data will be overwritten by kernel, result is junk data is loaded into CPU.
This commit is contained in:
parent
f89233ef8d
commit
ed0591ed98
@ -79,7 +79,8 @@ ENTRY(_thread_enter_uts)
|
||||
*/
|
||||
fnstcw MC_FP_CW_OFFSET(%edx)
|
||||
movl $0, MC_OWNEDFP_OFFSET(%edx) /* no FP */
|
||||
lahf /* get eflags */
|
||||
pushfl /* get eflags */
|
||||
popl %eax
|
||||
movl %eax, 68(%edx) /* store eflags */
|
||||
movl %esp, %eax /* setcontext pushes the return */
|
||||
addl $4, %eax /* address onto the top of the */
|
||||
|
@ -79,7 +79,8 @@ ENTRY(_thread_enter_uts)
|
||||
*/
|
||||
fnstcw MC_FP_CW_OFFSET(%edx)
|
||||
movl $0, MC_OWNEDFP_OFFSET(%edx) /* no FP */
|
||||
lahf /* get eflags */
|
||||
pushfl /* get eflags */
|
||||
popl %eax
|
||||
movl %eax, 68(%edx) /* store eflags */
|
||||
movl %esp, %eax /* setcontext pushes the return */
|
||||
addl $4, %eax /* address onto the top of the */
|
||||
|
@ -54,8 +54,8 @@ ENTRY(_thread_switch)
|
||||
je 2f
|
||||
movl $-1, %eax /* bzzzt, invalid context */
|
||||
jmp 5f
|
||||
2: movl 8(%esp), %eax /* get address of curthreadp */
|
||||
movl %edx, (%eax) /* we're now the current thread */
|
||||
2: movl 8(%esp), %ecx /* get address of curthreadp */
|
||||
movl %edx, %ebx /* save the pointer for later */
|
||||
/*
|
||||
* From here on, we don't touch the old stack.
|
||||
*/
|
||||
@ -78,12 +78,19 @@ ENTRY(_thread_switch)
|
||||
jmp 4f
|
||||
3: fninit
|
||||
fldcw MC_FP_CW_OFFSET(%edx)
|
||||
4: movl 48(%edx), %eax /* restore ax, bx, cx */
|
||||
movl 36(%edx), %ebx
|
||||
movl 44(%edx), %ecx
|
||||
4: movl 48(%edx), %eax /* restore ax, bx, cx, dx */
|
||||
pushl 68(%edx) /* flags on stack */
|
||||
pushl 40(%edx) /* %edx on stack */
|
||||
pushl 36(%edx) /* %ebx on stack */
|
||||
pushl 44(%edx) /* %ecx on stack */
|
||||
pushl 40(%edx) /* %edx on stack */
|
||||
/*
|
||||
* all registers are now moved out of mailbox
|
||||
* it's now safe to set current thread pointer
|
||||
*/
|
||||
movl %ebx,(%ecx)
|
||||
popl %edx /* %edx off stack */
|
||||
popl %ecx /* %ecx off stack */
|
||||
popl %ebx /* %ebx off stack */
|
||||
popf /* flags off stack */
|
||||
5: ret /* %eip off stack */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user