From: Bart Van Assche Date: Tue, 9 May 2017 04:45:30 +0000 (+0000) Subject: drd: Add support for calling pthread_create() from inside a shared library - bug... X-Git-Tag: svn/VALGRIND_3_13_0~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3bc6c7dc79ae2fb0878234ad6128d92f7f2bb2f;p=thirdparty%2Fvalgrind.git drd: Add support for calling pthread_create() from inside a shared library - bug #356374 git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16342 --- diff --git a/NEWS b/NEWS index b6db265044..1b8a3328bb 100644 --- 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) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c index e5078eec5d..d6abd43681 100644 --- a/drd/drd_pthread_intercepts.c +++ b/drd/drd_pthread_intercepts.c @@ -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)(); diff --git a/drd/drd_thread.c b/drd/drd_thread.c index 84e0401dfb..9ada77dfe3 100644 --- a/drd/drd_thread.c +++ b/drd/drd_thread.c @@ -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;