]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Check whether the big lock is held before invoking pre_thread_ll_create.
authorBart Van Assche <bvanassche@acm.org>
Sun, 25 Mar 2012 17:51:59 +0000 (17:51 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sun, 25 Mar 2012 17:51:59 +0000 (17:51 +0000)
If the pre_thread_ll_create tracking function would be invoked without the
big lock being held, that would trigger a race condition in the tools that
implement this tracking function.

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

coregrind/m_scheduler/scheduler.c
coregrind/m_syswrap/syswrap-amd64-linux.c
coregrind/m_syswrap/syswrap-arm-linux.c
coregrind/m_syswrap/syswrap-darwin.c
coregrind/m_syswrap/syswrap-ppc32-linux.c
coregrind/m_syswrap/syswrap-ppc64-linux.c
coregrind/m_syswrap/syswrap-s390x-linux.c
coregrind/m_syswrap/syswrap-x86-linux.c
coregrind/pub_core_scheduler.h

index 4548db0a0aa735dbe341b86efe93517d1a8cdbb7..be2ae5906659b585158ac0f7786dc6b00c7bb84d 100644 (file)
@@ -326,6 +326,12 @@ void VG_(release_BigLock_LL) ( HChar* who )
    ML_(release_sched_lock)(the_BigLock);
 }
 
+Bool VG_(owns_BigLock_LL) ( ThreadId tid )
+{
+   return (ML_(get_sched_lock_owner)(the_BigLock)
+           == VG_(threads)[tid].os_state.lwpid);
+}
+
 
 /* Clear out the ThreadState and release the semaphore. Leaves the
    ThreadState in VgTs_Zombie state, so that it doesn't get
index 6408185d09b4a006ad18d4c2d2c6a3e66678fc5f..39a69484dcf969c7590e8d2f2e62a797c96bd7a1 100644 (file)
@@ -289,6 +289,7 @@ static SysRes do_clone ( ThreadId ptid,
       know that this thread has come into existence.  If the clone
       fails, we'll send out a ll_exit notification for it at the out:
       label below, to clean up. */
+   vg_assert(VG_(owns_BigLock_LL)(ptid));
    VG_TRACK ( pre_thread_ll_create, ptid, ctid );
 
    if (flags & VKI_CLONE_SETTLS) {
index 4c1137fb6c4472c1495fe89c15cb9ccdf245df04..a416b1169e912ebf6b9fe003c39fdec7f5bf9c38 100644 (file)
@@ -228,6 +228,7 @@ static SysRes do_clone ( ThreadId ptid,
       ctst->client_stack_szB  = 0;
    }
 
+   vg_assert(VG_(owns_BigLock_LL)(ptid));
    VG_TRACK ( pre_thread_ll_create, ptid, ctid );
 
    if (flags & VKI_CLONE_SETTLS) {
index 96a83571eeb6f4d8039843ca238b77c30235aae1..a6db2398377eea04b32bd8b516ba4bd749c2173b 100644 (file)
@@ -6483,6 +6483,7 @@ POST(bsdthread_create)
    // should be in pthread_hijack instead, just before the call to
    // start_thread_NORETURN(), call_on_new_stack_0_1(), but we don't have the
    // parent tid value there...
+   vg_assert(VG_(owns_BigLock_LL)(ptid));
    VG_TRACK ( pre_thread_ll_create, tid, tst->tid );
 }
 
index efa272fb3ea350da02195acef316f2f6e3c0570e..715e685dd1fee806af0b572e656512b5b166101e 100644 (file)
@@ -335,6 +335,7 @@ static SysRes do_clone ( ThreadId ptid,
       know that this thread has come into existence.  If the clone
       fails, we'll send out a ll_exit notification for it at the out:
       label below, to clean up. */
+   vg_assert(VG_(owns_BigLock_LL)(ptid));
    VG_TRACK ( pre_thread_ll_create, ptid, ctid );
 
    if (flags & VKI_CLONE_SETTLS) {
index b55bee67283b0678c69234b9b72453519d2569dc..75137f2f01e2e3fcee4b84f28c9fc03d7aff2d21 100644 (file)
@@ -363,6 +363,7 @@ static SysRes do_clone ( ThreadId ptid,
       know that this thread has come into existence.  If the clone
       fails, we'll send out a ll_exit notification for it at the out:
       label below, to clean up. */
+   vg_assert(VG_(owns_BigLock_LL)(ptid));
    VG_TRACK ( pre_thread_ll_create, ptid, ctid );
 
    if (flags & VKI_CLONE_SETTLS) {
index ae8b1a4dbd0714e10b10388ad1b1f2585cd007b3..15f8f23803e21900977a63e7494edb65bd0f96c9 100644 (file)
@@ -287,6 +287,7 @@ static SysRes do_clone ( ThreadId ptid,
       know that this thread has come into existence.  If the clone
       fails, we'll send out a ll_exit notification for it at the out:
       label below, to clean up. */
+   vg_assert(VG_(owns_BigLock_LL)(ptid));
    VG_TRACK ( pre_thread_ll_create, ptid, ctid );
 
    if (flags & VKI_CLONE_SETTLS) {
index 2e642008661006e677b64e0fa2dc1d93bb1251b5..a79bc45124d9ea4038eea683beea4fdc3cf0063c 100644 (file)
@@ -303,6 +303,7 @@ static SysRes do_clone ( ThreadId ptid,
       if we don't state the new thread exists prior to that point.
       If the clone fails, we'll send out a ll_exit notification for it
       at the out: label below, to clean up. */
+   vg_assert(VG_(owns_BigLock_LL)(ptid));
    VG_TRACK ( pre_thread_ll_create, ptid, ctid );
 
    if (flags & VKI_CLONE_SETTLS) {
index 8d3d97c5ac84c556223278b8f15cdc7cd7952845..5e6042a324ba29276c9300e1d707d9bf3eaa7561 100644 (file)
@@ -78,6 +78,9 @@ extern void VG_(release_BigLock) ( ThreadId tid,
 /* Matching function to acquire_BigLock_LL. */
 extern void VG_(release_BigLock_LL) ( HChar* who );
 
+/* Whether the specified thread owns the big lock. */
+extern Bool VG_(owns_BigLock_LL) ( ThreadId tid );
+
 /* Yield the CPU for a while.  Drops/acquires the lock using the
    normal (non _LL) functions. */
 extern void VG_(vg_yield)(void);