From 9e83bd224f473d44b80c10afe3e5d59724f51985 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Sat, 13 Sep 2025 22:08:03 +0200 Subject: [PATCH] Bug 380269 - [PATCH] No multithreading in macOS Sierra (10.12) The patches were mostly applied, and now everything is. --- coregrind/m_syswrap/syswrap-amd64-darwin.c | 8 +++++--- coregrind/m_syswrap/syswrap-darwin.c | 16 +++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/coregrind/m_syswrap/syswrap-amd64-darwin.c b/coregrind/m_syswrap/syswrap-amd64-darwin.c index 6227352ee..b2eb17f77 100644 --- a/coregrind/m_syswrap/syswrap-amd64-darwin.c +++ b/coregrind/m_syswrap/syswrap-amd64-darwin.c @@ -476,15 +476,14 @@ void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr workitem, /* For whatever reason, tst->os_state.pthread appear to have a constant offset of 96 on 10.7, but zero on 10.6 and 10.5. No idea why. */ -# if DARWIN_VERS <= DARWIN_10_6 +# if DARWIN_VERS <= DARWIN_10_6 || DARWIN_VERS == DARWIN_10_13 UWord magic_delta = 0; # elif DARWIN_VERS == DARWIN_10_7 || DARWIN_VERS == DARWIN_10_8 UWord magic_delta = 0x60; # elif DARWIN_VERS == DARWIN_10_9 \ || DARWIN_VERS == DARWIN_10_10 \ || DARWIN_VERS == DARWIN_10_11 \ - || DARWIN_VERS == DARWIN_10_12 \ - || DARWIN_VERS == DARWIN_10_13 + || DARWIN_VERS == DARWIN_10_12 UWord magic_delta = 0xE0; # else # error "magic_delta: to be computed on new OS version" @@ -528,6 +527,9 @@ void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr workitem, vex->guest_R8 = reuse; vex->guest_R9 = 0; vex->guest_RSP = sp; +#if DARWIN_VERS >= DARWIN_10_12 + vex->guest_GS_CONST = self + pthread_tsd_offset; +#endif stacksize = 512*1024; // wq stacks are always DEFAULT_STACK_SIZE stack = VG_PGROUNDUP(sp) - stacksize; diff --git a/coregrind/m_syswrap/syswrap-darwin.c b/coregrind/m_syswrap/syswrap-darwin.c index d6df8b996..2e1ba1da8 100644 --- a/coregrind/m_syswrap/syswrap-darwin.c +++ b/coregrind/m_syswrap/syswrap-darwin.c @@ -2085,18 +2085,18 @@ PRE(bsdthread_register) pthread_starter = ARG1; wqthread_starter = ARG2; pthread_structsize = ARG3; - #if DARWIN_VERS >= DARWIN_10_12 - typedef struct { +#if DARWIN_VERS >= DARWIN_10_12 + typedef struct { uint64_t version; uint64_t dispatch_queue_offset; uint64_t main_qos; uint32_t tsd_offset; uint32_t return_to_kernel_offset; uint32_t mach_thread_self_offset; - } __attribute__ ((packed)) _pthread_registration_data; + } __attribute__ ((packed)) _pthread_registration_data; - pthread_tsd_offset = ((_pthread_registration_data*) ARG4)->tsd_offset; - #endif + pthread_tsd_offset = ((_pthread_registration_data*) ARG4)->tsd_offset; +#endif ARG1 = (Word)&pthread_hijack_asm; ARG2 = (Word)&wqthread_hijack_asm; } @@ -2142,6 +2142,7 @@ PRE(workq_ops) // GrP fixme need anything here? // GrP fixme may block? break; + case VKI_WQOPS_THREAD_KEVENT_RETURN: case VKI_WQOPS_THREAD_RETURN: { // The interesting case. The kernel will do one of two things: // 1. Return normally. We continue; libc proceeds to stop the thread. @@ -2171,10 +2172,6 @@ PRE(workq_ops) // JRS uh, looks like it queues up a bunch of threads, or some such? *flags |= SfMayBlock; // the kernel sources take a spinlock, so play safe break; - case VKI_WQOPS_THREAD_KEVENT_RETURN: - // RK fixme need anything here? - // perhaps similar to VKI_WQOPS_THREAD_RETURN above? - break; case VKI_WQOPS_SET_EVENT_MANAGER_PRIORITY: // RK fixme this just sets scheduling priorities - don't think we need // to do anything here @@ -10487,6 +10484,7 @@ PRE(openat_nocancel) /* Otherwise handle normally */ *flags |= SfMayBlock; } + POST(openat_nocancel) { vg_assert(SUCCESS); -- 2.47.3