]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Implement __pthread_kill_other_threads_np properly. It does seem to
authorJulian Seward <jseward@acm.org>
Thu, 30 May 2002 00:40:03 +0000 (00:40 +0000)
committerJulian Seward <jseward@acm.org>
Thu, 30 May 2002 00:40:03 +0000 (00:40 +0000)
be needed after all.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@342

coregrind/arch/x86-linux/vg_libpthread.c
coregrind/vg_include.h
coregrind/vg_libpthread.c
coregrind/vg_scheduler.c
vg_include.h
vg_libpthread.c
vg_scheduler.c

index c92d54c8f5dc89689b80bb64b12d853b18efea67..6f51b04aae7c99ab38c88d283ce14c601e909ddf 100644 (file)
@@ -897,28 +897,19 @@ void pthread_testcancel ( void )
 }
 
 
-/*-------------------*/
-/* If this is indeed used by LinuxThreads to implement thread nuking
-   post fork and pre exec, we should really nuke em, not do
-   pthread_cancel. */
-static pthread_mutex_t massacre_mx = PTHREAD_MUTEX_INITIALIZER;
-
+/* Not really sure what this is for.  I suspect for doing the POSIX
+   requirements for fork() and exec().  We do this internally anyway
+   whenever those syscalls are observed, so this could be superfluous,
+   but hey ... 
+*/
 void __pthread_kill_other_threads_np ( void )
 {
-   /* If we need this, implement it properly! */
-   vgPlain_unimp("__pthread_kill_other_threads_np");
-#if 0
-   int i, res, me;
-   __pthread_mutex_lock(&massacre_mx);
-   me = pthread_self();
-   for (i = 1; i < VG_N_THREADS; i++) {
-      if (i == me) continue;
-      res = pthread_cancel(i);
-      if (0 && res == 0)
-         printf("----------- NUKED %d\n", i);
-   }
-   __pthread_mutex_unlock(&massacre_mx);
-#endif
+   int res;
+   ensure_valgrind("__pthread_kill_other_threads_np");
+   VALGRIND_MAGIC_SEQUENCE(res, (-1) /* default */,
+                           VG_USERREQ__NUKE_OTHER_THREADS,
+                           0, 0, 0, 0);
+   assert(res == 0);
 }
 
 
index 840282b2002c7a16a2694f6a0e8a8915ecf062db..f5e665823b928457cad2dc76262150bafc5863f7 100644 (file)
@@ -478,6 +478,8 @@ extern Bool  VG_(is_empty_arena) ( ArenaId aid );
 #define VG_USERREQ__CLEANUP_POP             0x3021
 #define VG_USERREQ__GET_KEY_D_AND_S         0x3022
 
+#define VG_USERREQ__NUKE_OTHER_THREADS      0x3023
+
 /* Cosmetic ... */
 #define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101
 
index c92d54c8f5dc89689b80bb64b12d853b18efea67..6f51b04aae7c99ab38c88d283ce14c601e909ddf 100644 (file)
@@ -897,28 +897,19 @@ void pthread_testcancel ( void )
 }
 
 
-/*-------------------*/
-/* If this is indeed used by LinuxThreads to implement thread nuking
-   post fork and pre exec, we should really nuke em, not do
-   pthread_cancel. */
-static pthread_mutex_t massacre_mx = PTHREAD_MUTEX_INITIALIZER;
-
+/* Not really sure what this is for.  I suspect for doing the POSIX
+   requirements for fork() and exec().  We do this internally anyway
+   whenever those syscalls are observed, so this could be superfluous,
+   but hey ... 
+*/
 void __pthread_kill_other_threads_np ( void )
 {
-   /* If we need this, implement it properly! */
-   vgPlain_unimp("__pthread_kill_other_threads_np");
-#if 0
-   int i, res, me;
-   __pthread_mutex_lock(&massacre_mx);
-   me = pthread_self();
-   for (i = 1; i < VG_N_THREADS; i++) {
-      if (i == me) continue;
-      res = pthread_cancel(i);
-      if (0 && res == 0)
-         printf("----------- NUKED %d\n", i);
-   }
-   __pthread_mutex_unlock(&massacre_mx);
-#endif
+   int res;
+   ensure_valgrind("__pthread_kill_other_threads_np");
+   VALGRIND_MAGIC_SEQUENCE(res, (-1) /* default */,
+                           VG_USERREQ__NUKE_OTHER_THREADS,
+                           0, 0, 0, 0);
+   assert(res == 0);
 }
 
 
