Commit 325fea93 authored by Ramiro Polla's avatar Ramiro Polla Committed by David Schleef

Use VirtualAlloc() to allocate executable memory on Windows.

parent eb1003ba
......@@ -85,9 +85,12 @@ then
fi
case "${host_os}" in
mingw*|pw32*|cygwin*)
nobody_is_using_this_currently)
AC_DEFINE(HAVE_CODEMEM_MALLOC, 1, [Use malloc to allocate code for execution])
;;
mingw*|pw32*|cygwin*)
AC_DEFINE(HAVE_CODEMEM_VIRTUALALLOC, 1, [Use VirtualAlloc to allocate code for execution])
;;
linux*|darwin*|solaris*|netbsd*|freebsd*|openbsd*|kfreebsd*|gnu*)
AC_DEFINE(HAVE_CODEMEM_MMAP, 1, [Use mmap to allocate code for execution])
;;
......
......@@ -14,6 +14,9 @@
#ifdef HAVE_CODEMEM_MMAP
#include <sys/mman.h>
#endif
#ifdef HAVE_CODEMEM_VIRTUALALLOC
#include <windows.h>
#endif
#include <orc/orcprogram.h>
#include <orc/orcdebug.h>
......@@ -65,12 +68,21 @@ orc_compiler_allocate_codemem (OrcCompiler *compiler)
}
#endif
#ifdef HAVE_CODEMEM_MALLOC
#ifdef HAVE_CODEMEM_VIRTUALALLOC
void
orc_compiler_allocate_codemem (OrcCompiler *compiler)
{
/* Now you know why Windows has viruses */
compiler->program->code = VirtualAlloc(NULL, SIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
compiler->program->code_exec = compiler->program->code;
compiler->program->code_size = SIZE;
compiler->codeptr = compiler->program->code;
}
#endif
#ifdef HAVE_CODEMEM_MALLOC
void
orc_compiler_allocate_codemem (OrcCompiler *compiler)
{
compiler->program->code = malloc(SIZE);
compiler->program->code_exec = compiler->program->code;
compiler->program->code_size = SIZE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment