]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
DRD: do not assert() upon fork(). Fixes the DRD part of #255355.
authorBart Van Assche <bvanassche@acm.org>
Thu, 3 Feb 2011 17:47:50 +0000 (17:47 +0000)
committerBart Van Assche <bvanassche@acm.org>
Thu, 3 Feb 2011 17:47:50 +0000 (17:47 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11520

drd/drd_main.c
drd/drd_thread.c
drd/drd_thread.h

index e317857ff34882952042c4b7b3922ab3d2c35e45..ebf08459ba437858be9737b4c84afe722b033e32 100644 (file)
@@ -627,6 +627,18 @@ static void drd_thread_finished(ThreadId vg_tid)
    DRD_(thread_finished)(drd_tid);
 }
 
+/*
+ * Called immediately after fork for the child process only. 'tid' is the
+ * only surviving thread in the child process. Cleans up thread state.
+ * See also http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_atfork.html for a detailed discussion of using fork() in combination with mutexes.
+ */
+static
+void drd__atfork_child(ThreadId tid)
+{
+   DRD_(drd_thread_atfork_child)(tid);
+}
+
+
 //
 // Implementation of the tool interface.
 //
@@ -756,6 +768,8 @@ void drd_pre_clo_init(void)
    VG_(track_pre_thread_ll_create) (drd_pre_thread_create);
    VG_(track_pre_thread_first_insn)(drd_post_thread_create);
    VG_(track_pre_thread_ll_exit)   (drd_thread_finished);
+   VG_(atfork)                     (NULL/*pre*/, NULL/*parent*/,
+                                   drd__atfork_child/*child*/);
 
    // Other stuff.
    DRD_(register_malloc_wrappers)(drd_start_using_mem_w_ecu,
index 909bb45a1989bf237261fecb015a694eb2bf9688..f85a5b0923e525b41769e71c132c14fb1d21eb8b 100644 (file)
@@ -504,6 +504,21 @@ void DRD_(thread_finished)(const DrdThreadId tid)
    }
 }
 
+/** Called just after fork() in the child process. */
+void DRD_(drd_thread_atfork_child)(const DrdThreadId tid)
+{
+   unsigned i;
+
+   for (i = 1; i < DRD_N_THREADS; i++)
+   {
+      if (i == tid)
+        continue;
+      if (DRD_(IsValidDrdThreadId(i)))
+        DRD_(thread_delete)(i);
+      tl_assert(!DRD_(IsValidDrdThreadId(i)));
+   }   
+}
+
 /** Called just before pthread_cancel(). */
 void DRD_(thread_pre_cancel)(const DrdThreadId tid)
 {
index cb4853b01dcf3aa90167b7f5100310809cd7a7d5..920df4a28cfa1bb3e6070a9939f58d072e42a9f6 100644 (file)
@@ -136,6 +136,7 @@ DrdThreadId DRD_(thread_post_create)(const ThreadId vg_created);
 void DRD_(thread_post_join)(DrdThreadId drd_joiner, DrdThreadId drd_joinee);
 void DRD_(thread_delete)(const DrdThreadId tid);
 void DRD_(thread_finished)(const DrdThreadId tid);
+void DRD_(drd_thread_atfork_child)(const DrdThreadId tid);
 void DRD_(thread_pre_cancel)(const DrdThreadId tid);
 void DRD_(thread_set_stack_startup)(const DrdThreadId tid,
                                     const Addr stack_startup);