[mono] Work around arm64 MacCatalyst unavailable JITing API #51669
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.
To JIT on Apple Silicon the application must call
pthread_jit_write_protect_np (0)
before writing to a code page and thenpthread_jit_write_protect_np (1)
before executing JITed code.Catalyst apps are Mac apps that get to use iOS frameworks (as well as some mac frameworks). The API access is guarded by
__API_AVAILABLE
and__API_UNAVAILABLE
macros in Apple framework headers. If an API is not explicitly marked for catalyst, clang will follow theios
availability.Unfortunately,
pthread_jit_write_protect_np
is marked like this:So a Catalyst app running on arm64 cannot call it. It will get a compile-time error.
Turns out the symbol
pthread_jit_write_protect_np
is actually present in the Catalyst framework libraries, and it does the right thing.This PR works around the unfortunate
pthread.h
declaration by not using it.We create a new .c file that included our own declaration
And then a new
mono_jit_write_protect
function that calls the pthread function.Another option would be to use something like
around the offending callsites. But neither ignoring
-Wpartial-availability
nor-Wunguarded-availability-new
seem to have any effect on the compilation error.Caveat: It's not yet clear whether this is ok to do in a retail (App Store) app.