• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Return -1 on error or 1 on success (never 0!). */
2 static int
get_syscall_args(struct tcb * tcp)3 get_syscall_args(struct tcb *tcp)
4 {
5 	if (x86_io.iov_len != sizeof(i386_regs)) {
6 		/* x86-64 or x32 ABI */
7 		if (tcp->s_ent->sys_flags & COMPAT_SYSCALL_TYPES) {
8 			/*
9 			 * X32 compat syscall: zero-extend from 32 bits.
10 			 * Use truncate_klong_to_current_wordsize(tcp->u_arg[N])
11 			 * in syscall handlers
12 			 * if you need to use *sign-extended* parameter.
13 			 */
14 			tcp->u_arg[0] = (uint32_t) x86_64_regs.rdi;
15 			tcp->u_arg[1] = (uint32_t) x86_64_regs.rsi;
16 			tcp->u_arg[2] = (uint32_t) x86_64_regs.rdx;
17 			tcp->u_arg[3] = (uint32_t) x86_64_regs.r10;
18 			tcp->u_arg[4] = (uint32_t) x86_64_regs.r8;
19 			tcp->u_arg[5] = (uint32_t) x86_64_regs.r9;
20 		} else {
21 			tcp->u_arg[0] = x86_64_regs.rdi;
22 			tcp->u_arg[1] = x86_64_regs.rsi;
23 			tcp->u_arg[2] = x86_64_regs.rdx;
24 			tcp->u_arg[3] = x86_64_regs.r10;
25 			tcp->u_arg[4] = x86_64_regs.r8;
26 			tcp->u_arg[5] = x86_64_regs.r9;
27 		}
28 	} else {
29 		/*
30 		 * i386 ABI: zero-extend from 32 bits.
31 		 * Use truncate_klong_to_current_wordsize(tcp->u_arg[N])
32 		 * in syscall handlers
33 		 * if you need to use *sign-extended* parameter.
34 		 */
35 		tcp->u_arg[0] = (uint32_t) i386_regs.ebx;
36 		tcp->u_arg[1] = (uint32_t) i386_regs.ecx;
37 		tcp->u_arg[2] = (uint32_t) i386_regs.edx;
38 		tcp->u_arg[3] = (uint32_t) i386_regs.esi;
39 		tcp->u_arg[4] = (uint32_t) i386_regs.edi;
40 		tcp->u_arg[5] = (uint32_t) i386_regs.ebp;
41 	}
42 	return 1;
43 }
44