From bfbb4bcd9bd91bc83fcd98097e664cf56916ca67 Mon Sep 17 00:00:00 2001 From: Agustin Gianni Date: Wed, 25 Jan 2023 19:30:00 +0000 Subject: Kernel: Remove trap based syscall handling This patch removes the x86 mechanism for calling syscalls, favoring the more modern syscall instruction. It also moves architecture dependent code from functions that are meant to be architecture agnostic therefore paving the way for adding more architectures. --- Kernel/API/Syscall.h | 3 +++ Kernel/Arch/x86_64/SyscallEntry.cpp | 9 +++++++ Kernel/Arch/x86_64/init.cpp | 1 - Kernel/Syscall.cpp | 52 ++----------------------------------- 4 files changed, 14 insertions(+), 51 deletions(-) diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h index b58efd4737..af5b4eb957 100644 --- a/Kernel/API/Syscall.h +++ b/Kernel/API/Syscall.h @@ -9,6 +9,7 @@ #include #include #include +#include constexpr int syscall_vector = 0x82; @@ -201,6 +202,8 @@ enum class NeedsBigProcessLock { namespace Syscall { +ErrorOr handle(RegisterState&, FlatPtr function, FlatPtr arg1, FlatPtr arg2, FlatPtr arg3, FlatPtr arg4); + enum Function { #undef __ENUMERATE_SYSCALL #define __ENUMERATE_SYSCALL(sys_call, needs_lock) SC_##sys_call, diff --git a/Kernel/Arch/x86_64/SyscallEntry.cpp b/Kernel/Arch/x86_64/SyscallEntry.cpp index bd9ebfc7d1..052a6941b4 100644 --- a/Kernel/Arch/x86_64/SyscallEntry.cpp +++ b/Kernel/Arch/x86_64/SyscallEntry.cpp @@ -4,9 +4,18 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include +#include +#include +#include +#include +#include +#include + +using namespace Kernel; extern "C" void syscall_entry(); extern "C" [[gnu::naked]] void syscall_entry() diff --git a/Kernel/Arch/x86_64/init.cpp b/Kernel/Arch/x86_64/init.cpp index 00fe1ac858..4e62011afc 100644 --- a/Kernel/Arch/x86_64/init.cpp +++ b/Kernel/Arch/x86_64/init.cpp @@ -341,7 +341,6 @@ void init_stage2(void*) } NetworkingManagement::the().initialize(); - Syscall::initialize(); #ifdef ENABLE_KERNEL_COVERAGE_COLLECTION (void)KCOVDevice::must_create().leak_ref(); diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index 37a8434d60..3ed9c2e874 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -15,60 +16,10 @@ #include #include -#if ARCH(X86_64) -# include -#endif - namespace Kernel { -extern "C" void syscall_handler(TrapFrame*) __attribute__((used)); -extern "C" void syscall_asm_entry(); - -NEVER_INLINE NAKED void syscall_asm_entry() -{ - // clang-format off -#if ARCH(X86_64) - asm( - " pushq $0x0\n" - " pushq %r15\n" - " pushq %r14\n" - " pushq %r13\n" - " pushq %r12\n" - " pushq %r11\n" - " pushq %r10\n" - " pushq %r9\n" - " pushq %r8\n" - " pushq %rax\n" - " pushq %rcx\n" - " pushq %rdx\n" - " pushq %rbx\n" - " pushq %rsp\n" - " pushq %rbp\n" - " pushq %rsi\n" - " pushq %rdi\n" - " pushq %rsp \n" /* set TrapFrame::regs */ - " subq $" __STRINGIFY(TRAP_FRAME_SIZE - 8) ", %rsp \n" - " movq %rsp, %rdi \n" - " cld\n" - " call enter_trap_no_irq \n" - " movq %rsp, %rdi \n" - " call syscall_handler\n" - " jmp common_trap_exit \n"); -#endif - // clang-format on -} - namespace Syscall { -static ErrorOr handle(RegisterState&, FlatPtr function, FlatPtr arg1, FlatPtr arg2, FlatPtr arg3, FlatPtr arg4); - -UNMAP_AFTER_INIT void initialize() -{ -#if ARCH(X86_64) - register_user_callable_interrupt_handler(syscall_vector, syscall_asm_entry); -#endif -} - using Handler = auto(Process::*)(FlatPtr, FlatPtr, FlatPtr, FlatPtr) -> ErrorOr; using HandlerWithRegisterState = auto(Process::*)(RegisterState&) -> ErrorOr; @@ -143,6 +94,7 @@ ErrorOr handle(RegisterState& regs, FlatPtr function, FlatPtr arg1, Fla } +extern "C" NEVER_INLINE void syscall_handler(TrapFrame* trap); NEVER_INLINE void syscall_handler(TrapFrame* trap) { #if ARCH(X86_64) -- cgit v1.2.3