Mark JIT code as writeable / executable depending on the situation
Some platforms don't want memory to be marked as writeable and
executable at the same time. When we write to the code block, we
calculate the OS page that the buffer position maps to. Then we call mprotect to allow writes on that particular page. As an optimization,
we cache the "last written" aligned page which allows us to amortize the
cost of the mprotect call. In other words, sequential writes to the
same page will only call mprotect on the page once.
When we're done writing, we call mprotect on the entire JIT buffer.
This means we don't need to keep track of which pages were marked as
writeable, we let the OS take care of that.
Mark JIT code as writeable / executable depending on the situation
Some platforms don't want memory to be marked as writeable and
executable at the same time. When we write to the code block, we
calculate the OS page that the buffer position maps to. Then we call
mprotect
to allow writes on that particular page. As an optimization,we cache the "last written" aligned page which allows us to amortize the
cost of the
mprotect
call. In other words, sequential writes to thesame page will only call
mprotect
on the page once.When we're done writing, we call
mprotect
on the entire JIT buffer.This means we don't need to keep track of which pages were marked as
writeable, we let the OS take care of that.
Co-authored-by: John Hawthorn [email protected]