18 KSTACK_USERSTATE_SIZE equ (4+8+1+5)*4 ; SRegs, GPRegs, CPU, IRET
19 [global Proc_ReturnToUser]
20 [extern Proc_GetCurThread]
22 ; RBP is the handler to use
24 call Proc_GetCurThread
26 ; EAX is the current thread
28 mov rax, [rbx+40] ; Get Kernel Stack
29 sub rax, KSTACK_USERSTATE_SIZE
32 ; NOTE: This can cause corruption if the signal happens while the user
33 ; has called a kernel operation.
34 ; Good thing this can only be called on a user fault.
37 ; Get and alter User SP
38 mov rcx, [rax+KSTACK_USERSTATE_SIZE-3*8]
39 mov rdx, [rbx+60] ; Get Signal Number
41 mov QWORD [rcx-16], User_Syscall_RetAndExit
44 ; Restore Segment Registers
51 push 0x202 ; RFLAGS (IF and Rsvd)
58 User_Syscall_RetAndExit:
67 [global gInitialKernelStack]