use mmap calls for executable memory allocation on non-win32

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3868 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
TimeServ 2011-07-12 04:38:54 +00:00
parent 329e5750d3
commit 987a86a4ac
1 changed files with 15 additions and 0 deletions

View File

@ -42,6 +42,10 @@ optimisations:
#ifdef QCJIT
#ifndef _WIN32
#include <sys/mman.h>
#endif
static float ta, tb, nullfloat=0;
struct jitstate
@ -206,7 +210,11 @@ void PR_CloseJit(struct jitstate *jit)
{
free(jit->statementjumps);
free(jit->statementoffsets);
#ifndef _WIN32
munmap(jit->code, jit->jitstatements * 500);
#else
free(jit->code);
#endif
}
#define EmitByte(v) EmitByte(jit, v)
@ -238,7 +246,11 @@ struct jitstate *PR_GenerateJit(progfuncs_t *progfuncs)
jit->statementjumps = malloc(numstatements*12);
jit->statementoffsets = malloc(numstatements*4);
#ifndef _WIN32
jit->code = mmap(NULL, numstatements*500, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
#else
jit->code = malloc(numstatements*500);
#endif
if (!jit->code)
return NULL;
@ -1256,6 +1268,7 @@ LOADREG(glob + op[i].b, REG_EDI);
FixupJumps(jit);
/* most likely want executable memory calls somewhere else more common */
#ifdef _WIN32
{
DWORD old;
@ -1264,6 +1277,8 @@ LOADREG(glob + op[i].b, REG_EDI);
//this means that we must maintain read/write protection, or libc will crash us
VirtualProtect(jit->code, jit->codesize, PAGE_EXECUTE_READWRITE, &old);
}
#else
mprotect(jit->code, jit->codesize, PROT_READ|PROT_EXEC);
#endif
// externs->WriteFile("jit.x86", jit->code, jit->codesize);