diff options
author | thilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2006-05-15 15:57:02 +0000 |
---|---|---|
committer | thilo <thilo@edf5b092-35ff-0310-97b2-ce42778d08ea> | 2006-05-15 15:57:02 +0000 |
commit | 52c9ab29da968989517b20ba84a376dee91690c9 (patch) | |
tree | 1c9275c8aa53f0a64dc1ed0867728a15be4b7f50 /code | |
parent | fdc20842602910fe3dd4026bb1dd6a67020f6fb3 (diff) | |
download | ioquake3-aero-52c9ab29da968989517b20ba84a376dee91690c9.tar.gz ioquake3-aero-52c9ab29da968989517b20ba84a376dee91690c9.zip |
Fix JIT compiler code execution on NX-protected win32 OS
git-svn-id: svn://svn.icculus.org/quake3/trunk@780 edf5b092-35ff-0310-97b2-ce42778d08ea
Diffstat (limited to 'code')
-rw-r--r-- | code/qcommon/vm_x86.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/code/qcommon/vm_x86.c b/code/qcommon/vm_x86.c index 7a0c162..527ee72 100644 --- a/code/qcommon/vm_x86.c +++ b/code/qcommon/vm_x86.c @@ -22,6 +22,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // vm_x86.c -- load time compiler and execution environment for x86 #include "vm_local.h" +#ifdef _WIN32 +#include <windows.h> +#endif #ifdef __FreeBSD__ // rb0101023 #include <sys/types.h> @@ -1081,6 +1084,11 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { vm->codeBase = mmap(NULL, compiledOfs, PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0); if(vm->codeBase == (void*)-1) Com_Error(ERR_DROP, "VM_CompileX86: can't mmap memory"); +#elif _WIN32 + // allocate memory with EXECUTE permissions under windows. + vm->codeBase = VirtualAlloc(NULL, compiledOfs, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + if(!vm->codeBase) + Com_Error(ERR_DROP, "VM_CompileX86: VirtualAlloc failed"); #else vm->codeBase = malloc(compiledOfs); #endif @@ -1090,6 +1098,14 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { #ifdef VM_X86_MMAP if(mprotect(vm->codeBase, compiledOfs, PROT_READ|PROT_EXEC)) Com_Error(ERR_DROP, "VM_CompileX86: mprotect failed"); +#elif _WIN32 + { + DWORD oldProtect = 0; + + // remove write permissions. + if(!VirtualProtect(vm->codeBase, compiledOfs, PAGE_EXECUTE_READ, &oldProtect)) + Com_Error(ERR_DROP, "VM_CompileX86: VirtualProtect failed"); + } #endif Z_Free( buf ); @@ -1108,6 +1124,8 @@ void VM_Destroy_Compiled(vm_t* self) { #ifdef VM_X86_MMAP munmap(self->codeBase, self->codeLength); +#elif _WIN32 + VirtualFree(self->codeBase, self->codeLength, MEM_RELEASE); #else free(self->codeBase); #endif |