From: Rhys Kidd Date: Mon, 26 Jan 2015 03:27:01 +0000 (+0000) Subject: Partial fix for bz339745. Mac OS: Further progress worker queue thread support. Addit... X-Git-Tag: svn/VALGRIND_3_11_0~704 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=479f864dd72e2bfc513e8d20ab2b082bf93e5d89;p=thirdparty%2Fvalgrind.git Partial fix for bz339745. Mac OS: Further progress worker queue thread support. Additional magic constants have been checked against OS X 10.9 and 10.10 git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14888 --- diff --git a/NEWS b/NEWS index 84eddf67d0..4cf2556014 100644 --- a/NEWS +++ b/NEWS @@ -56,6 +56,7 @@ where XXXXXX is the bug number as listed below. 339442 Fix testsuite build failure on OS X 10.9 339688 Mac-specific ASM does not support .version directive (cpuid, tronical and pushfpopf tests) +339745 Valgrind crash when check Marmalade app (partial fix) 339755 Fix known deliberate memory leak in setenv() on Mac OS X 10.9 339780 Fix known uninitialised read in pthread_rwlock_init() on Mac OS X 10.9 339789 Fix none/tests/execve test on Mac OS X 10.9 diff --git a/coregrind/m_syswrap/syswrap-amd64-darwin.c b/coregrind/m_syswrap/syswrap-amd64-darwin.c index b1790bb476..b8b886500d 100644 --- a/coregrind/m_syswrap/syswrap-amd64-darwin.c +++ b/coregrind/m_syswrap/syswrap-amd64-darwin.c @@ -465,10 +465,7 @@ void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr workitem, out just the relevant parts. Hence: */ # if DARWIN_VERS <= DARWIN_10_7 Bool is_reuse = reuse != 0; -# elif DARWIN_VERS == DARWIN_10_8 || DARWIN_VERS == DARWIN_10_9 - Bool is_reuse = (reuse & 0x20000 /* == WQ_FLAG_THREAD_REUSE */) != 0; -# elif DARWIN_VERS == DARWIN_10_10 - // XXX FIXME is this correct? +# elif DARWIN_VERS == DARWIN_10_8 || DARWIN_VERS == DARWIN_10_9 || DARWIN_VERS == DARWIN_10_10 Bool is_reuse = (reuse & 0x20000 /* == WQ_FLAG_THREAD_REUSE */) != 0; # else # error "Unsupported Darwin version" diff --git a/coregrind/m_syswrap/syswrap-x86-darwin.c b/coregrind/m_syswrap/syswrap-x86-darwin.c index b4a6f63b71..64d5358ac7 100644 --- a/coregrind/m_syswrap/syswrap-x86-darwin.c +++ b/coregrind/m_syswrap/syswrap-x86-darwin.c @@ -397,20 +397,42 @@ void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr workitem, lock. */ VG_(acquire_BigLock_LL)("wqthread_hijack"); + if (0) VG_(printf)( + "wqthread_hijack: self %#lx, kport %#lx, " + "stackaddr %#lx, workitem %#lx, reuse/flags %x, sp %#lx\n", + self, kport, stackaddr, workitem, reuse, sp); + /* Start the thread with all signals blocked. VG_(scheduler) will set the mask correctly when we finally get there. */ VG_(sigfillset)(&blockall); VG_(sigprocmask)(VKI_SIG_SETMASK, &blockall, NULL); - if (reuse) { + /* For 10.7 and earlier, |reuse| appeared to be used as a simple + boolean. In 10.8 and later its name changed to |flags| and has + various other bits OR-d into it too, so it's necessary to fish + out just the relevant parts. Hence: */ +# if DARWIN_VERS <= DARWIN_10_7 + Bool is_reuse = reuse != 0; +# elif DARWIN_VERS == DARWIN_10_8 || DARWIN_VERS == DARWIN_10_9 || DARWIN_VERS == DARWIN_10_10 + Bool is_reuse = (reuse & 0x20000 /* == WQ_FLAG_THREAD_REUSE */) != 0; +# else +# error "Unsupported Darwin version" +# endif + + if (is_reuse) { /* For whatever reason, tst->os_state.pthread appear to have a constant offset of 72 on 10.7, but zero on 10.6 and 10.5. No idea why. */ # if DARWIN_VERS <= DARWIN_10_6 UWord magic_delta = 0; -# elif DARWIN_VERS >= DARWIN_10_7 +# elif DARWIN_VERS == DARWIN_10_7 || DARWIN_VERS == DARWIN_10_8 UWord magic_delta = 0x48; +# elif DARWIN_VERS == DARWIN_10_9 || DARWIN_VERS == DARWIN_10_10 + UWord magic_delta = 0xB0; +# else +# error "magic_delta: to be computed on new OS version" + // magic_delta = tst->os_state.pthread - self # endif // This thread already exists; we're merely re-entering @@ -454,7 +476,7 @@ void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr workitem, stacksize = 512*1024; // wq stacks are always DEFAULT_STACK_SIZE stack = VG_PGROUNDUP(sp) - stacksize; - if (reuse) { + if (is_reuse) { // Continue V's thread back in the scheduler. // The client thread is of course in another location entirely.