Browse Source

on win32 use VirtualAlloc and VirtualFree to allocate/free executable memory

cache-refactoring
Aleksey Demakov 17 years ago
parent
commit
0d39a0e365
  1. 5
      ChangeLog
  2. 20
      jit/jit-alloc.c

5
ChangeLog

@ -1,3 +1,8 @@
2008-05-23 Juan Jesus Garcia de Soria <juanj.g_soria@grupobbva.com>
* jit/jit-alloc.c (jit_malloc_exec, jit_free_exec): on win32 use
VirtualAlloc and VirtualFree to allocate/free executable memory.
2008-05-23 Klaus Treichel <ktreichel@web.de>
* dpas/dpas-scanner.l, tools/gen-rules-scanner.l,

20
jit/jit-alloc.c

@ -143,10 +143,14 @@ void jit_free(void *ptr)
@*/
void *jit_malloc_exec(unsigned int size)
{
#ifdef JIT_USE_MMAP
void *ptr = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
#if defined(JIT_WIN32_PLATFORM)
return VirtualAlloc(NULL, size,
MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
#elif defined(JIT_USE_MMAP)
void *ptr = mmap(0, size,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if(ptr == (void *)-1)
{
return (void *)0;
@ -169,11 +173,13 @@ void jit_free_exec(void *ptr, unsigned int size)
{
if(ptr)
{
#ifdef JIT_USE_MMAP
#if defined(JIT_WIN32_PLATFORM)
VirtualFree(ptr, size, MEM_DECOMMIT | MEM_RELEASE);
#elif defined(JIT_USE_MMAP)
munmap(ptr, size);
#else
#else
free(ptr);
#endif
#endif
}
}

Loading…
Cancel
Save