Skip to content

Conversation

@patryk4815
Copy link
Contributor

@patryk4815 patryk4815 commented Aug 7, 2025

The read_sprr_perm function now correctly works both on real Apple CPUs and in GitHub Actions virtualized environments by relying on pthread_jit_write_protect_supported_np().
This ensures proper detection of JIT write protection status without depending on build-time msr register check.
As a result, building wheels for Apple ARM64 should now fully work fine.

Fixes:

More context:
In libsystem_pthread.dylib, the function _pthread_jit_write_protect_np first checks whether JIT write protection is enabled by reading from a special memory location in the commpage: 0xfffffc10c.
The same memory location is also checked by the _pthread_jit_write_protect_supported_np function.

In other words, whenever Apple code wants to access the S3_6_c15_c1_5 system register using the mrs instruction, it first verifies that JIT write protection is supported by calling _pthread_jit_write_protect_supported_np(), which ensures the system is in a valid state for that operation.

image image

@wtdcode
Copy link
Member

wtdcode commented Aug 7, 2025

This seems cool, let’s see CI.

@patryk4815
Copy link
Contributor Author

patryk4815 commented Aug 7, 2025

@wtdcode probably I need disable assertion in assert_executable, I see one crash (when _pthread_jit_write_protect_supported_np is false)
done

@wtdcode wtdcode merged commit 79f910e into unicorn-engine:dev Aug 8, 2025
44 checks passed
@wtdcode
Copy link
Member

wtdcode commented Aug 8, 2025

Thanks =)

momo5502 added a commit to momo5502/unicorn that referenced this pull request Aug 24, 2025
…enable Apple ARM64 wheel builds on PyPI. Fixes unicorn-engine#2033. (unicorn-engine#2227)"

This reverts commit 79f910e.
K4ddate pushed a commit to K4ddate/unicorn that referenced this pull request Sep 16, 2025
…pple ARM64 wheel builds on PyPI. Fixes unicorn-engine#2033. (unicorn-engine#2227)

* Fix `read_sprr_perm` for Apple real CPUs and GitHub Actions; enable Apple ARM64 wheel builds on PyPI. Fixes unicorn-engine#2033.

* Guard `assert_executable` with `pthread_jit_write_protect_supported_np`
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.

2 participants