JIT: fastmem: handle W^X codemem in fault handler

Set the protection on the code memory to RW when the fault handler
rewrites code, and set it back to RX, the protection prior to the
interrupt, after doing so.

This fixes a segfault that occurred on NetBSD, due to its PaX MPROTECT
policy, when trying to run fastmem.

This could potentially be the reason as to why fastmem does not work on
Apple Silicon Macs, although I am unable to confirm as I do not possess
such a device to test with.
This commit is contained in:
Rayyan Ansari
2025-08-28 21:58:51 +01:00
parent eaa477de7d
commit 18a4885c22

View File

@ -826,7 +826,11 @@ bool ARMJIT_Memory::FaultHandler(FaultDescription& faultDesc, melonDS::NDS& nds)
rewriteToSlowPath = !nds.JIT.Memory.MapAtAddress(faultDesc.EmulatedFaultAddr);
if (rewriteToSlowPath)
{
nds.JIT.JitEnableWrite();
faultDesc.FaultPC = nds.JIT.JITCompiler.RewriteMemAccess(faultDesc.FaultPC);
nds.JIT.JitEnableExecute();
}
return true;
}