Fix x64 ABI compliance by aligning stack and reserving shadow space
All checks were successful
Builds / ExectOS (i686, debug) (push) Successful in 29s
Builds / ExectOS (amd64, debug) (push) Successful in 30s
Builds / ExectOS (i686, release) (push) Successful in 37s
Builds / ExectOS (amd64, release) (push) Successful in 40s

This commit is contained in:
2026-03-31 20:06:25 +02:00
parent d834b7e0c8
commit 494b615dc2

View File

@@ -115,22 +115,26 @@ Ar\Type\Vector:
mov %cs, %ax
and $3, %al
mov %al, TrapPreviousMode(%rbp)
jz KernelMode\Type\Vector
swapgs
jmp UserMode\Type\Vector
KernelMode\Type\Vector:
/* Save kernel stack pointer (SS:RSP) */
movl %ss, %eax
mov %eax, TrapSegSs(%rbp)
lea TRAP_FRAME_SIZE(%rbp), %rax
mov %rax, TrapRsp(%rbp)
/* Skip swapgs as the interrupt originated from kernel mode */
jz UserMode\Type\Vector
swapgs
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
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
/* Pass to the trap dispatcher */
call ArDispatchTrap
@@ -139,6 +143,9 @@ UserMode\Type\Vector:
call ArDispatchTrap
.endif
/* Restore the original trap frame stack pointer */
mov %rbx, %rsp
/* Test previous mode and swapgs if needed */
testb $1, TrapPreviousMode(%rbp)
jz KernelModeReturn\Type\Vector