Fix x64 ABI compliance by aligning stack and reserving shadow space
This commit is contained in:
@@ -115,22 +115,26 @@ Ar\Type\Vector:
|
|||||||
mov %cs, %ax
|
mov %cs, %ax
|
||||||
and $3, %al
|
and $3, %al
|
||||||
mov %al, TrapPreviousMode(%rbp)
|
mov %al, TrapPreviousMode(%rbp)
|
||||||
jz KernelMode\Type\Vector
|
|
||||||
swapgs
|
|
||||||
jmp UserMode\Type\Vector
|
|
||||||
|
|
||||||
KernelMode\Type\Vector:
|
/* Skip swapgs as the interrupt originated from kernel mode */
|
||||||
/* Save kernel stack pointer (SS:RSP) */
|
jz UserMode\Type\Vector
|
||||||
movl %ss, %eax
|
|
||||||
mov %eax, TrapSegSs(%rbp)
|
swapgs
|
||||||
lea TRAP_FRAME_SIZE(%rbp), %rax
|
|
||||||
mov %rax, TrapRsp(%rbp)
|
|
||||||
|
|
||||||
UserMode\Type\Vector:
|
UserMode\Type\Vector:
|
||||||
/* Push Frame Pointer and clear direction flag */
|
/* Set up trap frame pointer for the dispatcher and clear the direction flag */
|
||||||
mov %rsp, %rcx
|
mov %rsp, %rcx
|
||||||
cld
|
cld
|
||||||
|
|
||||||
|
/* Preserve the original stack pointer */
|
||||||
|
mov %rsp, %rbx
|
||||||
|
|
||||||
|
/* Force stack alignment */
|
||||||
|
and $-16, %rsp
|
||||||
|
|
||||||
|
/* Allocate 32 bytes of shadow space */
|
||||||
|
sub $32, %rsp
|
||||||
|
|
||||||
.ifc \Type,Trap
|
.ifc \Type,Trap
|
||||||
/* Pass to the trap dispatcher */
|
/* Pass to the trap dispatcher */
|
||||||
call ArDispatchTrap
|
call ArDispatchTrap
|
||||||
@@ -139,6 +143,9 @@ UserMode\Type\Vector:
|
|||||||
call ArDispatchTrap
|
call ArDispatchTrap
|
||||||
.endif
|
.endif
|
||||||
|
|
||||||
|
/* Restore the original trap frame stack pointer */
|
||||||
|
mov %rbx, %rsp
|
||||||
|
|
||||||
/* Test previous mode and swapgs if needed */
|
/* Test previous mode and swapgs if needed */
|
||||||
testb $1, TrapPreviousMode(%rbp)
|
testb $1, TrapPreviousMode(%rbp)
|
||||||
jz KernelModeReturn\Type\Vector
|
jz KernelModeReturn\Type\Vector
|
||||||
|
|||||||
Reference in New Issue
Block a user