aboutsummaryrefslogtreecommitdiff
path: root/linux-user/host/i386/safe-syscall.inc.S
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2021-11-15 14:08:52 +0100
committerRichard Henderson <richard.henderson@linaro.org>2021-12-19 20:47:33 -0800
commita3310c0397e21df8f47cde3e55736104b9584d2d (patch)
tree2e550417028aea39886ba22f4b60fb9c88404630 /linux-user/host/i386/safe-syscall.inc.S
parentb9d2af3c62c22870c02410d5c9c6d097ee0ddf3f (diff)
downloadqemu-a3310c0397e21df8f47cde3e55736104b9584d2d.zip
qemu-a3310c0397e21df8f47cde3e55736104b9584d2d.tar.gz
qemu-a3310c0397e21df8f47cde3e55736104b9584d2d.tar.bz2
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/i386/safe-syscall.inc.S')
-rw-r--r--linux-user/host/i386/safe-syscall.inc.S35
1 files changed, 25 insertions, 10 deletions
diff --git a/linux-user/host/i386/safe-syscall.inc.S b/linux-user/host/i386/safe-syscall.inc.S
index e425aa5..f588323 100644
--- a/linux-user/host/i386/safe-syscall.inc.S
+++ b/linux-user/host/i386/safe-syscall.inc.S
@@ -20,9 +20,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
@@ -41,7 +38,7 @@ safe_syscall_base:
/* The syscall calling convention isn't the same as the C one:
* we enter with 0(%esp) == return address
- * 4(%esp) == *signal_pending
+ * 4(%esp) == &signal_pending
* 8(%esp) == syscall number
* 12(%esp) ... 32(%esp) == syscall arguments
* and return the result in eax
@@ -70,11 +67,13 @@ safe_syscall_start:
/* if signal_pending is non-zero, don't do the call */
mov 4+16(%esp), %eax /* signal_pending */
cmpl $0, (%eax)
- jnz 1f
+ jnz 2f
mov 8+16(%esp), %eax /* syscall number */
int $0x80
safe_syscall_end:
/* code path for having successfully executed the syscall */
+ cmp $-4095, %eax
+ jae 0f
pop %ebx
.cfi_remember_state
.cfi_adjust_cfa_offset -4
@@ -89,12 +88,28 @@ safe_syscall_end:
.cfi_adjust_cfa_offset -4
.cfi_restore ebp
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, %eax
- jmp safe_syscall_end
- .cfi_endproc
+2: mov $TARGET_ERESTARTSYS, %eax
+ /* code path setting errno */
+1: pop %ebx
+ .cfi_adjust_cfa_offset -4
+ .cfi_restore ebx
+ pop %edi
+ .cfi_adjust_cfa_offset -4
+ .cfi_restore edi
+ pop %esi
+ .cfi_adjust_cfa_offset -4
+ .cfi_restore esi
+ pop %ebp
+ .cfi_adjust_cfa_offset -4
+ .cfi_restore ebp
+ jmp safe_syscall_set_errno_tail
+
+ .cfi_endproc
.size safe_syscall_base, .-safe_syscall_base