1 2 /*--------------------------------------------------------------------*/ 3 /*--- Support for doing system calls. syscall-arm64-linux.S ---*/ 4 /*--------------------------------------------------------------------*/ 5 6 /* 7 This file is part of Valgrind, a dynamic binary instrumentation 8 framework. 9 10 Copyright (C) 2013-2015 OpenWorks 11 info (at) open-works.net 12 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. 17 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. 22 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 26 02111-1307, USA. 27 28 The GNU General Public License is contained in the file COPYING. 29 */ 30 31 #include "pub_core_basics_asm.h" 32 33 #if defined(VGP_arm64_linux) 34 35 #include "pub_core_vkiscnums_asm.h" 36 #include "libvex_guest_offsets.h" 37 38 39 /*----------------------------------------------------------------*/ 40 /* 41 Perform a syscall for the client. This will run a syscall 42 with the client's specific per-thread signal mask. 43 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 50 interactions. 51 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. 55 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. 61 62 VG_(fixup_guest_state_after_syscall_interrupted) does the 63 thread state fixup in the case where we were interrupted by a 64 signal. 65 66 Prototype: 67 68 UWord ML_(do_syscall_for_client_WRK)( 69 Int syscallno, // x0 70 void* guest_state, // x1 71 const vki_sigset_t *sysmask, // x2 72 const vki_sigset_t *postmask, // x3 73 Int nsigwords) // x4 74 */ 75 /* from vki-arm64-linux.h */ 76 #define VKI_SIG_SETMASK 2 77 78 .globl ML_(do_syscall_for_client_WRK) 79 ML_(do_syscall_for_client_WRK): 80 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]! 91 92 1: 93 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 */ 99 svc 0x00000000 100 101 102 ldr x5, [sp, #8] /* saved x1 == guest_state */ 103 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] 111 112 2: svc 0x00000000 113 3: 114 ldr x5, [sp, #8] /* saved x1 == guest_state */ 115 str x0, [x5, #OFFSET_arm64_X0] 116 117 4: 118 mov x8, #__NR_rt_sigprocmask 119 mov x0, #VKI_SIG_SETMASK 120 ldr x1, [sp, #24] /* saved x3 == postmask */ 121 mov x2, #0 122 ldr x3, [sp, #32] /* saved x4 == nsigwords */ 123 svc 0x00000000 124 125 cmp x0, #0 126 blt 7f 127 128 5: /* Success: return zero */ 129 mov x0, #0 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 139 ret 140 141 7: /* Failure: return 0x8000 | error code */ 142 orr x0, x0, #0x8000 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 152 ret 153 154 155 156 .section .rodata 157 /* export the ranges so that 158 VG_(fixup_guest_state_after_syscall_interrupted) can do the 159 right thing */ 160 161 .align 3 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 172 173 #endif // defined(VGP_arm_linux) 174 175 /* Let the linker know we don't need an executable stack */ 176 MARK_STACK_NO_EXEC 177 178 /*--------------------------------------------------------------------*/ 179 /*--- end ---*/ 180 /*--------------------------------------------------------------------*/ 181