2 * safe-syscall.inc.S : host-specific assembly fragment
3 * to handle signals occurring at the same time as system calls.
4 * This is intended to be included by common-user/safe-syscall.S
6 * Written by Richard Henderson <rth@twiddle.net>
7 * Copyright (C) 2016 Red Hat, Inc.
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 .global safe_syscall_base
14 .global safe_syscall_start
15 .global safe_syscall_end
16 .type safe_syscall_base, %function
18 .cfi_sections .debug_frame
25 /* This is the entry point for making a system call. The calling
26 * convention here is that of a C varargs function with the
27 * first argument an 'int *' to the signal_pending flag, the
28 * second one the system call number (as a 'long'), and all further
29 * arguments being syscall arguments (also 'long').
34 mov r12, sp /* save entry stack */
35 push { r4, r5, r6, r7, r8, lr }
36 .save { r4, r5, r6, r7, r8, lr }
37 .cfi_adjust_cfa_offset 24
41 .cfi_rel_offset r7, 12
42 .cfi_rel_offset r8, 16
43 .cfi_rel_offset lr, 20
45 /* The syscall calling convention isn't the same as the C one:
46 * we enter with r0 == &signal_pending
47 * r1 == syscall number
48 * r2, r3, [sp+0] ... [sp+12] == syscall arguments
49 * and return the result in r0
50 * and the syscall instruction needs
51 * r7 == syscall number
52 * r0 ... r6 == syscall arguments
53 * and returns the result in r0
54 * Shuffle everything around appropriately.
55 * Note the 16 bytes that we pushed to save registers.
57 mov r8, r0 /* copy signal_pending */
58 mov r7, r1 /* syscall number */
59 mov r0, r2 /* syscall args */
61 ldm r12, { r2, r3, r4, r5, r6 }
63 /* This next sequence of code works in conjunction with the
64 * rewind_if_safe_syscall_function(). If a signal is taken
65 * and the interrupted PC is anywhere between 'safe_syscall_start'
66 * and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'.
67 * The code sequence must therefore be able to cope with this, and
68 * the syscall instruction must be the final one in the sequence.
71 /* if signal_pending is non-zero, don't do the call */
72 ldr r12, [r8] /* signal_pending */
78 /* code path for having successfully executed the syscall */
79 #if defined(__linux__)
80 /* Linux kernel returns (small) negative errno. */
84 #elif defined(__FreeBSD__)
85 /* FreeBSD kernel returns positive errno and C bit set. */
88 #error "unsupported os"
90 pop { r4, r5, r6, r7, r8, pc }
92 /* code path when we didn't execute the syscall */
93 2: mov r0, #QEMU_ERESTARTSYS
95 /* code path setting errno */
96 1: pop { r4, r5, r6, r7, r8, lr }
97 .cfi_adjust_cfa_offset -24
104 b safe_syscall_set_errno_tail
108 .size safe_syscall_base, .-safe_syscall_base