[kernel] Allow 7+ argument syscalls
The syscall interface is designed to closely follow the System V amd64 calling convention, so that as much as possible, the call into the assembly trampoline for the syscall sets up the call correctly. Before this change, the only exception was using r10 (a caller-saved register already) to stash the contents of rcx, which gets clobbered by the syscall instruction. However, this only preserves registers for the function call, as the stack is switched upon kernel entry, and additional call frames have been added by the time the syscall gets back into C++ land. This change adds a new parameter to the syscall in rbx. Since rbx is callee-saved, the syscall trampoline pushes it to the stack, and then puts the address of the stack-passed arguments into rbx. Now that the syscall implementations are wrapped in the _syscall_verify_* functions, we can piggy-back on those to also set up the extra arguments from the user stack. Now, for any syscall with 7 or more arguments, the verify wrapper takes the first six arguments normally, then gets a stack pointer (the rbx value) as its 7th and final argument. It's then the job of the verify wrapper to get the remaining arguments from that stack pointer and pass them to the implementation function as normal arguments.
This commit is contained in:
@@ -50,6 +50,11 @@ syscall_handler_prelude:
|
||||
push r14
|
||||
push r15
|
||||
|
||||
; if we've got more than 6 arguments, the rest
|
||||
; are on the user stack, and pointed to by rbx.
|
||||
; push rbx so that it's the 7th argument.
|
||||
push rbx
|
||||
|
||||
inc qword [rel __counter_syscall_enter]
|
||||
|
||||
cmp rax, NUM_SYSCALLS
|
||||
@@ -62,6 +67,8 @@ syscall_handler_prelude:
|
||||
|
||||
call r11
|
||||
|
||||
add rsp, 8 ; account for passing rbx on the stack
|
||||
|
||||
inc qword [rel __counter_syscall_sysret]
|
||||
jmp kernel_to_user_trampoline
|
||||
|
||||
|
||||
Reference in New Issue
Block a user