From 67ebc588124f5f1126bccc30251594f5579695c7 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sat, 26 Sep 2020 22:01:21 -0700 Subject: [PATCH] [kernel] Allow for more than three syscall args The rcx register is used by the function call ABI for the 4th argument, but is also clobbered by SYSCALL to hold the IP. The r10 register is caller-saved but not part of the ABI, so stash rcx there when crossing the syscall boundary. --- src/kernel/syscall.s | 8 +++++--- src/libraries/libc/arch/x86_64/syscalls.s | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/kernel/syscall.s b/src/kernel/syscall.s index b95878b..659bbf4 100644 --- a/src/kernel/syscall.s +++ b/src/kernel/syscall.s @@ -23,9 +23,11 @@ syscall_handler_prelude: mov rbp, rsp ; account for the hole in the sysv abi - ; argument list since SYSCALL uses rcx - mov rcx, r8 - mov r8, r9 + ; argument list since SYSCALL uses rcx. + ; r10 is non-preserved but not part of + ; the function call ABI, so the rcx arg + ; was stashed there. + mov rcx, r10 push rbx push r11 diff --git a/src/libraries/libc/arch/x86_64/syscalls.s b/src/libraries/libc/arch/x86_64/syscalls.s index 4a9e42e..b9b5416 100644 --- a/src/libraries/libc/arch/x86_64/syscalls.s +++ b/src/libraries/libc/arch/x86_64/syscalls.s @@ -5,9 +5,10 @@ mov rbp, rsp ; args should already be in rdi, etc, but rcx will - ; get stomped, so shift args out one spot from rcx - mov r9, r8 - mov r8, rcx + ; get stomped, so stash it in r10, which isn't a + ; callee-saved register, but also isn't used in the + ; function call ABI. + mov r10, rcx mov rax, %2 syscall