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, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 The GNU General Public License is contained in the file COPYING.
31 #include "pub_core_basics_asm.h"
33 #if defined(VGP_arm64_linux)
35 #include "pub_core_vkiscnums_asm.h"
36 #include "libvex_guest_offsets.h"
39 /*----------------------------------------------------------------*/
41 Perform a syscall for the client. This will run a syscall
42 with the client's specific per-thread signal mask.
44 The structure of this function is such that, if the syscall is
45 interrupted by a signal, we can determine exactly what
46 execution state we were in with respect to the execution of
47 the syscall by examining the value of IP in the signal
48 handler. This means that we can always do the appropriate
49 thing to precisely emulate the kernel's signal/syscall
52 The syscall number is taken from the argument, even though it
53 should also be in guest_state->guest_X8. The syscall result
54 is written back to guest_state->guest_X0 on completion.
56 Returns 0 if the syscall was successfully called (even if the
57 syscall itself failed), or a nonzero error code in the lowest
58 8 bits if one of the sigprocmasks failed (there's no way to
59 determine which one failed). And there's no obvious way to
60 recover from that either, but nevertheless we want to know.
62 VG_(fixup_guest_state_after_syscall_interrupted) does the
63 thread state fixup in the case where we were interrupted by a
68 UWord ML_(do_syscall_for_client_WRK)(
70 void* guest_state, // x1
71 const vki_sigset_t *sysmask, // x2
72 const vki_sigset_t *postmask, // x3
75 /* from vki-arm64-linux.h */
76 #define VKI_SIG_SETMASK 2
78 .globl ML_(do_syscall_for_client_WRK)
79 ML_(do_syscall_for_client_WRK):
81 /* Stash callee-saves and our args on the stack */
82 stp x29, x30, [sp, #-16]!
83 stp x27, x28, [sp, #-16]!
84 stp x25, x26, [sp, #-16]!
85 stp x23, x24, [sp, #-16]!
86 stp x21, x22, [sp, #-16]!
87 stp x19, x20, [sp, #-16]!
88 stp x4, x5, [sp, #-16]!
89 stp x2, x3, [sp, #-16]!
90 stp x0, x1, [sp, #-16]!
94 mov x8, #__NR_rt_sigprocmask
95 mov x0, #VKI_SIG_SETMASK
96 mov x1, x2 /* sysmask */
97 mov x2, x3 /* postmask */
98 mov x3, x4 /* nsigwords */
102 ldr x5, [sp, #8] /* saved x1 == guest_state */
104 ldr x8, [sp, #0] /* saved x0 == syscall# */
105 ldr x0, [x5, #OFFSET_arm64_X0]
106 ldr x1, [x5, #OFFSET_arm64_X1]
107 ldr x2, [x5, #OFFSET_arm64_X2]
108 ldr x3, [x5, #OFFSET_arm64_X3]
109 ldr x4, [x5, #OFFSET_arm64_X4]
110 ldr x5, [x5, #OFFSET_arm64_X5]
114 ldr x5, [sp, #8] /* saved x1 == guest_state */
115 str x0, [x5, #OFFSET_arm64_X0]
118 mov x8, #__NR_rt_sigprocmask
119 mov x0, #VKI_SIG_SETMASK
120 ldr x1, [sp, #24] /* saved x3 == postmask */
122 ldr x3, [sp, #32] /* saved x4 == nsigwords */
128 5: /* Success: return zero */
130 ldp xzr, x1, [sp], #16
131 ldp x2, x3, [sp], #16
132 ldp x4, x5, [sp], #16
133 ldp x19, x20, [sp], #16
134 ldp x21, x22, [sp], #16
135 ldp x23, x24, [sp], #16
136 ldp x25, x26, [sp], #16
137 ldp x27, x28, [sp], #16
138 ldp x29, x30, [sp], #16
141 7: /* Failure: return 0x8000 | error code */
143 ldp xzr, x1, [sp], #16
144 ldp x2, x3, [sp], #16
145 ldp x4, x5, [sp], #16
146 ldp x19, x20, [sp], #16
147 ldp x21, x22, [sp], #16
148 ldp x23, x24, [sp], #16
149 ldp x25, x26, [sp], #16
150 ldp x27, x28, [sp], #16
151 ldp x29, x30, [sp], #16
157 /* export the ranges so that
158 VG_(fixup_guest_state_after_syscall_interrupted) can do the
162 .globl ML_(blksys_setup)
163 .globl ML_(blksys_restart)
164 .globl ML_(blksys_complete)
165 .globl ML_(blksys_committed)
166 .globl ML_(blksys_finished)
167 ML_(blksys_setup): .quad 1b
168 ML_(blksys_restart): .quad 2b
169 ML_(blksys_complete): .quad 3b
170 ML_(blksys_committed): .quad 4b
171 ML_(blksys_finished): .quad 5b
173 #endif // defined(VGP_arm_linux)
175 /* Let the linker know we don't need an executable stack */
178 /*--------------------------------------------------------------------*/
180 /*--------------------------------------------------------------------*/