2 /*--------------------------------------------------------------------*/
3 /*--- Support for doing system calls. syscall-s390x-linux.S ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright IBM Corp. 2010-2017
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, see <http://www.gnu.org/licenses/>.
25 The GNU General Public License is contained in the file COPYING.
28 /* Contributed by Christian Borntraeger */
30 #include "pub_core_basics_asm.h"
31 #include "pub_core_vkiscnums_asm.h"
32 #include "libvex_guest_offsets.h"
34 #if defined(VGA_s390x)
36 /*----------------------------------------------------------------*/
38 Perform a syscall for the client. This will run a syscall
39 with the client's specific per-thread signal mask.
41 The structure of this function is such that, if the syscall is
42 interrupted by a signal, we can determine exactly what
43 execution state we were in with respect to the execution of
44 the syscall by examining the value of NIP in the signal
45 handler. This means that we can always do the appropriate
46 thing to precisely emulate the kernel's signal/syscall
49 The syscall number is taken from the argument, since the syscall
50 number can be encoded in the svc instruction itself.
51 The syscall result is written back to guest register r2.
53 Returns 0 if the syscall was successfully called (even if the
54 syscall itself failed), or a nonzero error code in the lowest
55 8 bits if one of the sigprocmasks failed (there's no way to
56 determine which one failed). And there's no obvious way to
57 recover from that either, but nevertheless we want to know.
59 VG_(fixup_guest_state_after_syscall_interrupted) does the
60 thread state fixup in the case where we were interrupted by a
65 UWord ML_(do_syscall_for_client_WRK)(
67 void* guest_state, // r3
68 const vki_sigset_t *sysmask, // r4
69 const vki_sigset_t *postmask, // r5
73 #define VKI_SIG_SETMASK 2
76 #define SP_R2 SP_SAVE + 0*8
77 #define SP_R3 SP_SAVE + 1*8
78 #define SP_R4 SP_SAVE + 2*8
79 #define SP_R5 SP_SAVE + 3*8
80 #define SP_R6 SP_SAVE + 4*8
81 #define SP_R7 SP_SAVE + 5*8
82 #define SP_R8 SP_SAVE + 6*8
83 #define SP_R9 SP_SAVE + 7*8
86 .globl ML_(do_syscall_for_client_WRK)
87 ML_(do_syscall_for_client_WRK):
88 1: /* Even though we can't take a signal until the sigprocmask completes,
89 start the range early.
90 If IA is in the range [1,2), the syscall hasn't been started yet */
92 /* Set the signal mask which should be current during the syscall. */
93 /* Save and restore all the parameters and all the registers that
95 stmg %r2,%r9, SP_R2(%r15)
97 lghi %r2, VKI_SIG_SETMASK /* how */
98 lgr %r3, %r4 /* sysmask */
99 lgr %r4, %r5 /* postmask */
100 lgr %r5, %r6 /* nsigwords */
101 svc __NR_rt_sigprocmask
103 jne 7f /* sigprocmask failed */
105 /* OK, that worked. Now do the syscall proper. */
106 lg %r9, SP_R3(%r15) /* guest state --> r9 */
107 lg %r2, OFFSET_s390x_r2(%r9) /* guest r2 --> real r2 */
108 lg %r3, OFFSET_s390x_r3(%r9) /* guest r3 --> real r3 */
109 lg %r4, OFFSET_s390x_r4(%r9) /* guest r4 --> real r4 */
110 lg %r5, OFFSET_s390x_r5(%r9) /* guest r5 --> real r5 */
111 lg %r6, OFFSET_s390x_r6(%r9) /* guest r6 --> real r6 */
112 lg %r7, OFFSET_s390x_r7(%r9) /* guest r7 --> real r7 */
113 lg %r1, SP_R2(%r15) /* syscallno -> r1 */
118 stg %r2, OFFSET_s390x_r2(%r9)
120 4: /* Re-block signals. If IA is in [4,5), then the syscall
121 is complete and we needn't worry about it. */
122 lghi %r2, VKI_SIG_SETMASK /* how */
123 lg %r3, SP_R5(%r15) /* postmask */
124 lghi %r4, 0x0 /* NULL */
125 lg %r5, SP_R6(%r15) /* nsigwords */
126 svc __NR_rt_sigprocmask
128 jne 7f /* sigprocmask failed */
130 5: /* Everyting ok. Return 0 and restore the call-saved
131 registers, that we have clobbered */
133 lmg %r6,%r9, SP_R6(%r15)
136 7: /* Some problem. Return 0x8000 | error and restore the call-saved
137 registers we have clobbered. */
140 lmg %r6,%r9, SP_R6(%r15)
144 /* Export the ranges so that
145 VG_(fixup_guest_state_after_syscall_interrupted) can do the
148 .globl ML_(blksys_setup)
149 .globl ML_(blksys_restart)
150 .globl ML_(blksys_complete)
151 .globl ML_(blksys_committed)
152 .globl ML_(blksys_finished)
154 /* The compiler can assume that 8 byte data elements are aligned on 8 byte */
156 ML_(blksys_setup): .quad 1b
157 ML_(blksys_restart): .quad 2b
158 ML_(blksys_complete): .quad 3b
159 ML_(blksys_committed): .quad 4b
160 ML_(blksys_finished): .quad 5b
163 #endif /* VGA_s390x */
165 /* Let the linker know we don't need an executable stack */
168 /*--------------------------------------------------------------------*/
170 /*--------------------------------------------------------------------*/