From: "Jonathan Worthington" <[EMAIL PROTECTED]>
> Here is my attempt at a patch for executable memory allocation, which
makes
+void *
+mem_alloc_executable(size_t size)
+{
+ void *ptr = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
^^^^^^^^^^^^^^^
MEM_RESERVE | MEM_COMMIT
or more preferrable MEM_RESERVE | MEM_TOP_DOWN | MEM_COMMIT
+ if (memInfo.RegionSize <= size)
+ {
+ CopyMemory(newBlock, memblock, memInfo.RegionSize);
+ }
+ else
+ {
+ CopyMemory(newBlock, memblock, size);
+ }
memInfo.RegionSize is always either greater or equal size. So just
CopyMemory(newBlock, memblock, size);
would be enough
+void
+mem_free_executable(void *addr)
+{
+ /* We need to decommit, then release the pages. */
+ VirtualFree(addr, 1, MEM_DECOMMIT); <<<<<<<<<<<<< No need
+ VirtualFree(addr, 0, MEM_RELEASE);
+}
There is no need to decommit pages if next you release the region.
0x4C56