Related to: Reloaded-Project/Reloaded.Hooks-rs#1
Currently we toggle between R^X and R^W, because this is forced on us by the mach_ APIs. This is not ideal, in a situation like hooks, it's possible we might be toggling code in process of being executed, in which case, we're smoked.
Unfortunately the JIT APIs pthread_jit_write_protect_np only work on memory allocated with mmap, not the mach APIs, and allocating at specific address with mmap is broken on macOS. Well played.
It would be nice to experiment with mapping each custom page twice over, but that's unfortunately not a possibility right now. Without access to one of these machines, I can't test it very well, short of paying some cloud company for access (lol) or hassling someone too much for my liking.