From: Eugene Syromyatnikov Date: Wed, 3 Jan 2018 16:36:25 +0000 (+0100) Subject: Call get_scno during startup_tcb only for forcibly attached processes X-Git-Tag: v4.21~229 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=576e2db4d0175334fccaf38e04bfc8537344015d;p=strace Call get_scno during startup_tcb only for forcibly attached processes Otherwise it makes little sense on most arches to try to get syscall number. * defs.h (TCB_GRABBED): New tcb flag. * strace.c (attach_tcb): Set TCB_GRABBED for the tcb. (startup_tcb): Call get_scno() only if process is grabbed and its registers may contain syscall number information. Reported-by: Dmitry V. Levin Closes: https://github.com/strace/strace/issues/22 --- diff --git a/defs.h b/defs.h index afb2cb0b..35761290 100644 --- a/defs.h +++ b/defs.h @@ -244,6 +244,8 @@ struct tcb { #define TCB_TAMPERED 0x40 /* A syscall has been tampered with */ #define TCB_HIDE_LOG 0x80 /* We should hide everything (until execve) */ #define TCB_SKIP_DETACH_ON_FIRST_EXEC 0x100 /* -b execve should skip detach on first execve */ +#define TCB_GRABBED 0x200 /* We grab the process and can catch it + * in the middle of a syscall */ /* qualifier flags */ #define QUAL_TRACE 0x001 /* this system call should be traced */ diff --git a/strace.c b/strace.c index 70906248..7491a2e9 100644 --- a/strace.c +++ b/strace.c @@ -1002,7 +1002,8 @@ attach_tcb(struct tcb *const tcp) return; } - tcp->flags |= TCB_ATTACHED | TCB_STARTUP | post_attach_sigstop; + tcp->flags |= TCB_ATTACHED | TCB_GRABBED | TCB_STARTUP | + post_attach_sigstop; newoutf(tcp); debug_msg("attach to pid %d (main) succeeded", tcp->pid); @@ -1033,8 +1034,8 @@ attach_tcb(struct tcb *const tcp) debug_msg("attach to pid %d succeeded", tid); struct tcb *tid_tcp = alloctcb(tid); - tid_tcp->flags |= TCB_ATTACHED | TCB_STARTUP | - post_attach_sigstop; + tid_tcp->flags |= TCB_ATTACHED | TCB_GRABBED | + TCB_STARTUP | post_attach_sigstop; newoutf(tid_tcp); } @@ -2149,7 +2150,7 @@ startup_tcb(struct tcb *tcp) } } - if (get_scno(tcp) == 1) + if ((tcp->flags & TCB_GRABBED) && (get_scno(tcp) == 1)) tcp->s_prev_ent = tcp->s_ent; }