Kernel: Fix signal trampoline

32 bit did not even support it and 64 bit did not align stack
This commit is contained in:
Bananymous 2024-04-18 13:32:40 +03:00
parent a698f91db4
commit 061012a268
4 changed files with 18 additions and 6 deletions

View File

@ -7,22 +7,26 @@
.global signal_trampoline .global signal_trampoline
signal_trampoline: signal_trampoline:
ud2
pushl %ebp pushl %ebp
movl %esp, %ebp movl %esp, %ebp
subl $8, %esp
pusha pusha
movl 40(%esp), %edi movl 40(%esp), %edi
movl 36(%esp), %eax movl 36(%esp), %eax
// align stack to 16 bytes
movl %esp, %ebx
andl $0x0F, %ebx
subl %ebx, %esp
subl $12, %esp subl $12, %esp
pushl %edi pushl %edi
call *%eax call *%eax
addl $16, %esp addl $16, %esp
// restore stack
addl %ebx, %esp
popa popa
leave leave

View File

@ -23,12 +23,18 @@ signal_trampoline:
pushq %r14 pushq %r14
pushq %r15 pushq %r15
// This is 16 byte aligned
movq 128(%rsp), %rdi movq 128(%rsp), %rdi
movq 120(%rsp), %rax movq 120(%rsp), %rax
// align stack to 16 bytes
movq %rsp, %rbx
andq $0x0F, %rbx
subq %rbx, %rsp
call *%rax call *%rax
// restore stack
addq %rbx, %rsp
popq %r15 popq %r15
popq %r14 popq %r14
popq %r13 popq %r13

View File

@ -94,7 +94,7 @@ namespace Kernel
private: private:
static constexpr size_t m_kernel_stack_size = PAGE_SIZE * 64; static constexpr size_t m_kernel_stack_size = PAGE_SIZE * 64;
static constexpr size_t m_userspace_stack_size = PAGE_SIZE * 4; static constexpr size_t m_userspace_stack_size = PAGE_SIZE * 64;
BAN::UniqPtr<VirtualRange> m_kernel_stack; BAN::UniqPtr<VirtualRange> m_kernel_stack;
BAN::UniqPtr<VirtualRange> m_userspace_stack; BAN::UniqPtr<VirtualRange> m_userspace_stack;
const pid_t m_tid { 0 }; const pid_t m_tid { 0 };

View File

@ -335,7 +335,9 @@ namespace Kernel
else if (signal_handler != (vaddr_t)SIG_DFL) else if (signal_handler != (vaddr_t)SIG_DFL)
{ {
// call userspace signal handlers // call userspace signal handlers
#if ARCH(x86_64)
interrupt_stack.sp -= 128; // skip possible red-zone interrupt_stack.sp -= 128; // skip possible red-zone
#endif
write_to_stack(interrupt_stack.sp, interrupt_stack.ip); write_to_stack(interrupt_stack.sp, interrupt_stack.ip);
write_to_stack(interrupt_stack.sp, signal); write_to_stack(interrupt_stack.sp, signal);
write_to_stack(interrupt_stack.sp, signal_handler); write_to_stack(interrupt_stack.sp, signal_handler);