shithub: 5v

Download patch

ref: 26dd49399614ec9544f66aa95809af437247322e
parent: c1b943384c1cf8bddbad7df63319d597710f943d
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Sep 9 17:09:02 EDT 2023

chk: give better errors.

--- a/chk.c
+++ b/chk.c
@@ -63,9 +63,14 @@
 		exits("bad access");
 	}
 	for(; off != end; off++){
-		bits = chk << (2*(off&3));;
-		if((seg->shadow[off>>2] & bits) != bits){
-			print("invalid read: %#x at %#x (%x != %x)\n", seg->start+off, P->R[15] - 4, bits, (seg->shadow[off>>2] & bits));
+		bits = seg->shadow[off>>2] >> 2*(off&3);
+		if((bits&3) != chk){
+			if(chk&MARKALLOC)
+				print("%d: access outside alloc: %#x at PC %#x\n",
+					P->pid, seg->start+off, P->R[15] - 4);
+			if(chk&MARKINIT)
+				print("%d: invalid read: %#x at PC %#x\n", 
+					P->pid, seg->start+off, P->R[15] - 4);
 			rendezvous(&never, nil);
 			exits("bad access");
 		}