[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:
Justin C. Miller
2022-01-30 12:25:11 -08:00
parent 17ca402aa0
commit b6218a1121
4 changed files with 44 additions and 4 deletions

View File

@@ -6,6 +6,15 @@
push rbp
mov rbp, rsp
; if the syscall has more than 6 arguments, the rest
; will be pushed on the stack. in that case, we'd need
; to pass this stack pointer to the kernel, so stash
; off rbx (callee-saved) and pass the pointer to the
; arguments there.
push rbx
mov rbx, rbp
add rbx, 16 ; account for stack frame
; args should already be in rdi, etc, but rcx will
; get stomped, so stash it in r10, which isn't a
; callee-saved register, but also isn't used in the
@@ -16,6 +25,7 @@
syscall
; result is now already in rax, so just return
pop rbx
pop rbp
ret
%endmacro