index 9db5021e693b6ccbf102003aa10100541c8b730c..228a8a3d75f1e3195ac7b7bd5feb3776e399a3ea 100644 (file)
@@ -1706,8 +1706,9 @@ void VG_(nuke_all_threads_except) ( ThreadId me )
       if (tid == me
           || VG_(threads)[tid].status == VgTs_Empty) 
          continue;
-      VG_(printf)(
-         "VG_(nuke_all_threads_except): nuking tid %d\n", tid);
+      if (0)
+         VG_(printf)(
+            "VG_(nuke_all_threads_except): nuking tid %d\n", tid);
       VG_(threads)[tid].status = VgTs_Empty;
       cleanup_after_thread_exited( tid );
    }
@@ -3044,6 +3045,11 @@ void do_nontrivial_clientreq ( ThreadId tid )
                                       (CleanupEntry*)arg[2] );
          break;
 
+      case VG_USERREQ__NUKE_OTHER_THREADS:
+         VG_(nuke_all_threads_except) ( tid );
+         SET_EDX(tid, 0);
+         break;
+
       case VG_USERREQ__MAKE_NOACCESS:
       case VG_USERREQ__MAKE_WRITABLE:
       case VG_USERREQ__MAKE_READABLE:
index 840282b2002c7a16a2694f6a0e8a8915ecf062db..f5e665823b928457cad2dc76262150bafc5863f7 100644 (file)
@@ -478,6 +478,8 @@ extern Bool  VG_(is_empty_arena) ( ArenaId aid );
 #define VG_USERREQ__CLEANUP_POP             0x3021
 #define VG_USERREQ__GET_KEY_D_AND_S         0x3022
 
+#define VG_USERREQ__NUKE_OTHER_THREADS      0x3023
+
 /* Cosmetic ... */
 #define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101
 
index c92d54c8f5dc89689b80bb64b12d853b18efea67..6f51b04aae7c99ab38c88d283ce14c601e909ddf 100644 (file)
@@ -897,28 +897,19 @@ void pthread_testcancel ( void )
 }
 
 
-/*-------------------*/
-/* If this is indeed used by LinuxThreads to implement thread nuking
-   post fork and pre exec, we should really nuke em, not do
-   pthread_cancel. */
-static pthread_mutex_t massacre_mx = PTHREAD_MUTEX_INITIALIZER;
-
+/* Not really sure what this is for.  I suspect for doing the POSIX
+   requirements for fork() and exec().  We do this internally anyway
+   whenever those syscalls are observed, so this could be superfluous,
+   but hey ... 
+*/
 void __pthread_kill_other_threads_np ( void )
 {
-   /* If we need this, implement it properly! */
-   vgPlain_unimp("__pthread_kill_other_threads_np");
-#if 0
-   int i, res, me;
-   __pthread_mutex_lock(&massacre_mx);
-   me = pthread_self();
-   for (i = 1; i < VG_N_THREADS; i++) {
-      if (i == me) continue;
-      res = pthread_cancel(i);
-      if (0 && res == 0)
-         printf("----------- NUKED %d\n", i);
-   }
-   __pthread_mutex_unlock(&massacre_mx);
-#endif
+   int res;
+   ensure_valgrind("__pthread_kill_other_threads_np");
+   VALGRIND_MAGIC_SEQUENCE(res, (-1) /* default */,
+                           VG_USERREQ__NUKE_OTHER_THREADS,
+                           0, 0, 0, 0);
+   assert(res == 0);
 }
 
 
index 9db5021e693b6ccbf102003aa10100541c8b730c..228a8a3d75f1e3195ac7b7bd5feb3776e399a3ea 100644 (file)
@@ -1706,8 +1706,9 @@ void VG_(nuke_all_threads_except) ( ThreadId me )
       if (tid == me
           || VG_(threads)[tid].status == VgTs_Empty) 
          continue;
-      VG_(printf)(
-         "VG_(nuke_all_threads_except): nuking tid %d\n", tid);
+      if (0)
+         VG_(printf)(
+            "VG_(nuke_all_threads_except): nuking tid %d\n", tid);
       VG_(threads)[tid].status = VgTs_Empty;
       cleanup_after_thread_exited( tid );
    }
@@ -3044,6 +3045,11 @@ void do_nontrivial_clientreq ( ThreadId tid )
                                       (CleanupEntry*)arg[2] );
          break;
 
+      case VG_USERREQ__NUKE_OTHER_THREADS:
+         VG_(nuke_all_threads_except) ( tid );
+         SET_EDX(tid, 0);
+         break;
+
       case VG_USERREQ__MAKE_NOACCESS:
       case VG_USERREQ__MAKE_WRITABLE:
       case VG_USERREQ__MAKE_READABLE: