On 31-07-2012 20:30, Era Scarecrow wrote:
On Tuesday, 31 July 2012 at 17:23:08 UTC, Maxime Chevalier wrote:
New to the D language here. I'm working on a tracing JIT compiler and
will need to allocate chunks of memory that are marked as executable.
Is there a standard way of doing this in D, or do I need to directly
call into mprotect? If I'm going to be calling mprotect, what's the
cleanest way to do that, do I need to declare my own prototype for the
function and its flags, or should I write some C code that does the call?
The x86 chip it's a simple flag that the OS can set. For use with like
UPX, the whole section is marked read, write & execute I believe (since
it has to expand it first before it can execute the code; That is of
course for loaded memory, not allocating...). I would say check their
sources, may prove interesting.
UPX simply uses VirtualProtect/mprotect. It's the only way you _can_ do
this in ring 3 on any OS with sane security.
--
Alex Rønne Petersen
[email protected]
http://lycus.org