diff options
author | Richard Henderson <richard.henderson@linaro.org> | 2021-11-15 14:08:52 +0100 |
---|---|---|
committer | Richard Henderson <richard.henderson@linaro.org> | 2021-12-19 20:47:33 -0800 |
commit | a3310c0397e21df8f47cde3e55736104b9584d2d (patch) | |
tree | 2e550417028aea39886ba22f4b60fb9c88404630 /linux-user/host/x86_64/safe-syscall.inc.S | |
parent | b9d2af3c62c22870c02410d5c9c6d097ee0ddf3f (diff) |
linux-user: Move syscall error detection into safe_syscall_base
The current api from safe_syscall_base() is to return -errno, which is
the interface provided by *some* linux kernel abis. The wrapper macro,
safe_syscall(), detects error, stores into errno, and returns -1, to
match the api of the system syscall().
For those kernel abis that do not return -errno natively, this leads
to double syscall error detection. E.g. Linux ppc64, which sets the
SO flag for error.
Simplify the usage from C by moving the error detection into assembly,
and usage from assembly by providing a C helper with which to set errno.
Reviewed-by: Warner Losh <imp@bsdimp.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'linux-user/host/x86_64/safe-syscall.inc.S')
-rw-r--r-- | linux-user/host/x86_64/safe-syscall.inc.S | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/linux-user/host/x86_64/safe-syscall.inc.S b/linux-user/host/x86_64/safe-syscall.inc.S index 158225553e..39b64250c3 100644 --- a/linux-user/host/x86_64/safe-syscall.inc.S +++ b/linux-user/host/x86_64/safe-syscall.inc.S @@ -19,9 +19,6 @@ * first argument an 'int *' to the signal_pending flag, the * second one the system call number (as a 'long'), and all further * arguments being syscall arguments (also 'long'). - * We return a long which is the syscall's return value, which - * may be negative-errno on failure. Conversion to the - * -1-and-errno-set convention is done by the calling wrapper. */ safe_syscall_base: .cfi_startproc @@ -35,9 +32,9 @@ safe_syscall_base: .cfi_adjust_cfa_offset 8 .cfi_rel_offset rbp, 0 - /* The syscall calling convention isn't the same as the - * C one: - * we enter with rdi == *signal_pending + /* + * The syscall calling convention isn't the same as the C one: + * we enter with rdi == &signal_pending * rsi == syscall number * rdx, rcx, r8, r9, (stack), (stack) == syscall arguments * and return the result in rax @@ -68,24 +65,30 @@ safe_syscall_base: safe_syscall_start: /* if signal_pending is non-zero, don't do the call */ cmpl $0, (%rbp) - jnz 1f + jnz 2f syscall safe_syscall_end: /* code path for having successfully executed the syscall */ + cmp $-4095, %rax + jae 0f pop %rbp .cfi_remember_state .cfi_def_cfa_offset 8 .cfi_restore rbp ret + .cfi_restore_state + +0: neg %eax + jmp 1f -1: /* code path when we didn't execute the syscall */ - .cfi_restore_state - mov $-TARGET_ERESTARTSYS, %rax - pop %rbp +2: mov $TARGET_ERESTARTSYS, %eax + + /* code path setting errno */ +1: pop %rbp .cfi_def_cfa_offset 8 .cfi_restore rbp - ret + jmp safe_syscall_set_errno_tail .cfi_endproc .size safe_syscall_base, .-safe_syscall_base |