-
Notifications
You must be signed in to change notification settings - Fork 407
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
"Cannot allocate executable pages" on macOS/arm64 if GC_set_pages_executable(1) #394
Comments
Do you use bdwgc master? |
Is USE_MMAP_ANON defined or not? Try the opposite, because GC_unix_mmap_get_mem logic is different. The difference in gcconfig.h between arm64 and x64: MPROTECT_VDB is not defined for arm64. I don't think it will help, but try passing -D MPROTECT_VDB to CFLAGS_EXTRA for arm64 build. |
I originally tried the 8.2.0 release, and also the latest master (today). Same result. Well, turning off
|
Do you think it may be related to mmap issues other projects have encountered, eg. nodejs/node#37061 (comment). ? |
Probably. What's the solution possible? |
It looks like we need a fix similar to that in Chromium. Will it help? You can quickly try it by adding MAP_JIT |
Applying MAP_JIT, the entitlements, and code-signing the app results in a bus error on the first write to memory. Here is a reproducible example : #include <stdio.h>
#include <sys/mman.h>
int main(){
int N=5;
int *ptr = mmap ( NULL, N*sizeof(int), PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS , 0, 0 );
if ( ptr == MAP_FAILED ) {
printf("Mapping Failed\n");
return 1;
}
for(int i=0; i<N; i++) {
ptr[i] = i*10;
}
for(int i=0; i<N; i++)
printf("[%d] ",ptr[i]);
printf("\n");
int err = munmap(ptr, 10*sizeof(int));
if(err != 0){
printf("UnMapping Failed\n");
return 1;
}
return 0;
} Built for x64, it runs without a problem : If we add the entitlements.plist
Apply code signing, with runtime hardening
The result is a bus error. The same error in gctest.
There's an interesting comment here : zherczeg/sljit#99 This implies that on macOS Apple Silicon (arm64) you cannot set memory to Indeed. If you modify the example above to exclude If I set |
NO_EXECUTE_PERMISSION is defined by default (all provided build scripts). This is done for performance reasons. The clients could overwrite this by GC_set_pages_executable(1) before GC_INIT() if they need to allocate executable memory. According to this issue, clients on macOS/arm64 cannot allocate executable memory as of the current bdwgc version. I'm not aware if any of known bdwgc clients are affected.
Implementing a workaround in bdwgc is not trivial (and involves proposing new API for clients), the usage could be like this, just a guess:
|
If someone needs this functionality, patches are welcomed. |
The clasp project (https://github.com/clasp-developers/clasp.git) is a Boehm client that needs this functionality. |
I found a way around it. I don't use the GC to allocate large blocks to put JITted code into them. |
Got it. Thank you for the W/A idea. |
Is there much of a cost to using No worries - I'll find out. |
I found out - there is a hard limit of 8192 root sets (using |
Okay. It is better to open another issue for this. |
I reproduced it myself.
If we allocate w/o PROT_EXEC, then it works:
|
While working on a macOS arm64 native build of my project, binaries are failing with the following error : "Cannot allocate executable pages".
So I built gctest ( as per the instructions, using the latest sources from the master branch) and it also fails with the same error.
When built for x64 using the same version of bdwgc on the same machine, binaries are running as expected (under rosetta, presumably).
In my project, bdwgc is a static build.
Any ideas what the issue may be?
Perhaps there's some config I can tweak?
Thanks!
The text was updated successfully, but these errors were encountered: