2 /*--------------------------------------------------------------------*/
3 /*--- Support for doing system calls. syscall-arm-linux.S ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2008-2017 Evan Geller (gaze@bea.ms)
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 The GNU General Public License is contained in the file COPYING.
30 #include "pub_core_basics_asm.h"
32 #if defined(VGP_arm_linux)
34 #include "pub_core_vkiscnums_asm.h"
35 #include "libvex_guest_offsets.h"
38 /*----------------------------------------------------------------*/
40 Perform a syscall for the client. This will run a syscall
41 with the client's specific per-thread signal mask.
43 The structure of this function is such that, if the syscall is
44 interrupted by a signal, we can determine exactly what
45 execution state we were in with respect to the execution of
46 the syscall by examining the value of IP in the signal
47 handler. This means that we can always do the appropriate
48 thing to precisely emulate the kernel's signal/syscall
51 The syscall number is taken from the argument, even though it
52 should also be in regs->m_R7. The syscall result is written
53 back to regs->m_R0 on completion.
55 Returns 0 if the syscall was successfully called (even if the
56 syscall itself failed), or a nonzero error code in the lowest
57 8 bits if one of the sigprocmasks failed (there's no way to
58 determine which one failed). And there's no obvious way to
59 recover from that either, but nevertheless we want to know.
61 VG_(fixup_guest_state_after_syscall_interrupted) does the
62 thread state fixup in the case where we were interrupted by a
67 UWord ML_(do_syscall_for_client_WRK)(
69 void* guest_state, // r1
70 const vki_sigset_t *sysmask, // r2
71 const vki_sigset_t *postmask, // r3
72 Int nsigwords) // [sp, #0]
75 #define VKI_SIG_SETMASK 2
77 .globl ML_(do_syscall_for_client_WRK)
78 ML_(do_syscall_for_client_WRK):
80 /* Stash callee-saves and our args on the stack */
81 push {r0, r1, r3, r4, r5, r7, fp, lr}
85 mov r7, #__NR_rt_sigprocmask
86 mov r0, #VKI_SIG_SETMASK
87 mov r1, r2 /* sysmask */
88 mov r2, r3 /* postmask */
89 ldr r3, [sp, #32] /* nsigwords */
93 ldr r5, [sp, #4] /* guest_state */
95 ldr r7, [sp, #0] /* syscall# */
96 ldr r0, [r5, #OFFSET_arm_R0]
97 ldr r1, [r5, #OFFSET_arm_R1]
98 ldr r2, [r5, #OFFSET_arm_R2]
99 ldr r3, [r5, #OFFSET_arm_R3]
100 ldr r4, [r5, #OFFSET_arm_R4]
101 ldr r5, [r5, #OFFSET_arm_R5]
105 ldr r5, [sp, #4] /* guest_state */
106 str r0, [r5, #OFFSET_arm_R0]
109 mov r7, #__NR_rt_sigprocmask
110 mov r0, #VKI_SIG_SETMASK
111 ldr r1, [sp, #8] /* postmask */
113 ldr r3, [sp, #32] /* nsigwords */
118 add sp, sp, #4 /* r0 contains return value */
122 pop {r1, r3, r4, r5, r7, fp, pc}
124 7: /* Failure: return 0x8000 | error code */
126 pop {r1, r3, r4, r5, r7, fp, pc}
130 /* export the ranges so that
131 VG_(fixup_guest_state_after_syscall_interrupted) can do the
134 .globl ML_(blksys_setup)
135 .globl ML_(blksys_restart)
136 .globl ML_(blksys_complete)
137 .globl ML_(blksys_committed)
138 .globl ML_(blksys_finished)
139 ML_(blksys_setup): .long 1b
140 ML_(blksys_restart): .long 2b
141 ML_(blksys_complete): .long 3b
142 ML_(blksys_committed): .long 4b
143 ML_(blksys_finished): .long 5b
145 #endif // defined(VGP_arm_linux)
147 /* Let the linker know we don't need an executable stack */
150 /*--------------------------------------------------------------------*/
152 /*--------------------------------------------------------------------*/