[SCM] strace branch, master, updated. v4.6-124-geb0e3e8

Dmitry V. Levin ldv at altlinux.org
Fri Feb 15 01:28:17 UTC 2013


Denys,

On Tue, Aug 30, 2011 at 05:04:35PM +0000, Denys Vlasenko wrote:
[...]
> @@ -1553,14 +1536,24 @@ syscall_enter(struct tcb *tcp)
>  		if (upeek(tcp, REG_GENERAL(syscall_regs[i]), &tcp->u_arg[i]) < 0)
>  			return -1;
>  # elif defined(X86_64)
> -	static const int argreg[SUPPORTED_PERSONALITIES][MAX_ARGS] = {
> -		{ 8 * RDI, 8 * RSI, 8 * RDX, 8 * R10, 8 * R8 , 8 * R9  }, /* x86-64 ABI */
> -		{ 8 * RBX, 8 * RCX, 8 * RDX, 8 * RSI, 8 * RDI, 8 * RBP }  /* i386 ABI */
> -	};
> -
> -	for (i = 0; i < nargs; ++i)
> -		if (upeek(tcp, argreg[current_personality][i], &tcp->u_arg[i]) < 0)
> -			return -1;
> +	(void)i;
> +	(void)nargs;
> +	if (current_personality == 0) { /* x86-64 ABI */
> +		tcp->u_arg[0] = x86_64_regs.rdi;
> +		tcp->u_arg[1] = x86_64_regs.rsi;
> +		tcp->u_arg[2] = x86_64_regs.rdx;
> +		tcp->u_arg[3] = x86_64_regs.r10;
> +		tcp->u_arg[4] = x86_64_regs.r8;
> +		tcp->u_arg[5] = x86_64_regs.r9;
> +	} else { /* i386 ABI */
> +		/* Sign-extend lower 32 bits */
> +		tcp->u_arg[0] = (long)(int)x86_64_regs.rbx;
> +		tcp->u_arg[1] = (long)(int)x86_64_regs.rcx;
> +		tcp->u_arg[2] = (long)(int)x86_64_regs.rdx;
> +		tcp->u_arg[3] = (long)(int)x86_64_regs.rsi;
> +		tcp->u_arg[4] = (long)(int)x86_64_regs.rdi;
> +		tcp->u_arg[5] = (long)(int)x86_64_regs.rbp;
> +	}
>  # elif defined(MICROBLAZE)
>  	for (i = 0; i < nargs; ++i)
>  		if (upeek(tcp, (5 + i) * 4, &tcp->u_arg[i]) < 0)

This sign-extending on x86-64 appeared to be not so good after all.
I don't remember many syscalls taking signed long arguments, but there are
a lot that take pointers, and these are displayed wrongly now, e.g.

$ strace -etrace=uname,mprotect,mmap2,munmap,set_thread_area,fstat64 -everbose=none /path/to/chroot32/bin/cat </dev/null 
[ Process PID=12345 runs in 32 bit mode. ]
uname(0xffffffffbfbf4a5a)               = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fda000
fstat64(3, 0xffffffffbfbf46a0)          = 0
mmap2(NULL, 22219, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7fd4000
fstat64(3, 0xffffffffbfbf4710)          = 0
mmap2(NULL, 1514108, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7e62000
mprotect(0xffffffffb7fcd000, 4096, PROT_NONE) = 0
mmap2(0xffffffffb7fce000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16b) = 0xb7fce000
mmap2(0xffffffffb7fd1000, 10876, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7fd1000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7e61000
set_thread_area(0xffffffffbfbf4be0)     = 0
mprotect(0xffffffffb7fce000, 8192, PROT_READ) = 0
mprotect(0x8053000, 4096, PROT_READ)    = 0
mprotect(0xffffffffb7ffb000, 4096, PROT_READ) = 0
munmap(0xffffffffb7fd4000, 22219)       = 0
fstat64(1, 0xffffffffbfbf4cd0)          = 0
fstat64(0, 0xffffffffbfbf4cd0)          = 0
+++ exited with 0 +++

So I think we shouldn't sign-extend syscall arguments by default.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20130215/c8a9c76e/attachment.bin>


More information about the Strace-devel mailing list