|
From: <sv...@va...> - 2014-10-17 16:03:27
|
Author: sewardj
Date: Fri Oct 17 17:03:20 2014
New Revision: 14636
Log:
_thread_suspend: hold on to the lock when suspending some other
thread, so as to not deadlock the process.
_thread_resume: add wrapper
Modified:
trunk/coregrind/m_syswrap/priv_syswrap-darwin.h
trunk/coregrind/m_syswrap/syswrap-darwin.c
Modified: trunk/coregrind/m_syswrap/priv_syswrap-darwin.h
==============================================================================
--- trunk/coregrind/m_syswrap/priv_syswrap-darwin.h (original)
+++ trunk/coregrind/m_syswrap/priv_syswrap-darwin.h Fri Oct 17 17:03:20 2014
@@ -565,6 +565,7 @@
DECL_TEMPLATE(darwin, thread_create);
DECL_TEMPLATE(darwin, thread_create_running);
DECL_TEMPLATE(darwin, thread_suspend);
+DECL_TEMPLATE(darwin, thread_resume);
DECL_TEMPLATE(darwin, thread_get_state);
DECL_TEMPLATE(darwin, thread_policy);
DECL_TEMPLATE(darwin, thread_policy_set);
Modified: trunk/coregrind/m_syswrap/syswrap-darwin.c
==============================================================================
--- trunk/coregrind/m_syswrap/syswrap-darwin.c (original)
+++ trunk/coregrind/m_syswrap/syswrap-darwin.c Fri Oct 17 17:03:20 2014
@@ -6882,6 +6882,33 @@
// Do keep the scheduler lock while suspending any other thread.
// Otherwise we might halt the other thread while it holds the lock,
// which would deadlock the process.
+ *flags &= ~SfMayBlock;
+ }
+}
+
+
+POST(thread_resume)
+{
+}
+
+PRE(thread_resume)
+{
+ mach_msg_header_t *mh = (mach_msg_header_t *)ARG1;
+ Bool self_resume = (mh->msgh_request_port == MACH_THREAD);
+
+ PRINT("thread_resume(%s)", name_for_port(mh->msgh_request_port));
+
+ AFTER = POST_FN(thread_resume);
+
+ if (self_resume) {
+ // This doesn't make much sense. If we are resuming ourself, we can't
+ // already be running. So I don't see how we can ever get here.
+ vg_assert(0);
+ } else {
+ // Resuming some other thread. It might not yet come back to life
+ // (if the suspend count is still above zero) so make sure we keep
+ // holding the lock.
+ *flags &= ~SfMayBlock;
}
}
@@ -7375,6 +7402,9 @@
case 3605:
CALL_PRE(thread_suspend);
return;
+ case 3606:
+ CALL_PRE(thread_resume);
+ return;
case 3612:
CALL_PRE(thread_info);
return;
|