It seems the ideas of OpenBSD W^X finally reached Mac OS X , but in a different way.
Other JITs handle that by
* mmap-ing the to-be-written code region R/W
* jitting to that region
* when done mprotect to remove the w and add the x
Example: Firefox .
That is a significant change to Cog's JIT. On the top of my head:
1. When jitting, one would need to control per page the rights inside the machine code zone and write each CogMethod within a page boundary with a 1-to-1 mapping CogMethod per page (likely memory overhead induced).
2. Inline cache logic (Mono, closedPIC and openPIC) should be changed not to edit the instructions in the machine code zone but a RW structure (likely execution time overhead induced), or to change page protection for relinking (which is think is disallowed, once it is executable it cannot go back to be W).
3. Machine code zone GC should be changed not to edit the machine code zone to update literals but a RW located structure, which is particulary nasty on back-ends where inlined literals are forced (x86_32) or to change page protection for relinking (which is think is disallowed, once it is executable it cannot go back to be W).
I'd say MAP_JIT is the cheap option unless someone has budget to invest in this change.
I have no idea why Apple came up with MAP_JIT. If we used the above,
maybe we don't need to be singend to at least run…