···1212#ifndef QEMU_HOSTDEP_H
1313#define QEMU_HOSTDEP_H
14141515+/* We have a safe-syscall.inc.S */
1616+#define HAVE_SAFE_SYSCALL
1717+1818+#ifndef __ASSEMBLER__
1919+2020+/* These are defined by the safe-syscall.inc.S file */
2121+extern char safe_syscall_start[];
2222+extern char safe_syscall_end[];
2323+2424+/* Adjust the signal context to rewind out of safe-syscall if we're in it */
2525+static inline void rewind_if_in_safe_syscall(void *puc)
2626+{
2727+ struct ucontext *uc = puc;
2828+ unsigned long *pcreg = &uc->uc_mcontext.gp_regs[PT_NIP];
2929+3030+ if (*pcreg > (uintptr_t)safe_syscall_start
3131+ && *pcreg < (uintptr_t)safe_syscall_end) {
3232+ *pcreg = (uintptr_t)safe_syscall_start;
3333+ }
3434+}
3535+3636+#endif /* __ASSEMBLER__ */
3737+1538#endif
+92
linux-user/host/ppc64/safe-syscall.inc.S
···11+/*
22+ * safe-syscall.inc.S : host-specific assembly fragment
33+ * to handle signals occurring at the same time as system calls.
44+ * This is intended to be included by linux-user/safe-syscall.S
55+ *
66+ * Written by Richard Henderson <rth@twiddle.net>
77+ * Copyright (C) 2016 Red Hat, Inc.
88+ *
99+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
1010+ * See the COPYING file in the top-level directory.
1111+ */
1212+1313+ .global safe_syscall_base
1414+ .global safe_syscall_start
1515+ .global safe_syscall_end
1616+ .type safe_syscall_base, @function
1717+1818+ .text
1919+2020+ /* This is the entry point for making a system call. The calling
2121+ * convention here is that of a C varargs function with the
2222+ * first argument an 'int *' to the signal_pending flag, the
2323+ * second one the system call number (as a 'long'), and all further
2424+ * arguments being syscall arguments (also 'long').
2525+ * We return a long which is the syscall's return value, which
2626+ * may be negative-errno on failure. Conversion to the
2727+ * -1-and-errno-set convention is done by the calling wrapper.
2828+ */
2929+#if _CALL_ELF == 2
3030+safe_syscall_base:
3131+ .cfi_startproc
3232+ .localentry safe_syscall_base,0
3333+#else
3434+ .section ".opd","aw"
3535+ .align 3
3636+safe_syscall_base:
3737+ .quad .L.safe_syscall_base,.TOC.@tocbase,0
3838+ .previous
3939+.L.safe_syscall_base:
4040+ .cfi_startproc
4141+#endif
4242+ /* We enter with r3 == *signal_pending
4343+ * r4 == syscall number
4444+ * r5 ... r10 == syscall arguments
4545+ * and return the result in r3
4646+ * and the syscall instruction needs
4747+ * r0 == syscall number
4848+ * r3 ... r8 == syscall arguments
4949+ * and returns the result in r3
5050+ * Shuffle everything around appropriately.
5151+ */
5252+ mr 11, 3 /* signal_pending */
5353+ mr 0, 4 /* syscall number */
5454+ mr 3, 5 /* syscall arguments */
5555+ mr 4, 6
5656+ mr 5, 7
5757+ mr 6, 8
5858+ mr 7, 9
5959+ mr 8, 10
6060+6161+ /* This next sequence of code works in conjunction with the
6262+ * rewind_if_safe_syscall_function(). If a signal is taken
6363+ * and the interrupted PC is anywhere between 'safe_syscall_start'
6464+ * and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'.
6565+ * The code sequence must therefore be able to cope with this, and
6666+ * the syscall instruction must be the final one in the sequence.
6767+ */
6868+safe_syscall_start:
6969+ /* if signal_pending is non-zero, don't do the call */
7070+ lwz 12, 0(11)
7171+ cmpwi 0, 12, 0
7272+ bne- 0f
7373+ sc
7474+safe_syscall_end:
7575+ /* code path when we did execute the syscall */
7676+ bnslr+
7777+7878+ /* syscall failed; return negative errno */
7979+ neg 3, 3
8080+ blr
8181+8282+ /* code path when we didn't execute the syscall */
8383+0: addi 3, 0, -TARGET_ERESTARTSYS
8484+ blr
8585+ .cfi_endproc
8686+8787+#if _CALL_ELF == 2
8888+ .size safe_syscall_base, .-safe_syscall_base
8989+#else
9090+ .size safe_syscall_base, .-.L.safe_syscall_base
9191+ .size .L.safe_syscall_base, .-.L.safe_syscall_base
9292+#endif