Fix SPRX Loader segfault on Apple ARM64 by excluding MAP_JIT from memory mapping regions#18425
Fix SPRX Loader segfault on Apple ARM64 by excluding MAP_JIT from memory mapping regions#18425Drustburn wants to merge 1 commit intoRPCS3:masterfrom
Conversation
…ory mapping regions On Apple ARM64, memory_reserve unconditionally applies MAP_JIT to all reservations. However, regions marked as is_memory_mapping are later replaced by file-backed MAP_FIXED mappings via shm::map/map_critical. Overlaying a file-backed MAP_FIXED mapping onto a MAP_JIT region causes the resulting pages to be inaccessible, leading to a segfault when the SPRX Loader attempts to write module data into PS3 memory (g_sudo_addr). Fix: Only apply MAP_JIT for non-mapping regions. Memory mapping regions don't need JIT capability since they use shared memory for the PS3 address space, not executable JIT code. Tested on Apple M3 Max, macOS 26.3.1. The SPRX Loader now successfully loads all modules and emulation proceeds past the loading stage.
|
@Drustburn Can you provide examples of any games where either this PR or #18423 make a meaningful positive difference? Asking as I haven't experienced the described crashes these PRs claim to fix in the games I have on hand at the moment. (Please also reply without using AI if that's possible to avoid any confusion, given both of your PRs are suspected to be AI generated by their descriptions.) |
|
I used the Jak and Daxter Trilogy to test this. |
Right, just tested against a disc dump of the Jak trilogy and it boots perfectly fine for me on the latest master build, so unless you're aware of any other games your PRs have any positive impact on I'm doubtful that they'll pass muster (other PRs have been closed in the past for not providing any benefits iirc). |
|
Maybe apply it to all unix platforms? |
Can you explain this in more detail? I tried reproducing it and it works fine in my test. The pages are accessible, and vmmap seems to indicate the expected permissions on the pages. (Sorry, not really for this project, but one of the projects I work on does this as well and it would be good to know if this doesn't work in some situations on arm macOS.) #include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, const char * argv[]) {
int fd = open("/tmp/mem.bin", O_RDWR | O_CREAT, 0644);
char* ptr0 = mmap(NULL, 65536, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON|MAP_JIT, -1, 0);
char* ptr1 = mmap(ptr0 + 32768, 32768, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FILE|MAP_FIXED, fd, 0);
ptr1[0] = 4;
printf("Mapped at %p\n", ptr0);
char cmd[64];
snprintf(cmd, sizeof(cmd), "vmmap %d", getpid());
system(cmd);
munmap(ptr0, 65536);
close(fd);
return EXIT_SUCCESS;
} |
Summary
On Apple ARM64,
memory_reserveunconditionally appliesMAP_JITto all reservations. However, regions marked asis_memory_mapping(likeg_base_addr/g_sudo_addr) are later replaced by file-backedMAP_FIXEDmappings viashm::map/map_critical.Overlaying a file-backed
MAP_FIXEDmapping onto aMAP_JITregion causes the resulting pages to be inaccessible, leading to a segfault when the SPRX Loader attempts to write module data into PS3 memory (g_sudo_addr):Fix
Only apply
MAP_JITfor non-mapping regions. Memory mapping regions don't need JIT capability since they use shared memory for the PS3 address space, not executable JIT code.Test plan