Closed GoogleCodeExporter closed 9 years ago
r167 | chappedm@gmail.com | 2012-11-03 10:52:42 -0400 (Sat, 03 Nov 2012) | 4
lines
issue-481: Replaced test mechanism for distinct address spaces with a more
reliable mechanism
Rather than using sys_ptrace+PTRACE_PEEK_DATA to determine whether address
spaces are distinct, we now use sys_waitpid+__WCLONE. See issue-481 for a more
detailed rationale.
Original comment by chapp...@gmail.com
on 3 Nov 2012 at 2:53
Original comment by chapp...@gmail.com
on 3 Nov 2012 at 2:53
I think this introduced the following race condition which I can reproduce
occasionally trying to use ListAllProcessThreads against a single-threaded
application:
- the directory scanner finds the main thread of a single-threaded program (ie
not a clone)
- it PTRACE_ATTACHes to this main thread, causing it to asynchronously stop.
- the new wait call here, with __WCLONE, will return immediately, because the
parent pid is not a clone. So, it returns immediately even though the process
is not yet stopped.
- we finish the iteration over threads, and since we only found the parent, we
go back and try to do the /proc/* based matching. In the retry step, we first
try to PTRACE_DETACH from the parent. But, if the async STOP hasn't been
delivered yet, this DETACH will fail.
- on the next loop through, our attempted call to PTRACE_ATTACH now fails
because we're already attached.
This ends up causing the attached parent to be orphaned, and the process ends
up SIGSTOPPED when the tracer process exits.
The fix is to do something like:
int waited_pid;
bool is_parent = (pid == ppid);
int flags = is_parent ? __WALL : __WCLONE;
while ((waited_pid = sys_waitpid(pid, &status, flags)) < 0) {
if (errno != EINTR) {
sys_ptrace_detach(pid);
num_threads--;
sig_num_threads = num_threads;
goto next_entry;
}
}
found_parent |= is_parent;
Original comment by tlip...@gmail.com
on 27 Nov 2013 at 10:04
Have you tried on master or 2.{0,1} ? In master this ticket's change was
reverted.
Original comment by alkondratenko
on 27 Nov 2013 at 10:05
Ah, I was looking at svn trunk - didn't catch that the project moved to git.
Thanks for noting that this was reverted.
Original comment by tlip...@gmail.com
on 3 Dec 2013 at 10:08
Original issue reported on code.google.com by
philip.a...@smoothwall.net
on 1 Nov 2012 at 11:15Attachments: