summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAgustin Gianni <agustingianni@gmail.com>2023-01-25 19:30:00 +0000
committerAndrew Kaster <andrewdkaster@gmail.com>2023-02-02 01:52:52 -0700
commitbfbb4bcd9bd91bc83fcd98097e664cf56916ca67 (patch)
tree6761df126abaf98a39e476159dc5755982ab5cb1
parente71c320154195ac19651168ca0b8c93078af3872 (diff)
downloadserenity-bfbb4bcd9bd91bc83fcd98097e664cf56916ca67.zip
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.
-rw-r--r--Kernel/API/Syscall.h3
-rw-r--r--Kernel/Arch/x86_64/SyscallEntry.cpp9
-rw-r--r--Kernel/Arch/x86_64/init.cpp1
-rw-r--r--Kernel/Syscall.cpp52
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 <AK/Types.h>
#include <AK/Userspace.h>
#include <Kernel/API/POSIX/sched.h>
+#include <Kernel/Arch/RegisterState.h>
constexpr int syscall_vector = 0x82;
@@ -201,6 +202,8 @@ enum class NeedsBigProcessLock {
namespace Syscall {
+ErrorOr<FlatPtr> 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 <Kernel/API/Syscall.h>
#include <Kernel/Arch/TrapFrame.h>
#include <Kernel/Arch/x86_64/DescriptorTable.h>
#include <Kernel/Arch/x86_64/Processor.h>
+#include <Kernel/Assertions.h>
+#include <Kernel/Panic.h>
+#include <Kernel/Process.h>
+#include <Kernel/Scheduler.h>
+#include <Kernel/Thread.h>
+#include <Kernel/ThreadTracer.h>
+
+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 <Kernel/API/Syscall.h>
+#include <Kernel/Arch/RegisterState.h>
#include <Kernel/Arch/TrapFrame.h>
#include <Kernel/Memory/MemoryManager.h>
#include <Kernel/Panic.h>
@@ -15,60 +16,10 @@
#include <Kernel/Sections.h>
#include <Kernel/ThreadTracer.h>
-#if ARCH(X86_64)
-# include <Kernel/Arch/x86_64/Interrupts.h>
-#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<FlatPtr> 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<FlatPtr>;
using HandlerWithRegisterState = auto(Process::*)(RegisterState&) -> ErrorOr<FlatPtr>;
@@ -143,6 +94,7 @@ ErrorOr<FlatPtr> 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)