Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5c7e6b6

Browse files
author
bart
committedFeb 3, 2011
DRD: do not assert() upon fork(). Fixes the DRD part of #255355.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11520 a5019735-40e9-0310-863c-91ae7b9d1cf9
1 parent 0f059a3 commit 5c7e6b6

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
 

‎drd/drd_main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,18 @@ static void drd_thread_finished(ThreadId vg_tid)
627627
DRD_(thread_finished)(drd_tid);
628628
}
629629

630+
/*
631+
* Called immediately after fork for the child process only. 'tid' is the
632+
* only surviving thread in the child process. Cleans up thread state.
633+
* See also http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_atfork.html for a detailed discussion of using fork() in combination with mutexes.
634+
*/
635+
static
636+
void drd__atfork_child(ThreadId tid)
637+
{
638+
DRD_(drd_thread_atfork_child)(tid);
639+
}
640+
641+
630642
//
631643
// Implementation of the tool interface.
632644
//
@@ -756,6 +768,8 @@ void drd_pre_clo_init(void)
756768
VG_(track_pre_thread_ll_create) (drd_pre_thread_create);
757769
VG_(track_pre_thread_first_insn)(drd_post_thread_create);
758770
VG_(track_pre_thread_ll_exit) (drd_thread_finished);
771+
VG_(atfork) (NULL/*pre*/, NULL/*parent*/,
772+
drd__atfork_child/*child*/);
759773

760774
// Other stuff.
761775
DRD_(register_malloc_wrappers)(drd_start_using_mem_w_ecu,

‎drd/drd_thread.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,21 @@ void DRD_(thread_finished)(const DrdThreadId tid)
504504
}
505505
}
506506

507+
/** Called just after fork() in the child process. */
508+
void DRD_(drd_thread_atfork_child)(const DrdThreadId tid)
509+
{
510+
unsigned i;
511+
512+
for (i = 1; i < DRD_N_THREADS; i++)
513+
{
514+
if (i == tid)
515+
continue;
516+
if (DRD_(IsValidDrdThreadId(i)))
517+
DRD_(thread_delete)(i);
518+
tl_assert(!DRD_(IsValidDrdThreadId(i)));
519+
}
520+
}
521+
507522
/** Called just before pthread_cancel(). */
508523
void DRD_(thread_pre_cancel)(const DrdThreadId tid)
509524
{

‎drd/drd_thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ DrdThreadId DRD_(thread_post_create)(const ThreadId vg_created);
136136
void DRD_(thread_post_join)(DrdThreadId drd_joiner, DrdThreadId drd_joinee);
137137
void DRD_(thread_delete)(const DrdThreadId tid);
138138
void DRD_(thread_finished)(const DrdThreadId tid);
139+
void DRD_(drd_thread_atfork_child)(const DrdThreadId tid);
139140
void DRD_(thread_pre_cancel)(const DrdThreadId tid);
140141
void DRD_(thread_set_stack_startup)(const DrdThreadId tid,
141142
const Addr stack_startup);

0 commit comments

Comments
 (0)
Please sign in to comment.