]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
drd: Add support for calling pthread_create() from inside a shared library - bug...
authorBart Van Assche <bvanassche@acm.org>
Tue, 9 May 2017 04:45:30 +0000 (04:45 +0000)
committerBart Van Assche <bvanassche@acm.org>
Tue, 9 May 2017 04:45:30 +0000 (04:45 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16342

NEWS
drd/drd_pthread_intercepts.c
drd/drd_thread.c

diff --git a/NEWS b/NEWS
index b6db265044c5517c84b75d5a1b9de3d040451d7d..1b8a3328bb9284539b8c6cf7acc3e9dc74fbf649 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -172,6 +172,7 @@ where XXXXXX is the bug number as listed below.
 379390  unhandled syscall: mach:70 (host_create_mach_voucher_trap)
 379473  MIPS: add support for rdhwr cycle counter register
 379504  remove TileGX/Linux port
+356374  Assertion 'DRD_(g_threadinfo)[tid].pt_threadid != INVALID_POSIX_THREADID' failed
 
 Release 3.12.0 (20 October 2016)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
index e5078eec5d06f2f15783a86416b98f6f0eeb6837..d6abd43681f29642500431caa050ea204a6953ef 100644 (file)
@@ -556,6 +556,14 @@ int pthread_create_intercept(pthread_t* thread, const pthread_attr_t* attr,
    assert(thread_args.detachstate == PTHREAD_CREATE_JOINABLE
           || thread_args.detachstate == PTHREAD_CREATE_DETACHED);
 
+   /*
+    * The DRD_(set_pthread_id)() from DRD_(init)() may encounter that
+    * pthread_self() == 0, e.g. when the main program is not linked with the
+    * pthread library and when a pthread_create() call occurs from within a
+    * shared library. Hence call DRD_(set_pthread_id)() again to ensure that
+    * DRD knows the identity of the current thread. See also B.Z. 356374.
+    */
+   DRD_(set_pthread_id)();
    DRD_(entering_pthread_create)();
    CALL_FN_W_WWWW(ret, fn, thread, attr, DRD_(thread_wrapper), &thread_args);
    DRD_(left_pthread_create)();
index 84e0401dfb48a4860c2af5316441d7c57bee3a3a..9ada77dfe3778618a25562d8462902976e268236 100644 (file)
@@ -602,8 +602,8 @@ void DRD_(thread_pre_cancel)(const DrdThreadId tid)
 /**
  * Store the POSIX thread ID for the specified thread.
  *
- * @note This function can be called two times for the same thread -- see also
- * the comment block preceding the pthread_create() wrapper in
+ * @note This function can be called multiple times for the same thread -- see
+ * also the comment block preceding the pthread_create() wrapper in
  * drd_pthread_intercepts.c.
  */
 void DRD_(thread_set_pthreadid)(const DrdThreadId tid, const PThreadId ptid)
@@ -613,6 +613,10 @@ void DRD_(thread_set_pthreadid)(const DrdThreadId tid, const PThreadId ptid)
    tl_assert(DRD_(g_threadinfo)[tid].pt_threadid == INVALID_POSIX_THREADID
              || DRD_(g_threadinfo)[tid].pt_threadid == ptid);
    tl_assert(ptid != INVALID_POSIX_THREADID);
+   if (DRD_(g_threadinfo)[tid].posix_thread_exists) {
+      tl_assert(DRD_(g_threadinfo)[tid].pt_threadid == ptid);
+      return;
+   }
    DRD_(g_threadinfo)[tid].posix_thread_exists = True;
    DRD_(g_threadinfo)[tid].pt_threadid         = ptid;