From 82e379b8f2d1018973599f52c623d64d0de31b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Wed, 8 Jul 2026 10:36:37 +0200 Subject: [PATCH] Address review: block-comment style and document the macOS 12+ requirement Reformat the malloc_getcpu Apple comment to the block style and note that the tpidr_el0/sidt scheme requires macOS 12+: macOS 11 and earlier kept the CPU number in tpidrro_el0's low 3 bits (now retired). Cite xnu's __TPIDR_CPU_NUM_MASK / MACHDEP_TPIDR_CPUNUM_MASK, kept in sync with _os_cpu_number, as the source of truth. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../jemalloc/internal/jemalloc_internal_inlines_a.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/include/jemalloc/internal/jemalloc_internal_inlines_a.h b/include/jemalloc/internal/jemalloc_internal_inlines_a.h index 1e3b7972..5f0d9d89 100644 --- a/include/jemalloc/internal/jemalloc_internal_inlines_a.h +++ b/include/jemalloc/internal/jemalloc_internal_inlines_a.h @@ -19,9 +19,17 @@ malloc_getcpu(void) { #elif defined(JEMALLOC_HAVE_SCHED_GETCPU) return (malloc_cpuid_t)sched_getcpu(); #elif defined(__APPLE__) - /* No sched_getcpu() on macOS; read the CPU number like _os_cpu_number(), see + /* + * No sched_getcpu() on macOS; read the CPU number like _os_cpu_number() + * does, from the low 12 bits of tpidr_el0 (arm64) or the IDT base (x86). + * The 0xfff mask is xnu's __TPIDR_CPU_NUM_MASK, kept in sync with + * _os_cpu_number in libsyscall/os/tsd.h (the kernel counterpart is + * MACHDEP_TPIDR_CPUNUM_MASK in osfmk/arm64/machine_machdep.h): * https://github.com/apple-oss-distributions/xnu/blob/main/libsyscall/os/tsd.h - * (it is no longer in tpidrro_el0's low bits on Apple Silicon). */ + * This requires macOS 12+: on macOS 11 and earlier arm64 kept the CPU + * number in tpidrro_el0's low 3 bits instead, so it would be misread here. + * Those releases are retired by Apple, so only the current layout is handled. + */ # if defined(__aarch64__) uint64_t cpu; __asm__ __volatile__("mrs %0, tpidr_el0" : "=r"(cpu));