2 ms·
You give executable permissions to a region of memory with machine code in it. The easy way to do this is mmap with PROT_EXEC then memcpy to it. Here's a good t
by duped 5y ago
You give executable permissions to a region of memory with machine code in it. The easy way to do this is mmap with PROT_EXEC then memcpy to it. Here's a good tutorial: https://eli.thegreenplace.net/2013/11/05/how-to-jit-an-introduction https://eli.thegreenplace.net/2013/11/05/how-to-jit-an-intro...
There is an issue with this on MacOS Big Sur where pages may not be writeable and executable in a hardened runtime. To get around that you need to write the machine code first, then mark it executable.
To execute the code you can cast it to a function pointer and call it.