1 /* Return -1 on error or 1 on success (never 0!). */ 2 static int get_syscall_args(struct tcb * tcp)3get_syscall_args(struct tcb *tcp) 4 { 5 if (x86_io.iov_len != sizeof(i386_regs)) { 6 /* x86-64 or x32 ABI */ 7 tcp->u_arg[0] = x86_64_regs.rdi; 8 tcp->u_arg[1] = x86_64_regs.rsi; 9 tcp->u_arg[2] = x86_64_regs.rdx; 10 tcp->u_arg[3] = x86_64_regs.r10; 11 tcp->u_arg[4] = x86_64_regs.r8; 12 tcp->u_arg[5] = x86_64_regs.r9; 13 #ifdef X32 14 tcp->ext_arg[0] = x86_64_regs.rdi; 15 tcp->ext_arg[1] = x86_64_regs.rsi; 16 tcp->ext_arg[2] = x86_64_regs.rdx; 17 tcp->ext_arg[3] = x86_64_regs.r10; 18 tcp->ext_arg[4] = x86_64_regs.r8; 19 tcp->ext_arg[5] = x86_64_regs.r9; 20 #endif 21 } else { 22 /* i386 ABI */ 23 /* Zero-extend from 32 bits */ 24 /* Use widen_to_long(tcp->u_arg[N]) in syscall handlers 25 * if you need to use *sign-extended* parameter. 26 */ 27 tcp->u_arg[0] = (long)(uint32_t)i386_regs.ebx; 28 tcp->u_arg[1] = (long)(uint32_t)i386_regs.ecx; 29 tcp->u_arg[2] = (long)(uint32_t)i386_regs.edx; 30 tcp->u_arg[3] = (long)(uint32_t)i386_regs.esi; 31 tcp->u_arg[4] = (long)(uint32_t)i386_regs.edi; 32 tcp->u_arg[5] = (long)(uint32_t)i386_regs.ebp; 33 } 34 return 1; 35 } 36