File tree 3 files changed +30
-0
lines changed 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -627,6 +627,18 @@ static void drd_thread_finished(ThreadId vg_tid)
627
627
DRD_ (thread_finished )(drd_tid );
628
628
}
629
629
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
+
630
642
//
631
643
// Implementation of the tool interface.
632
644
//
@@ -756,6 +768,8 @@ void drd_pre_clo_init(void)
756
768
VG_ (track_pre_thread_ll_create ) (drd_pre_thread_create );
757
769
VG_ (track_pre_thread_first_insn )(drd_post_thread_create );
758
770
VG_ (track_pre_thread_ll_exit ) (drd_thread_finished );
771
+ VG_ (atfork ) (NULL /*pre*/ , NULL /*parent*/ ,
772
+ drd__atfork_child /*child*/ );
759
773
760
774
// Other stuff.
761
775
DRD_ (register_malloc_wrappers )(drd_start_using_mem_w_ecu ,
Original file line number Diff line number Diff line change @@ -504,6 +504,21 @@ void DRD_(thread_finished)(const DrdThreadId tid)
504
504
}
505
505
}
506
506
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
+
507
522
/** Called just before pthread_cancel(). */
508
523
void DRD_ (thread_pre_cancel )(const DrdThreadId tid )
509
524
{
Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ DrdThreadId DRD_(thread_post_create)(const ThreadId vg_created);
136
136
void DRD_ (thread_post_join )(DrdThreadId drd_joiner , DrdThreadId drd_joinee );
137
137
void DRD_ (thread_delete )(const DrdThreadId tid );
138
138
void DRD_ (thread_finished )(const DrdThreadId tid );
139
+ void DRD_ (drd_thread_atfork_child )(const DrdThreadId tid );
139
140
void DRD_ (thread_pre_cancel )(const DrdThreadId tid );
140
141
void DRD_ (thread_set_stack_startup )(const DrdThreadId tid ,
141
142
const Addr stack_startup );
You can’t perform that action at this time.
0 commit comments