Executable memory

Adam D. Ruppe destructionator at gmail.com
Fri Oct 4 13:35:58 PDT 2013


On Friday, 4 October 2013 at 20:26:35 UTC, Alan wrote:
> Interesting... I was not aware of those functions in the D 
> runtime

Technically, they're part of the operating system. If druntime 
didn't provide them, you could also just add

// copy pasted from msdn
extern(Windows)
LPVOID VirtualAlloc(
   LPVOID lpAddress,
   SIZE_T dwSize,
   DWORD flAllocationType,
   DWORD flProtect
);


or

// copy pasted from the man page
extern(C)
  void *mmap(void *addr, size_t length, int prot, int flags,
                   int fd, off_t offset);


to your files (importing the necessary header so the types are 
defined, or defining them yourself too, might take some digging 
through the C header files though) and go ahead and call them 
that way.



> Just some simple conditional compile statements will probably 
> do the job!

yup. Also don't forget error checking, you should make sure the 
returned pointers aren't null (since they are C functions, they 
won't be throwing exceptions!)


More information about the Digitalmars-d-learn mailing list