[quake3-commits] r1722 - trunk/code/qcommon

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Nov 1 14:58:22 EST 2009


Author: ludwig
Date: 2009-11-01 14:58:21 -0500 (Sun, 01 Nov 2009)
New Revision: 1722

Modified:
   trunk/code/qcommon/vm_x86_64.c
Log:
report memory violations in debug mode

Modified: trunk/code/qcommon/vm_x86_64.c
===================================================================
--- trunk/code/qcommon/vm_x86_64.c	2009-11-01 19:58:18 UTC (rev 1721)
+++ trunk/code/qcommon/vm_x86_64.c	2009-11-01 19:58:21 UTC (rev 1722)
@@ -320,18 +320,19 @@
 	emit(op " %%cl, %%eax"); \
 	emit("movl %%eax, 0(%%rsi)");
 
-#if 1
+#ifdef DEBUG_VM
 #define RANGECHECK(reg, bytes) \
+	emit("movl %%" #reg ", %%ecx"); \
+	emit("andl $0x%x, %%ecx", vm->dataMask &~(bytes-1)); \
+	emit("cmpl %%" #reg ", %%ecx"); \
+	emit("jz rc_ok_i_%08x", instruction); \
+	emit("movq $%lu, %%rax", (unsigned long)memviolation); \
+	emit("callq *%%rax"); \
+	emit("rc_ok_i_%08x:", instruction);
+#elif 1
+// check is too expensive, so just confine memory access
+#define RANGECHECK(reg, bytes) \
 	emit("andl $0x%x, %%" #reg, vm->dataMask &~(bytes-1));
-#elif 0
-#define RANGECHECK(reg, bytes) \
-	emit("pushl %%" #reg); \
-	emit("andl $0x%x, %%" #reg, ~vm->dataMask); \
-	emit("jz rangecheck_ok_i_%08x", instruction); \
-	emit("int3"); \
-	emit("rangecheck_ok_i_%08x:", instruction); \
-	emit("popl %%" #reg); \
-	emit("andl $0x%x, %%" #reg, vm->dataMask);
 #else
 #define RANGECHECK(reg, bytes)
 #endif
@@ -370,6 +371,14 @@
 	exit(1);
 }
 
+#ifdef DEBUG_VM
+static void memviolation(void)
+{
+	Com_Error(ERR_DROP, "program tried to access memory outside VM\n");
+	exit(1);
+}
+#endif
+
 /*
 =================
 VM_Compile



More information about the quake3-commits mailing list