-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Dart on Apple M1 (arm64) doesn't call pthread_jit_write_protect_np when writing to executable memory #45793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Some background: Flutter engine can now cross compile to darwin-arm64 and with some changes flutter tool can assemble darwin-arm64 assets. Release (AOT) build works as expected on M1, JIT crashes when writing to executable memory. |
Something to keep in mind when implementing this: pthread_jit_write_protect_np does not have a sane initial value. |
@knopp if you read the whole issue then it apparently does have a reasonable default and the issue was a misunderstanding: https://github.com/dotnet/runtime/pull/51135/files |
My bad, I must have overlooked it. Never mind then. |
FWIW, I have built the standalone VM for ARM64 and successfully run both JIT and AOT on an M1, so I suspect there is some Flutter-specific issue. |
@rmacnak-google, weird - that shouldn't be possible according to Apple documentation. You shouldn't be able to write into |
I think this code in the engine which disables code write protection is to blame. Dart VM by default already flips code regions between RW and RX modes so that a memory region is never R and X at the same time (alternatively we use dual mapping to achieve the same on platforms where this is possible). That explains, why standalone VM works just fine. Flutter Engine disables this mode to avoid performance issues associated with it (unclear if this issues are relevant in development though), but as a result it uses VM in the mode where code pages are RWX and consequently we hit Mac OS X new protections. |
@mraleph, you're right! Thanks. It seems that |
Is there a link to the Flutter issue? :) |
Here: flutter/flutter#81208 (with a PR) |
This results in immediate segfault when running on Apple M1. Relevant documention from Apple:
https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon
Related to: #42773
This tracker is for issues related to:
The text was updated successfully, but these errors were encountered: