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 linux-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
20 /* This is the entry point for making a system call. The calling
21 * convention here is that of a C varargs function with the
22 * first argument an 'int *' to the signal_pending flag, the
23 * second one the system call number (as a 'long'), and all further
24 * arguments being syscall arguments (also 'long').
25 * We return a long which is the syscall's return value, which
26 * may be negative-errno on failure. Conversion to the
27 * -1-and-errno-set convention is done by the calling wrapper.
32 .localentry safe_syscall_base,0
37 .quad .L.safe_syscall_base,.TOC.@tocbase,0
42 /* We enter with r3 == *signal_pending
43 * r4 == syscall number
44 * r5 ... r10 == syscall arguments
45 * and return the result in r3
46 * and the syscall instruction needs
47 * r0 == syscall number
48 * r3 ... r8 == syscall arguments
49 * and returns the result in r3
50 * Shuffle everything around appropriately.
52 mr 11, 3 /* signal_pending */
53 mr 0, 4 /* syscall number */
54 mr 3, 5 /* syscall arguments */
61 /* This next sequence of code works in conjunction with the
62 * rewind_if_safe_syscall_function(). If a signal is taken
63 * and the interrupted PC is anywhere between 'safe_syscall_start'
64 * and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'.
65 * The code sequence must therefore be able to cope with this, and
66 * the syscall instruction must be the final one in the sequence.
69 /* if signal_pending is non-zero, don't do the call */
75 /* code path when we did execute the syscall */
78 /* syscall failed; return negative errno */
82 /* code path when we didn't execute the syscall */
83 0: addi 3, 0, -TARGET_ERESTARTSYS
88 .size safe_syscall_base, .-safe_syscall_base
90 .size safe_syscall_base, .-.L.safe_syscall_base
91 .size .L.safe_syscall_base, .-.L.safe_syscall_base