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.
This commit is contained in:
Agustin Gianni 2023-01-25 19:30:00 +00:00 committed by Andrew Kaster
parent e71c320154
commit bfbb4bcd9b
Notes: sideshowbarker 2024-07-17 00:55:50 +09:00
4 changed files with 14 additions and 51 deletions

View file

@ -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,

View file

@ -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()

View file

@ -341,7 +341,6 @@ void init_stage2(void*)
}
NetworkingManagement::the().initialize();
Syscall::initialize();
#ifdef ENABLE_KERNEL_COVERAGE_COLLECTION
(void)KCOVDevice::must_create().leak_ref();

View file

@ -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)