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-2013 OpenWorks 11 info@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#if defined(VGP_arm64_linux) 32 33#include "pub_core_basics_asm.h" 34#include "pub_core_vkiscnums_asm.h" 35#include "libvex_guest_offsets.h" 36 37 38/*----------------------------------------------------------------*/ 39/* 40 Perform a syscall for the client. This will run a syscall 41 with the client's specific per-thread signal mask. 42 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 49 interactions. 50 51 The syscall number is taken from the argument, even though it 52 should also be in guest_state->guest_X8. The syscall result 53 is written back to guest_state->guest_X0 on completion. 54 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. 60 61 VG_(fixup_guest_state_after_syscall_interrupted) does the 62 thread state fixup in the case where we were interrupted by a 63 signal. 64 65 Prototype: 66 67 UWord ML_(do_syscall_for_client_WRK)( 68 Int syscallno, // x0 69 void* guest_state, // x1 70 const vki_sigset_t *sysmask, // x2 71 const vki_sigset_t *postmask, // x3 72 Int nsigwords) // x4 73*/ 74/* from vki-arm64-linux.h */ 75#define VKI_SIG_SETMASK 2 76 77.globl ML_(do_syscall_for_client_WRK) 78ML_(do_syscall_for_client_WRK): 79 80 /* Stash callee-saves and our args on the stack */ 81 stp x29, x30, [sp, #-16]! 82 stp x27, x28, [sp, #-16]! 83 stp x25, x26, [sp, #-16]! 84 stp x23, x24, [sp, #-16]! 85 stp x21, x22, [sp, #-16]! 86 stp x19, x20, [sp, #-16]! 87 stp x4, x5, [sp, #-16]! 88 stp x2, x3, [sp, #-16]! 89 stp x0, x1, [sp, #-16]! 90 911: 92 93 mov x8, #__NR_rt_sigprocmask 94 mov x0, #VKI_SIG_SETMASK 95 mov x1, x2 /* sysmask */ 96 mov x2, x3 /* postmask */ 97 mov x3, x4 /* nsigwords */ 98 svc 0x00000000 99 100 101 ldr x5, [sp, #8] /* saved x1 == guest_state */ 102 103 ldr x8, [sp, #0] /* saved x0 == syscall# */ 104 ldr x0, [x5, #OFFSET_arm64_X0] 105 ldr x1, [x5, #OFFSET_arm64_X1] 106 ldr x2, [x5, #OFFSET_arm64_X2] 107 ldr x3, [x5, #OFFSET_arm64_X3] 108 ldr x4, [x5, #OFFSET_arm64_X4] 109 ldr x5, [x5, #OFFSET_arm64_X5] 110 1112: svc 0x00000000 1123: 113 ldr x5, [sp, #8] /* saved x1 == guest_state */ 114 str x0, [x5, #OFFSET_arm64_X0] 115 1164: 117 mov x8, #__NR_rt_sigprocmask 118 mov x0, #VKI_SIG_SETMASK 119 ldr x1, [sp, #24] /* saved x3 == postmask */ 120 mov x2, #0 121 ldr x3, [sp, #32] /* saved x4 == nsigwords */ 122 svc 0x00000000 123 124 cmp x0, #0 125 blt 7f 126 1275: /* Success: return zero */ 128 mov x0, #0 129 ldp xzr, x1, [sp], #16 130 ldp x2, x3, [sp], #16 131 ldp x4, x5, [sp], #16 132 ldp x19, x20, [sp], #16 133 ldp x21, x22, [sp], #16 134 ldp x23, x24, [sp], #16 135 ldp x25, x26, [sp], #16 136 ldp x27, x28, [sp], #16 137 ldp x29, x30, [sp], #16 138 ret 139 1407: /* Failure: return 0x8000 | error code */ 141 orr x0, x0, #0x8000 142 ldp xzr, x1, [sp], #16 143 ldp x2, x3, [sp], #16 144 ldp x4, x5, [sp], #16 145 ldp x19, x20, [sp], #16 146 ldp x21, x22, [sp], #16 147 ldp x23, x24, [sp], #16 148 ldp x25, x26, [sp], #16 149 ldp x27, x28, [sp], #16 150 ldp x29, x30, [sp], #16 151 ret 152 153 154 155.section .rodata 156/* export the ranges so that 157 VG_(fixup_guest_state_after_syscall_interrupted) can do the 158 right thing */ 159 160.align 3 161.globl ML_(blksys_setup) 162.globl ML_(blksys_restart) 163.globl ML_(blksys_complete) 164.globl ML_(blksys_committed) 165.globl ML_(blksys_finished) 166ML_(blksys_setup): .quad 1b 167ML_(blksys_restart): .quad 2b 168ML_(blksys_complete): .quad 3b 169ML_(blksys_committed): .quad 4b 170ML_(blksys_finished): .quad 5b 171 172/* Let the linker know we don't need an executable stack */ 173.section .note.GNU-stack,"",%progbits 174 175.previous 176 177#endif // defined(VGP_arm_linux) 178 179/*--------------------------------------------------------------------*/ 180/*--- end ---*/ 181/*--------------------------------------------------------------------*/ 182