2 /*--------------------------------------------------------------------*/
3 /*--- Support for doing system calls. syscall-arm64-linux.S ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2013-2017 OpenWorks
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 #include "pub_core_basics_asm.h"
31 #if defined(VGP_arm64_linux)
33 #include "pub_core_vkiscnums_asm.h"
34 #include "libvex_guest_offsets.h"
37 /*----------------------------------------------------------------*/
39 Perform a syscall for the client. This will run a syscall
40 with the client's specific per-thread signal mask.
42 The structure of this function is such that, if the syscall is
43 interrupted by a signal, we can determine exactly what
44 execution state we were in with respect to the execution of
45 the syscall by examining the value of IP in the signal
46 handler. This means that we can always do the appropriate
47 thing to precisely emulate the kernel's signal/syscall
50 The syscall number is taken from the argument, even though it
51 should also be in guest_state->guest_X8. The syscall result
52 is written back to guest_state->guest_X0 on completion.
54 Returns 0 if the syscall was successfully called (even if the
55 syscall itself failed), or a nonzero error code in the lowest
56 8 bits if one of the sigprocmasks failed (there's no way to
57 determine which one failed). And there's no obvious way to
58 recover from that either, but nevertheless we want to know.
60 VG_(fixup_guest_state_after_syscall_interrupted) does the
61 thread state fixup in the case where we were interrupted by a
66 UWord ML_(do_syscall_for_client_WRK)(
68 void* guest_state, // x1
69 const vki_sigset_t *sysmask, // x2
70 const vki_sigset_t *postmask, // x3
73 /* from vki-arm64-linux.h */
74 #define VKI_SIG_SETMASK 2
76 .globl ML_(do_syscall_for_client_WRK)
77 ML_(do_syscall_for_client_WRK):
79 /* Stash callee-saves and our args on the stack */
80 stp x29, x30, [sp, #-16]!
81 stp x27, x28, [sp, #-16]!
82 stp x25, x26, [sp, #-16]!
83 stp x23, x24, [sp, #-16]!
84 stp x21, x22, [sp, #-16]!
85 stp x19, x20, [sp, #-16]!
86 stp x4, x5, [sp, #-16]!
87 stp x2, x3, [sp, #-16]!
88 stp x0, x1, [sp, #-16]!
92 mov x8, #__NR_rt_sigprocmask
93 mov x0, #VKI_SIG_SETMASK
94 mov x1, x2 /* sysmask */
95 mov x2, x3 /* postmask */
96 mov x3, x4 /* nsigwords */
100 ldr x5, [sp, #8] /* saved x1 == guest_state */
102 ldr x8, [sp, #0] /* saved x0 == syscall# */
103 ldr x0, [x5, #OFFSET_arm64_X0]
104 ldr x1, [x5, #OFFSET_arm64_X1]
105 ldr x2, [x5, #OFFSET_arm64_X2]
106 ldr x3, [x5, #OFFSET_arm64_X3]
107 ldr x4, [x5, #OFFSET_arm64_X4]
108 ldr x5, [x5, #OFFSET_arm64_X5]
112 ldr x5, [sp, #8] /* saved x1 == guest_state */
113 str x0, [x5, #OFFSET_arm64_X0]
116 mov x8, #__NR_rt_sigprocmask
117 mov x0, #VKI_SIG_SETMASK
118 ldr x1, [sp, #24] /* saved x3 == postmask */
120 ldr x3, [sp, #32] /* saved x4 == nsigwords */
126 5: /* Success: return zero */
128 ldp xzr, x1, [sp], #16
129 ldp x2, x3, [sp], #16
130 ldp x4, x5, [sp], #16
131 ldp x19, x20, [sp], #16
132 ldp x21, x22, [sp], #16
133 ldp x23, x24, [sp], #16
134 ldp x25, x26, [sp], #16
135 ldp x27, x28, [sp], #16
136 ldp x29, x30, [sp], #16
139 7: /* Failure: return 0x8000 | error code */
141 ldp xzr, x1, [sp], #16
142 ldp x2, x3, [sp], #16
143 ldp x4, x5, [sp], #16
144 ldp x19, x20, [sp], #16
145 ldp x21, x22, [sp], #16
146 ldp x23, x24, [sp], #16
147 ldp x25, x26, [sp], #16
148 ldp x27, x28, [sp], #16
149 ldp x29, x30, [sp], #16
155 /* export the ranges so that
156 VG_(fixup_guest_state_after_syscall_interrupted) can do the
160 .globl ML_(blksys_setup)
161 .globl ML_(blksys_restart)
162 .globl ML_(blksys_complete)
163 .globl ML_(blksys_committed)
164 .globl ML_(blksys_finished)
165 ML_(blksys_setup): .quad 1b
166 ML_(blksys_restart): .quad 2b
167 ML_(blksys_complete): .quad 3b
168 ML_(blksys_committed): .quad 4b
169 ML_(blksys_finished): .quad 5b
171 #endif // defined(VGP_arm_linux)
173 /* Let the linker know we don't need an executable stack */
176 /*--------------------------------------------------------------------*/
178 /*--------------------------------------------------------------------*/