Repository navigation
Conversation
New ports under src/port/aarch64/macos and src/port/x86-64/macos: - Context switch: AArch64 assembly saving X19-X30, D8-D15, FPCR/FPSR, and a Mach-O (macho64) variant of the x86-64 NASM switch. - Guarded coroutine stacks via posix_memalign + mprotect, main stack bounds from pthread_get_stackaddr_np / pthread_get_stacksize_np. - Seeds from arc4random_buf, core count from sysconf. Shared changes, all limited to the new platforms: - cmi_config.h recognises arm64 and macOS. - Trial recovery uses setjmp/longjmp on arm64, since Clang does not implement __builtin_setjmp on AArch64. - Build: dispatch to the new ports, only require NASM on x86-64, use _DARWIN_C_SOURCE instead of _POSIX_C_SOURCE on macOS, and only pass -ffat-lto-objects when the compiler accepts it (Apple Clang does not). Co-Authored-By: Claude <noreply@anthropic.com> Includes-AI-Code: true
Both macOS ports called mprotect on every coroutine stack allocation and free, so every spawned process cost two system calls. Keep a per-thread pool of recycled guarded stacks, as the x86-64 Linux port does: a stack is protected once when first allocated, reused by later coroutines of the same size, and unprotected and freed by cmi_coroutine_stack_cleanup() at thread exit. Stacks are rounded up to whole pages, as on Linux. cmi_pagesize() now asks the OS once and caches the value. On an Apple M-series Mac, a churn of short-lived processes (~100 alive, 4M spawned) drops from 1.73 to 0.70 us per spawn; mprotect was 55% of the trial before and is gone from the profile. Co-Authored-By: Claude <noreply@anthropic.com> Includes-AI-Code: true
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds macOS support on both Apple Silicon and Intel Macs. Nothing changes for Linux or Windows: every shared-code change applies only to the new platforms.
New ports
src/port/aarch64/macosandsrc/port/x86-64/macos, using the same port interface asx86-64/linux:macho64, with Mach-O's leading-underscore symbols.posix_memalign, with aPROT_NONEguard page set bymprotect. As inx86-64/linux, freed stacks go to a per-thread pool and are reused by later coroutines of the same size, so each stack is protected once rather than on every spawn and retire.cmi_coroutine_stack_cleanup()frees the pool at thread exit. The main thread's stack bounds come frompthread_get_stackaddr_np/pthread_get_stacksize_np.cmi_pagesize()asks the OS once and caches the value.arc4random_buf, the core count fromsysconf(_SC_NPROCESSORS_ONLN).Shared changes
cmi_config.h: addsCMI_ARM64andCMI_MACOSdetection.cimba.c: Clang does not implement__builtin_setjmp/__builtin_longjmpon AArch64, so trial recovery usessetjmp/longjmpon arm64. x86-64 keeps the builtins.meson.build: NASM is required only on x86-64. macOS builds use-D_DARWIN_C_SOURCEinstead of-D_POSIX_C_SOURCE=200809L, because the POSIX define hidespthread_get_stackaddr_npandarc4random_buf.src/meson.build:-ffat-lto-objectsis passed only when the compiler accepts it. Apple Clang rejects it.src/port/meson.build: picks the port from the CPU family and OS.Testing
meson setup build && meson test -C buildpasses all 27 tests in a release build with LTO, and in a debug build with AddressSanitizer.mprotectwas about 55% of the run; it no longer shows in the profile.clang -arch x86_64andnasm -f macho64, linked the test programs against it and ran them under Rosetta. All test programs pass. The meson x86-64 build path itself was not run. The stack pool commit was compiled for x86-64 withclang -arch x86_64, but not run there.Co-Authored-By: Claude noreply@anthropic.com
Includes-AI-Code: true