[PATCH] Use PTRACE_GETREGS on i386

Dmitry V. Levin ldv at altlinux.org
Thu Aug 25 17:10:37 UTC 2011


On Thu, Aug 25, 2011 at 12:10:06PM +0200, Denys Vlasenko wrote:
> While discussing ptrace speedup, in one email Linus said
> that it's stupid that strace doesn't even use already existing
> speedups, such as PTRACE_GETREGS.

Yes, use of PTRACE_GETREGS is a long awaited change.
I expect a significant reduction of ptrace() syscall invocations.

> I guess we need to add a check on startup to make sure PTRACE_GETREGS works?

PTRACE_GETREGS is quite ancient thing, it is supported even by linux-2.2.26,
so I see no need in the runtime check this time.

> --- strace.5/syscall.c	2011-08-25 10:39:36.000000000 +0200
> +++ strace.6/syscall.c	2011-08-25 11:51:32.148543603 +0200
> @@ -716,7 +716,28 @@ struct tcb *tcp_last = NULL;
>  
>  #ifdef LINUX
>  # if defined (I386)
> -static long eax;
> +struct i386_user_regs_struct {
> +	long ebx;
> +	long ecx;
> +	long edx;
> +	long esi;
> +	long edi;
> +	long ebp;
> +	long eax;
> +	long xds;
> +	long xes;
> +	long xfs;
> +	long xgs;
> +	long orig_eax;
> +	long eip;
> +	long xcs;
> +	long eflags;
> +	long esp;
> +	long xss;
> +	/* Just in case we forgot a few fields and kernel would write more... */
> +	long paranoia[8];
> +};
> +static struct i386_user_regs_struct i386_regs;

I suppose we shouldn't hurry with this.  There is a <asm/ptrace.h> where
all this stuff is defined and supported for all linux architectures.
So I think migrating from <sys/ptrace.h> to <linux/ptrace.h> is the right
way to go.

> @@ -1291,21 +1313,17 @@ syscall_fixup_on_sysenter(struct tcb *tc
>  #ifdef LINUX
>  	/* A common case of "not a syscall entry" is post-execve SIGTRAP */
>  #if defined (I386)
> +	if (i386_regs.eax != -ENOSYS) {
> +		if (debug)
> +			fprintf(stderr, "not a syscall entry (eax = %ld)\n", i386_regs.eax);
> +		return 0;
> +	}

Looks like the check for !(ptrace_setoptions & PTRACE_O_TRACEEXEC) was
removed here.

> +#elif defined (X86_64)
>  	/* With PTRACE_O_TRACEEXEC, post-execve SIGTRAP is disabled.
> -	 * Every extra ptrace call is expensive, so check EAX
> +	 * Every extra ptrace call is expensive, so check RAX
>  	 * on syscall entry only if PTRACE_O_TRACEEXEC is not enabled:
>  	 */
>  	if (!(ptrace_setoptions & PTRACE_O_TRACEEXEC)) {
> -		if (upeek(tcp, 4*EAX, &eax) < 0)
> -			return -1;
> -		if (eax != -ENOSYS) {
> -			if (debug)
> -				fprintf(stderr, "not a syscall entry (eax = %ld)\n", eax);
> -			return 0;
> -		}
> -	}
> -#elif defined (X86_64)
> -	if (!(ptrace_setoptions & PTRACE_O_TRACEEXEC)) {
>  		if (upeek(tcp, 8*RAX, &rax) < 0)
>  			return -1;
>  		if (current_personality == 1)


-- 
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/20110825/926bb4bc/attachment.bin>


More information about the Strace-devel mailing list