summaryrefslogtreecommitdiff
path: root/src/qcommon/vm_x86.c
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2006-05-16 20:50:00 +0000
committerTim Angus <tim@ngus.net>2006-05-16 20:50:00 +0000
commitbac6bec08fe63e12578c47809823cb7ee3016c44 (patch)
treed5e3b21c8d8063d2f9afc4eb71e7a7b427d91c81 /src/qcommon/vm_x86.c
parent5c0efda0ef811b2bafedb2b4f53b083a9b90e1b4 (diff)
* Merged ioq3-r783
* Added back the syscalls things I didn't mean to remove
Diffstat (limited to 'src/qcommon/vm_x86.c')
-rw-r--r--src/qcommon/vm_x86.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/qcommon/vm_x86.c b/src/qcommon/vm_x86.c
index 2115cf50..c0a703bc 100644
--- a/src/qcommon/vm_x86.c
+++ b/src/qcommon/vm_x86.c
@@ -23,6 +23,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>
@@ -1082,6 +1085,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
@@ -1091,6 +1099,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 );
@@ -1109,6 +1125,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