summaryrefslogtreecommitdiff
path: root/src/qcommon/vm_x86_64.c
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2006-03-04 19:04:50 +0000
committerTim Angus <tim@ngus.net>2006-03-04 19:04:50 +0000
commit5da3420e72083d142352529acc11e1518ff153ba (patch)
tree7a8449dbe9989eebec47673e1c714e2f9cd4238a /src/qcommon/vm_x86_64.c
parent509b49968e696c7d01ebfe47eeef13acad8b6a32 (diff)
* Merged ioq3-r620
- NX stuff
Diffstat (limited to 'src/qcommon/vm_x86_64.c')
-rw-r--r--src/qcommon/vm_x86_64.c48
1 files changed, 15 insertions, 33 deletions
diff --git a/src/qcommon/vm_x86_64.c b/src/qcommon/vm_x86_64.c
index 23f87c30..822c3e1d 100644
--- a/src/qcommon/vm_x86_64.c
+++ b/src/qcommon/vm_x86_64.c
@@ -40,6 +40,8 @@ static FILE* qdasmout;
#define Dfprintf(args...)
#endif
+static void VM_Destroy_Compiled(vm_t* self);
+
/*
eax scratch
@@ -309,10 +311,8 @@ out:
static int doas(char* in, char* out, unsigned char** compiledcode)
{
- char* buf;
- char* mem;
- size_t size = -1, allocsize;
- int ps;
+ unsigned char* mem;
+ size_t size = -1;
pid_t pid;
Com_Printf("running assembler < %s > %s\n", in, out);
@@ -359,42 +359,16 @@ static int doas(char* in, char* out, unsigned char** compiledcode)
Com_Printf("done\n");
- mem = mmapfile(out, &size);
+ mem = (unsigned char*)mmapfile(out, &size);
if(!mem)
{
Com_Printf(S_COLOR_RED "can't mmap object file %s: %s\n", out, strerror(errno));
return -1;
}
- ps = sysconf(_SC_PAGE_SIZE);
- if(ps == -1)
- {
- Com_Printf(S_COLOR_RED "can't determine page size: %s\n", strerror(errno));
- return -1;
- }
-
- --ps;
+ *compiledcode = mem;
- allocsize = (size+ps)&~ps;
- buf = Hunk_Alloc(allocsize, h_high);
-
- buf = (void*)(((unsigned long)buf+ps)&~ps);
-
- memcpy(buf, mem, size);
-
- munmap(mem, 0);
-
- if((*compiledcode = (unsigned char*)buf))
- {
- // need to be able to exec code
- if(mprotect(buf, allocsize, PROT_READ|PROT_WRITE|PROT_EXEC) == -1)
- {
- Com_Error(ERR_FATAL, "mprotect failed on %p+%x: %s\n", buf, allocsize, strerror(errno));
- }
- return size;
- }
-
- return -1;
+ return size;
}
static void block_copy_vm(unsigned dest, unsigned src, unsigned count)
@@ -898,6 +872,8 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
vm->codeBase = compiledcode; // remember to skip ELF header!
vm->codeLength = compiledsize;
+
+ vm->destroy = VM_Destroy_Compiled;
entryPoint = getentrypoint(vm);
@@ -931,6 +907,12 @@ out:
}
}
+
+void VM_Destroy_Compiled(vm_t* self)
+{
+ munmap(self->codeBase, self->codeLength);
+}
+
/*
==============
VM_CallCompiled