Check whether the big lock is held before invoking pre_thread_ll_create.

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
This commit is contained in:
Bart Van Assche 2012-03-25 17:51:59 +00:00
parent 57ec7947c7
commit 563f0acd21
9 changed files with 16 additions and 0 deletions

View 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

View 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) {

View 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) {

View 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 );
}

View 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) {

View 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) {

View 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) {

View 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) {

View 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);