]> git.proxmox.com Git - mirror_qemu.git/commitdiff
common-user: Adjust system call return on FreeBSD
authorRichard Henderson <richard.henderson@linaro.org>
Tue, 23 Nov 2021 14:18:49 +0000 (15:18 +0100)
committerRichard Henderson <richard.henderson@linaro.org>
Mon, 20 Dec 2021 18:12:29 +0000 (10:12 -0800)
FreeBSD system calls return positive errno.  On the 4 hosts for
which we have support, error is indicated by the C bit set or clear.

Reviewed-by: Warner Losh <imp@bsdimp.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
common-user/host/aarch64/safe-syscall.inc.S
common-user/host/arm/safe-syscall.inc.S
common-user/host/i386/safe-syscall.inc.S
common-user/host/x86_64/safe-syscall.inc.S

index 73a04b73b39d60f32a1f5d3adbab5e14f2dc31e2..b8fd5b553e2288c4e2a7ac73e788c6e29dba29c4 100644 (file)
@@ -60,17 +60,29 @@ safe_syscall_start:
         cbnz    w10, 2f
         svc     0x0
 safe_syscall_end:
+
         /* code path for having successfully executed the syscall */
+#if defined(__linux__)
+        /* Linux kernel returns (small) negative errno. */
         cmp     x0, #-4096
         b.hi    0f
+#elif defined(__FreeBSD__)
+        /* FreeBSD kernel returns positive errno and C bit set. */
+        b.cs    1f
+#else
+#error "unsupported os"
+#endif
         ret
 
+#if defined(__linux__)
         /* code path setting errno */
 0:      neg     w0, w0
         b       safe_syscall_set_errno_tail
+#endif
 
         /* code path when we didn't execute the syscall */
 2:      mov     w0, #QEMU_ERESTARTSYS
-        b       safe_syscall_set_errno_tail
+1:      b       safe_syscall_set_errno_tail
+
         .cfi_endproc
         .size   safe_syscall_base, .-safe_syscall_base
index 66176a902c16a50663536e2497c2633af6461747..bbfb89634e7d80d2c2f5fb11a367b27ff5d3ff93 100644 (file)
@@ -74,10 +74,19 @@ safe_syscall_start:
         bne     2f
         swi     0
 safe_syscall_end:
+
         /* code path for having successfully executed the syscall */
+#if defined(__linux__)
+        /* Linux kernel returns (small) negative errno. */
         cmp     r0, #-4096
         neghi   r0, r0
         bhi     1f
+#elif defined(__FreeBSD__)
+        /* FreeBSD kernel returns positive errno and C bit set. */
+        bcs     1f
+#else
+#error "unsupported os"
+#endif
         pop     { r4, r5, r6, r7, r8, pc }
 
         /* code path when we didn't execute the syscall */
index aced8c5141f6053e6b51f22d8f3551b1043c02a3..baf5400a29ce44e41d5fb56c39ee6a393b38b783 100644 (file)
@@ -71,9 +71,18 @@ safe_syscall_start:
         mov     8+16(%esp), %eax        /* syscall number */
         int     $0x80
 safe_syscall_end:
+
         /* code path for having successfully executed the syscall */
+#if defined(__linux__)
+        /* Linux kernel returns (small) negative errno. */
         cmp     $-4095, %eax
         jae     0f
+#elif defined(__FreeBSD__)
+        /* FreeBSD kernel returns positive errno and C bit set. */
+        jc      1f
+#else
+#error "unsupported os"
+#endif
         pop     %ebx
         .cfi_remember_state
         .cfi_adjust_cfa_offset -4
@@ -90,8 +99,10 @@ safe_syscall_end:
         ret
         .cfi_restore_state
 
+#if defined(__linux__)
 0:      neg     %eax
         jmp     1f
+#endif
 
         /* code path when we didn't execute the syscall */
 2:      mov     $QEMU_ERESTARTSYS, %eax
index 84fed206f903662d9f7ff0384235e467487f09c3..a20927a78386f307d60ab48637f82432599f3b71 100644 (file)
@@ -68,9 +68,18 @@ safe_syscall_start:
         jnz     2f
         syscall
 safe_syscall_end:
+
         /* code path for having successfully executed the syscall */
+#if defined(__linux__)
+        /* Linux kernel returns (small) negative errno. */
         cmp     $-4095, %rax
         jae     0f
+#elif defined(__FreeBSD__)
+        /* FreeBSD kernel returns positive errno and C bit set. */
+        jc      1f
+#else
+#error "unsupported os"
+#endif
         pop     %rbp
         .cfi_remember_state
         .cfi_def_cfa_offset 8
@@ -78,8 +87,10 @@ safe_syscall_end:
         ret
         .cfi_restore_state
 
+#if defined(__linux__)
 0:      neg     %eax
         jmp     1f
+#endif
 
         /* code path when we didn't execute the syscall */
 2:      mov     $QEMU_ERESTARTSYS, %eax