* jit/jit-alloc.c: Use mmap and munmap to allocate executable memory
where available because memory allocated with malloc is not executable
on some archs/distros.
+2006-08-22 Klaus treichel <ktreichel@web.de>
+
+ * jit/jit-alloc.c: Use mmap and munmap to allocate executable memory
+ where available because memory allocated with malloc is not executable
+ on some archs/distros.
+
2006-08-23 Aleksey Demakov <ademakov@gmail.com>
* jit/jit-reg-alloc.c: improve handling of three-address op codes.
#include <windows.h>
#include <io.h>
#endif
+#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MMAP) && defined(HAVE_MUNMAP)
+/*
+ * Make sure that "MAP_ANONYMOUS" is correctly defined, because it
+ * may not exist on some variants of Unix.
+ */
+#ifndef MAP_ANONYMOUS
+ #ifdef MAP_ANON
+ #define MAP_ANONYMOUS MAP_ANON
+ #endif
+#endif
+#ifdef MAP_ANONYMOUS
+#define JIT_USE_MMAP
+#endif
+#endif
+
/*@
* @section Memory allocation
@*/
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(ptr == (void *)-1)
+ {
+ return (void *)0;
+ }
+ return ptr;
+#else
return malloc(size);
+#endif
}
/*@
{
if(ptr)
{
+ #ifdef JIT_USE_MMAP
+ munmap(ptr, size);
+ #else
free(ptr);
+ #endif
}
}