summaryrefslogtreecommitdiff
path: root/src/qcommon/vm_x86.c
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2009-10-26 00:10:07 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:17:05 +0000
commit0fed3b1c32d99560482ea162b197531439df76e5 (patch)
treedd5f74d3124715a538462aa474f9af294f79bbbd /src/qcommon/vm_x86.c
parentaf6fd4fa5aaa4dc7c59ae54ead20d5ef0fbcc946 (diff)
* Merge ioq3-r1708
Diffstat (limited to 'src/qcommon/vm_x86.c')
-rw-r--r--src/qcommon/vm_x86.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/qcommon/vm_x86.c b/src/qcommon/vm_x86.c
index 0f558ef7..e001f413 100644
--- a/src/qcommon/vm_x86.c
+++ b/src/qcommon/vm_x86.c
@@ -406,6 +406,15 @@ qboolean EmitMovEBXEDI(vm_t *vm, int andit) {
return qfalse;
}
+#define JUSED(x) \
+ do { \
+ if (x < 0 || x >= jusedSize) { \
+ Com_Error( ERR_DROP, \
+ "VM_CompileX86: jump target out of range at offset %d", pc ); \
+ } \
+ jused[x] = 1; \
+ } while(0)
+
/*
=================
VM_Compile
@@ -417,13 +426,14 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
int v;
int i;
qboolean opt;
+ int jusedSize = header->instructionCount + 2;
// allocate a very large temp buffer, we will shrink it later
maxLength = header->codeLength * 8;
buf = Z_Malloc( maxLength );
- jused = Z_Malloc(header->instructionCount + 2 );
+ jused = Z_Malloc(jusedSize);
- Com_Memset(jused, 0, header->instructionCount+2);
+ Com_Memset(jused, 0, jusedSize);
// ensure that the optimisation pass knows about all the jump
// table targets
@@ -564,7 +574,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
lastConst = Constant4();
Emit4( lastConst );
if (code[pc] == OP_JUMP) {
- jused[lastConst] = 1;
+ JUSED(lastConst);
}
break;
case OP_LOCAL:
@@ -730,7 +740,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "75 06" ); // jne +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_NE:
@@ -740,7 +750,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "74 06" ); // je +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_LTI:
@@ -750,7 +760,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "7D 06" ); // jnl +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_LEI:
@@ -760,7 +770,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "7F 06" ); // jnle +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_GTI:
@@ -770,7 +780,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "7E 06" ); // jng +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_GEI:
@@ -780,7 +790,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "7C 06" ); // jnge +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_LTU:
@@ -790,7 +800,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "73 06" ); // jnb +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_LEU:
@@ -800,7 +810,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "77 06" ); // jnbe +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_GTU:
@@ -810,7 +820,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "76 06" ); // jna +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_GEU:
@@ -820,7 +830,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "72 06" ); // jnae +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_EQF:
@@ -832,7 +842,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "74 06" ); // je +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_NEF:
@@ -844,7 +854,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "75 06" ); // jne +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_LTF:
@@ -856,7 +866,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "74 06" ); // je +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_LEF:
@@ -868,7 +878,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "74 06" ); // je +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_GTF:
@@ -880,7 +890,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "75 06" ); // jne +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_GEF:
@@ -892,7 +902,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
EmitString( "75 06" ); // jne +6
EmitString( "FF 25" ); // jmp [0x12345678]
v = Constant4();
- jused[v] = 1;
+ JUSED(v);
Emit4( (int)vm->instructionPointers + v*4 );
break;
case OP_NEGI: