Home | History | Annotate | Download | only in m_syswrap
      1 
      2 /*--------------------------------------------------------------------*/
      3 /*--- Support for doing system calls.        syscall-arm-linux.S ---*/
      4 /*--------------------------------------------------------------------*/
      5 
      6 /*
      7   This file is part of Valgrind, a dynamic binary instrumentation
      8   framework.
      9 
     10   Copyright (C) 2008-2012 Evan Geller (gaze (at) bea.ms)
     11 
     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.
     16 
     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.
     21 
     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
     25   02111-1307, USA.
     26 
     27   The GNU General Public License is contained in the file COPYING.
     28 */
     29 
     30 #if defined(VGP_arm_linux)
     31 
     32 #include "pub_core_basics_asm.h"
     33 #include "pub_core_vkiscnums_asm.h"
     34 #include "libvex_guest_offsets.h"
     35 
     36 
     37 /*----------------------------------------------------------------*/
     38 /*
     39         Perform a syscall for the client.  This will run a syscall
     40         with the client's specific per-thread signal mask.
     41 
     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
     48         interactions.
     49 
     50         The syscall number is taken from the argument, even though it
     51         should also be in regs->m_R7.  The syscall result is written
     52         back to regs->m_R0 on completion.
     53 
     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.
     59 
     60         VG_(fixup_guest_state_after_syscall_interrupted) does the
     61         thread state fixup in the case where we were interrupted by a
     62         signal.
     63 
     64         Prototype:
     65 
     66    UWord ML_(do_syscall_for_client_WRK)(
     67               Int syscallno,                 // r0
     68               void* guest_state,             // r1
     69               const vki_sigset_t *sysmask,   // r2
     70               const vki_sigset_t *postmask,  // r3
     71               Int nsigwords)                 // [sp, #0]
     72 */
     73 /* from vki_arch.h */
     74 #define VKI_SIG_SETMASK 2
     75 
     76 .globl ML_(do_syscall_for_client_WRK)
     77 ML_(do_syscall_for_client_WRK):
     78 
     79    /* Stash callee-saves and our args on the stack */
     80    push {r0, r1, r3, r4, r5, r7, fp, lr}
     81 
     82 1:
     83 
     84    mov r7, #__NR_rt_sigprocmask
     85    mov r0, #VKI_SIG_SETMASK
     86    mov r1, r2 /* sysmask */
     87    mov r2, r3 /* postmask */
     88    ldr r3, [sp, #32] /* nsigwords */
     89    svc 0x00000000
     90 
     91 
     92    ldr r5, [sp, #4] /* guest_state */
     93 
     94    ldr r7, [sp, #0] /* syscall# */
     95    ldr r0, [r5, #OFFSET_arm_R0]
     96    ldr r1, [r5, #OFFSET_arm_R1]
     97    ldr r2, [r5, #OFFSET_arm_R2]
     98    ldr r3, [r5, #OFFSET_arm_R3]
     99    ldr r4, [r5, #OFFSET_arm_R4]
    100    ldr r5, [r5, #OFFSET_arm_R5]
    101 
    102 2: svc 0x00000000
    103 3:
    104    ldr r5, [sp, #4] /* guest_state */
    105    str r0, [r5, #OFFSET_arm_R0]
    106 
    107 4:
    108    mov r7, #__NR_rt_sigprocmask
    109    mov r0, #VKI_SIG_SETMASK
    110    ldr r1, [sp, #8] /* postmask */
    111    mov r2, #0
    112    ldr r3, [sp, #32] /* nsigwords */
    113    svc 0x00000000
    114 
    115   cmp r0, #0
    116    blt 7f
    117    add sp, sp, #4 /* r0 contains return value */
    118 
    119 5: /* Success */
    120    mov r0, #0
    121    pop {r1, r3, r4, r5, r7, fp, pc}
    122 
    123 7: /* Failure: return 0x8000 | error code */
    124    orr r0, r0, #0x8000
    125    pop {r1, r3, r4, r5, r7, fp, pc}
    126 
    127 
    128 .section .rodata
    129 /* export the ranges so that
    130    VG_(fixup_guest_state_after_syscall_interrupted) can do the
    131    right thing */
    132 
    133 .globl ML_(blksys_setup)
    134 .globl ML_(blksys_restart)
    135 .globl ML_(blksys_complete)
    136 .globl ML_(blksys_committed)
    137 .globl ML_(blksys_finished)
    138 ML_(blksys_setup):      .long 1b
    139 ML_(blksys_restart):    .long 2b
    140 ML_(blksys_complete):   .long 3b
    141 ML_(blksys_committed):  .long 4b
    142 ML_(blksys_finished):   .long 5b
    143 
    144 /* Let the linker know we don't need an executable stack */
    145 .section .note.GNU-stack,"",%progbits
    146 
    147 .previous
    148 
    149 #endif // defined(VGP_arm_linux)
    150 
    151 /*--------------------------------------------------------------------*/
    152 /*--- end                                                          ---*/
    153 /*--------------------------------------------------------------------*/
    154