MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / SyscallHandler

Function SyscallHandler

Kernel/src/arch/x86_64/syscalls.cpp:2719–2739  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2717int lastSyscall = 0;
2718extern "C"
2719void SyscallHandler(regs64_t* regs) {
2720 if (regs->rax >= NUM_SYSCALLS) // If syscall is non-existant then return
2721 return;
2722
2723 asm("sti"); // By reenabling interrupts, a thread in a syscall can be preempted
2724
2725 thread_t* thread = GetCPULocal()->currentThread;
2726 if(!syscalls[regs->rax]) return;
2727 if(thread->state == ThreadStateZombie) for(;;);
2728
2729 uint64_t rsp = 0;
2730 asm volatile("mov %%rsp, %0" : "=r"(rsp));
2731
2732 IF_DEBUG((rsp < KERNEL_VIRTUAL_BASE), {
2733 Log::Info("warning: call: %d, thread rip: %x, kstack: %x, kernel rsp: %x, tss rsp0: %x, thread cs: %x, thread ss: %x", regs->rax, regs->rip, GetCPULocal()->currentThread->kernelStack, rsp, GetCPULocal()->tss.rsp0, regs->cs, regs->ss);
2734 });
2735
2736 acquireLock(&thread->lock);
2737 regs->rax = syscalls[regs->rax](regs); // Call syscall
2738 releaseLock(&thread->lock);
2739}

Callers

nothing calls this directly

Calls 2

GetCPULocalFunction · 0.85
InfoFunction · 0.85

Tested by

no test coverage detected