Skip to content

Fix function cloning Darwin/arm64#9

Open
pboyd wants to merge 1 commit intomainfrom
macos-arm
Open

Fix function cloning Darwin/arm64#9
pboyd wants to merge 1 commit intomainfrom
macos-arm

Conversation

@pboyd
Copy link
Owner

@pboyd pboyd commented Feb 23, 2026

  • On Darwin, use MAP_JIT when allocating memory for cloned functions and call pthread_jit_write_protect_np() as needed.
  • On arm64, try to reserve memory within 128 MiB of the text/data segments, but allow addresses up to 4 GiB away. When a BL address is more than 128 MiB away insert a trampoline at the end of the function to branch to the fixed address.
  • On amd64, the search code still still applies, but we only need to be within range of a 32-bit signed int.

@pboyd pboyd force-pushed the macos-arm branch 23 times, most recently from 55465b6 to 2048d31 Compare February 25, 2026 11:56
@pboyd pboyd marked this pull request as ready for review February 25, 2026 11:57
@pboyd pboyd force-pushed the macos-arm branch 6 times, most recently from 98f57bf to 46ea1e9 Compare February 27, 2026 12:40
@pboyd pboyd changed the title Workaround problems on Darwin/arm64 Fix function cloning Darwin/arm64 Feb 27, 2026
- On Darwin, use MAP_JIT when allocating memory for cloned functions and
  call `pthread_jit_write_protect_np()` as needed.
- On arm64, try to reserve memory within 128 MiB of the text/data
  segments, but allow addresses up to 4 GiB away. When a BL address is
  more than 128 MiB away insert a trampoline at the end of the function
  to branch to the fixed address.
- On amd64, the search code still still applies, but we only need to be
  within range of a 32-bit signed int.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant