|
From: <sv...@va...> - 2012-03-25 17:52:06
|
bart 2012-03-25 18:51:59 +0100 (Sun, 25 Mar 2012)
New Revision: 12458
Log:
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.
Modified files:
trunk/coregrind/m_scheduler/scheduler.c
trunk/coregrind/m_syswrap/syswrap-amd64-linux.c
trunk/coregrind/m_syswrap/syswrap-arm-linux.c
trunk/coregrind/m_syswrap/syswrap-darwin.c
trunk/coregrind/m_syswrap/syswrap-ppc32-linux.c
trunk/coregrind/m_syswrap/syswrap-ppc64-linux.c
trunk/coregrind/m_syswrap/syswrap-s390x-linux.c
trunk/coregrind/m_syswrap/syswrap-x86-linux.c
trunk/coregrind/pub_core_scheduler.h
Modified: trunk/coregrind/m_syswrap/syswrap-ppc64-linux.c (+1 -0)
===================================================================
--- trunk/coregrind/m_syswrap/syswrap-ppc64-linux.c 2012-03-25 15:55:17 +01:00 (rev 12457)
+++ trunk/coregrind/m_syswrap/syswrap-ppc64-linux.c 2012-03-25 18:51:59 +01:00 (rev 12458)
@@ -363,6 +363,7 @@
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) {
Modified: trunk/coregrind/m_syswrap/syswrap-arm-linux.c (+1 -0)
===================================================================
--- trunk/coregrind/m_syswrap/syswrap-arm-linux.c 2012-03-25 15:55:17 +01:00 (rev 12457)
+++ trunk/coregrind/m_syswrap/syswrap-arm-linux.c 2012-03-25 18:51:59 +01:00 (rev 12458)
@@ -228,6 +228,7 @@
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) {
Modified: trunk/coregrind/m_syswrap/syswrap-x86-linux.c (+1 -0)
===================================================================
--- trunk/coregrind/m_syswrap/syswrap-x86-linux.c 2012-03-25 15:55:17 +01:00 (rev 12457)
+++ trunk/coregrind/m_syswrap/syswrap-x86-linux.c 2012-03-25 18:51:59 +01:00 (rev 12458)
@@ -303,6 +303,7 @@
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) {
Modified: trunk/coregrind/m_syswrap/syswrap-amd64-linux.c (+1 -0)
===================================================================
--- trunk/coregrind/m_syswrap/syswrap-amd64-linux.c 2012-03-25 15:55:17 +01:00 (rev 12457)
+++ trunk/coregrind/m_syswrap/syswrap-amd64-linux.c 2012-03-25 18:51:59 +01:00 (rev 12458)
@@ -289,6 +289,7 @@
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) {
Modified: trunk/coregrind/pub_core_scheduler.h (+3 -0)
===================================================================
--- trunk/coregrind/pub_core_scheduler.h 2012-03-25 15:55:17 +01:00 (rev 12457)
+++ trunk/coregrind/pub_core_scheduler.h 2012-03-25 18:51:59 +01:00 (rev 12458)
@@ -78,6 +78,9 @@
/* 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);
Modified: trunk/coregrind/m_syswrap/syswrap-s390x-linux.c (+1 -0)
===================================================================
--- trunk/coregrind/m_syswrap/syswrap-s390x-linux.c 2012-03-25 15:55:17 +01:00 (rev 12457)
+++ trunk/coregrind/m_syswrap/syswrap-s390x-linux.c 2012-03-25 18:51:59 +01:00 (rev 12458)
@@ -287,6 +287,7 @@
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) {
Modified: trunk/coregrind/m_scheduler/scheduler.c (+6 -0)
===================================================================
--- trunk/coregrind/m_scheduler/scheduler.c 2012-03-25 15:55:17 +01:00 (rev 12457)
+++ trunk/coregrind/m_scheduler/scheduler.c 2012-03-25 18:51:59 +01:00 (rev 12458)
@@ -326,7 +326,13 @@
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
reallocated until the caller is really ready. */
Modified: trunk/coregrind/m_syswrap/syswrap-ppc32-linux.c (+1 -0)
===================================================================
--- trunk/coregrind/m_syswrap/syswrap-ppc32-linux.c 2012-03-25 15:55:17 +01:00 (rev 12457)
+++ trunk/coregrind/m_syswrap/syswrap-ppc32-linux.c 2012-03-25 18:51:59 +01:00 (rev 12458)
@@ -335,6 +335,7 @@
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) {
Modified: trunk/coregrind/m_syswrap/syswrap-darwin.c (+1 -0)
===================================================================
--- trunk/coregrind/m_syswrap/syswrap-darwin.c 2012-03-25 15:55:17 +01:00 (rev 12457)
+++ trunk/coregrind/m_syswrap/syswrap-darwin.c 2012-03-25 18:51:59 +01:00 (rev 12458)
@@ -6483,6 +6483,7 @@
// 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 );
}
|
|
From: Julian S. <js...@ac...> - 2012-03-26 16:29:57
|
This breaks the build on darwin, alas, since ptid isn't in scope in that function. I don't see an obvious way to fix it since (as the comment says) the parent tid isn't available, and this is a syscall wrapper, so we can't pass it in as an extra parameter. J On Sunday, March 25, 2012, sv...@va... wrote: > bart 2012-03-25 18:51:59 +0100 (Sun, 25 Mar 2012) > > New Revision: 12458 > > Log: > 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. > > Modified: trunk/coregrind/m_syswrap/syswrap-darwin.c (+1 -0) > =================================================================== > --- trunk/coregrind/m_syswrap/syswrap-darwin.c 2012-03-25 15:55:17 +01:00 > (rev 12457) +++ trunk/coregrind/m_syswrap/syswrap-darwin.c 2012-03-25 > 18:51:59 +01:00 (rev 12458) @@ -6483,6 +6483,7 @@ > // 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 ); > } |