diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-06-29 10:31:25 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-29 20:03:36 +0200 |
commit | 6dde7dac8f7540c8f17e85cc3193832611f1bcc8 (patch) | |
tree | 9fe873d4e2477cfcf816cdb9db4cca0478dee8ff /Kernel/Syscalls/sigaction.cpp | |
parent | 36ce2a2b765a54c2548475134060d0a89081c2fa (diff) | |
download | serenity-6dde7dac8f7540c8f17e85cc3193832611f1bcc8.zip |
Kernel: Implement signal handling for x86_64
Diffstat (limited to 'Kernel/Syscalls/sigaction.cpp')
-rw-r--r-- | Kernel/Syscalls/sigaction.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Kernel/Syscalls/sigaction.cpp b/Kernel/Syscalls/sigaction.cpp index 1b07db25a9..1c0a413b3a 100644 --- a/Kernel/Syscalls/sigaction.cpp +++ b/Kernel/Syscalls/sigaction.cpp @@ -104,7 +104,28 @@ KResultOr<FlatPtr> Process::sys$sigreturn([[maybe_unused]] RegisterState& regist registers.userspace_esp = registers.esp; return smuggled_eax; #else - PANIC("sys$sigreturn() not implemented."); + //Here, we restore the state pushed by dispatch signal and asm_signal_trampoline. + FlatPtr* stack_ptr = (FlatPtr*)registers.userspace_rsp; + FlatPtr smuggled_rax = *stack_ptr; + + //pop the stored rax, rbp, return address, handler and signal code + stack_ptr += 5; + + Thread::current()->m_signal_mask = *stack_ptr; + stack_ptr++; + + //pop rdi, rsi, rbp, rsp, rbx, rdx, rcx, rax, r8, r9, r10, r11, r12, r13, r14 and r15 + memcpy(®isters.rdi, stack_ptr, 16 * sizeof(FlatPtr)); + stack_ptr += 16; + + registers.rip = *stack_ptr; + stack_ptr++; + + registers.rflags = (registers.rflags & ~safe_eflags_mask) | (*stack_ptr & safe_eflags_mask); + stack_ptr++; + + registers.userspace_rsp = registers.rsp; + return smuggled_rax; #endif } |