1 /*
2 * Copyright (c) 2015-2021 The strace developers.
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7
8 /* Return -1 on error or 1 on success (never 0!). */
9 static int
10 arch_get_syscall_args(struct tcb *tcp)
11 {
12 if (x86_io.iov_len != sizeof(i386_regs)) {
13 /* x86-64 or x32 ABI */
14 if (tcp_sysent(tcp)->sys_flags & COMPAT_SYSCALL_TYPES) {
15 /*
16 * X32 compat syscall: zero-extend from 32 bits.
17 * Use truncate_klong_to_current_wordsize(tcp->u_arg[N])
18 * in syscall handlers
19 * if you need to use *sign-extended* parameter.
20 */
21 tcp->u_arg[0] = (uint32_t) x86_64_regs.rdi;
22 tcp->u_arg[1] = (uint32_t) x86_64_regs.rsi;
23 tcp->u_arg[2] = (uint32_t) x86_64_regs.rdx;
24 tcp->u_arg[3] = (uint32_t) x86_64_regs.r10;
25 tcp->u_arg[4] = (uint32_t) x86_64_regs.r8;
26 tcp->u_arg[5] = (uint32_t) x86_64_regs.r9;
27 } else {
28 tcp->u_arg[0] = x86_64_regs.rdi;
29 tcp->u_arg[1] = x86_64_regs.rsi;
30 tcp->u_arg[2] = x86_64_regs.rdx;
31 tcp->u_arg[3] = x86_64_regs.r10;
32 tcp->u_arg[4] = x86_64_regs.r8;
33 tcp->u_arg[5] = x86_64_regs.r9;
34 }
35 } else {
36 /*
37 * i386 ABI: zero-extend from 32 bits.
38 * Use truncate_klong_to_current_wordsize(tcp->u_arg[N])
39 * in syscall handlers
40 * if you need to use *sign-extended* parameter.
41 */
42 tcp->u_arg[0] = (uint32_t) i386_regs.ebx;
43 tcp->u_arg[1] = (uint32_t) i386_regs.ecx;
44 tcp->u_arg[2] = (uint32_t) i386_regs.edx;
45 tcp->u_arg[3] = (uint32_t) i386_regs.esi;
46 tcp->u_arg[4] = (uint32_t) i386_regs.edi;
47 tcp->u_arg[5] = (uint32_t) i386_regs.ebp;
48 }
49 return 1;
50 }