From: Julian Seward Date: Fri, 17 Oct 2014 16:03:20 +0000 (+0000) Subject: _thread_suspend: hold on to the lock when suspending some other X-Git-Tag: svn/VALGRIND_3_11_0~912 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70cf4709e7aff89c116ff71ddbfba554b079007d;p=thirdparty%2Fvalgrind.git _thread_suspend: hold on to the lock when suspending some other thread, so as to not deadlock the process. _thread_resume: add wrapper git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14636 --- diff --git a/coregrind/m_syswrap/priv_syswrap-darwin.h b/coregrind/m_syswrap/priv_syswrap-darwin.h index 780966545d..1f0b49f71a 100644 --- a/coregrind/m_syswrap/priv_syswrap-darwin.h +++ b/coregrind/m_syswrap/priv_syswrap-darwin.h @@ -565,6 +565,7 @@ DECL_TEMPLATE(darwin, thread_terminate); 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); diff --git a/coregrind/m_syswrap/syswrap-darwin.c b/coregrind/m_syswrap/syswrap-darwin.c index e04e39acf0..6c6cc43d45 100644 --- a/coregrind/m_syswrap/syswrap-darwin.c +++ b/coregrind/m_syswrap/syswrap-darwin.c @@ -6882,6 +6882,33 @@ PRE(thread_suspend) // 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 @@ PRE(mach_msg_thread) case 3605: CALL_PRE(thread_suspend); return; + case 3606: + CALL_PRE(thread_resume); + return; case 3612: CALL_PRE(thread_info); return;