2 /*--------------------------------------------------------------------*/
3 /*--- Support for doing system calls. syscall-mips32-linux.S ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2010-2017 RT-RK
11 mips-valgrind@rt-rk.com
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_mips32_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 regs->v0. The syscall result is written
54 back to regs->v0 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)(
69 Int syscallno, // $4 - a0
70 void* guest_state, // $5 - a1
71 const vki_sigset_t *sysmask, // $6 - a2
72 const vki_sigset_t *postmask, // $7 - a3
73 Int nsigwords) // stack
76 #define VKI_SIG_SETMASK 3
78 .globl ML_(do_syscall_for_client_WRK)
79 ML_(do_syscall_for_client_WRK):
81 subu $29, $29, 56 #set up the steck frame,
99 /* Set the signal mask which should be current during the syscall. */
101 1: li $2, __NR_rt_sigprocmask
102 li $4, VKI_SIG_SETMASK
103 move $5, $6 /* sysmask */
104 move $6, $7 /* postmask */
105 lw $7, 72($29) /* nsigwords */
109 # TODO: this should remain, keep it just for now
113 lw $8, 48($29) /* t0 == ThreadState */
115 lw $2, 52($29) /* v0 == syscallno */
116 lw $4, OFFSET_mips32_r4($8)
117 lw $5, OFFSET_mips32_r5($8)
118 lw $6, OFFSET_mips32_r6($8)
119 lw $7, OFFSET_mips32_r7($8)
120 subu $29, $29, 24 #set up the steck frame,
121 lw $9, OFFSET_mips32_r29($8)
129 3: addu $29, $29, 24 #set up the steck frame,
131 lw $8, 48($29) /* t0 == ThreadState */
132 sw $2, OFFSET_mips32_r2($8)
133 sw $3, OFFSET_mips32_r3($8)
134 sw $7, OFFSET_mips32_r7($8)
136 4: li $2, __NR_rt_sigprocmask
137 li $4, VKI_SIG_SETMASK
140 lw $7, 72($29) /* nsigwords */
164 addu $29, $29, 56 #release the stack frame.
169 7: /* Failure: return 0x8000 | error code */
186 addu $29, $29, 56 #release the stack frame.
192 /* export the ranges so that
193 VG_(fixup_guest_state_after_syscall_interrupted) can do the
196 .globl ML_(blksys_setup)
197 .globl ML_(blksys_restart)
198 .globl ML_(blksys_complete)
199 .globl ML_(blksys_committed)
200 .globl ML_(blksys_finished)
201 ML_(blksys_setup): .long 1b
202 ML_(blksys_restart): .long 2b
203 ML_(blksys_complete): .long 3b
204 ML_(blksys_committed): .long 4b
205 ML_(blksys_finished): .long 5b
207 #endif // defined(VGP_mips32_linux)
209 /* Let the linker know we don't need an executable stack */
212 /*--------------------------------------------------------------------*/
214 /*--------------------------------------------------------------------*/