From 4e35b8b49d225061e5dffed35621f3cbc303ac96 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 21 Jul 2023 11:01:19 +0300 Subject: [PATCH] Kernel: Syscalls now get the interrupt stack --- kernel/arch/x86_64/interrupts.S | 4 ++++ kernel/include/kernel/InterruptStack.h | 17 +++++++++++++++++ kernel/kernel/Syscall.cpp | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 kernel/include/kernel/InterruptStack.h diff --git a/kernel/arch/x86_64/interrupts.S b/kernel/arch/x86_64/interrupts.S index ad6aa9719c..eacf910ab1 100644 --- a/kernel/arch/x86_64/interrupts.S +++ b/kernel/arch/x86_64/interrupts.S @@ -163,7 +163,11 @@ syscall_asm: movq %rax, %rdi movq %rbx, %rsi xchgq %rcx, %rdx + movq %rsp, %rbx + addq $120, %rbx + pushq %rbx call cpp_syscall_handler + addq $8, %rsp popaq_no_rax addq $8, %rsp iretq \ No newline at end of file diff --git a/kernel/include/kernel/InterruptStack.h b/kernel/include/kernel/InterruptStack.h new file mode 100644 index 0000000000..84416b5f36 --- /dev/null +++ b/kernel/include/kernel/InterruptStack.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +namespace Kernel +{ + + struct InterruptStack + { + uint64_t rip; + uint64_t cs; + uint64_t flags; + uint64_t rsp; + uint64_t ss; + }; + +} \ No newline at end of file diff --git a/kernel/kernel/Syscall.cpp b/kernel/kernel/Syscall.cpp index c112f0297d..219828ffb5 100644 --- a/kernel/kernel/Syscall.cpp +++ b/kernel/kernel/Syscall.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -17,7 +18,7 @@ namespace Kernel extern "C" long sys_fork_trampoline(); - extern "C" long cpp_syscall_handler(int syscall, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5) + extern "C" long cpp_syscall_handler(int syscall, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, InterruptStack& interrupt_stack) { Thread::current().set_in_syscall(true); @@ -28,6 +29,7 @@ namespace Kernel (void)arg3; (void)arg4; (void)arg5; + (void)interrupt_stack; BAN::ErrorOr ret = BAN::Error::from_errno(ENOSYS);