shithub: 5v

Download patch

ref: 5a514a681e4c2ab86f76509203a0a96d371d51aa
parent: 808dd0b3d75a5c3eadd1da5c1b57bf550dccb30b
author: Ori Bernstein <[email protected]>
date: Tue Aug 29 18:26:43 EDT 2023

chk: fix some locking

--- a/arm.c
+++ b/arm.c
@@ -38,6 +38,8 @@
 	u32int a;
 
 	a = *(u32int*) vaddrnol(P->R[13] + 4 + 4 * n, 4, ARD);
+	if(a == 0)
+		return ~0;
 	return *(ulong*) vaddrnol(a-4, 4, ARD);
 }
 
--- a/chk.c
+++ b/chk.c
@@ -23,7 +23,7 @@
 		print("not tracing\n");
 		return;
 	}
-	for(i = (off&~0x4095)/8; i < (seg->size + 7)/8; i++){
+	for(i = (off&~0x4095)/8; i <= (seg->size + 7)/8; i++){
 		if(i % 40 == 0)
 			p = seprint(p, e, "\n[%04x] ", seg->start+i*8);
 		p = seprint(p, e, "%02ux", seg->shadow[i]);
@@ -93,6 +93,7 @@
 	markinvalid(seg, p - (uchar*)seg->data, av[0]);
 	if(mallocverbose)
 		dumpmap(seg, p-(uchar*)seg->start, "postmalloc");
+	segunlock(seg);
 }
 
 
@@ -102,23 +103,25 @@
 	uchar *oldp, *newp;
 	u32int oldsz, newsz, sz;
 	u32int oldoff, newoff;
-	Segment *seg;
+	Segment *seg0, *seg1;
 
-	oldp = vaddr(av[0], 0, 0, &seg);
-	newp = vaddr(P->R[0], 0, 0, &seg);
+	oldp = vaddr(av[0], 0, 0, &seg0);
+	newp = vaddr(P->R[0], 0, 0, &seg1);
 	oldsz = av[1];
 	newsz = av[2];
-	oldoff = oldp - (uchar*)seg->data;
-	newoff = newp - (uchar*)seg->data;
+	oldoff = oldp - (uchar*)seg0->data;
+	newoff = newp - (uchar*)seg1->data;
 	sz = (oldsz < newsz) ? oldsz : newsz;
 	if(mallocverbose)
-		dumpmap(seg, oldp-(uchar*)seg->start, "realloc %#x+%d => %#x+%d\n", av[0], av[1], P->R[0], av[2]);
+		dumpmap(seg0, oldp-(uchar*)seg0->start, "realloc %#x+%d => %#x+%d\n", av[0], av[1], P->R[0], av[2]);
 	if(oldp != newp)
-		memcpy(seg->shadow+oldoff/8, seg->shadow+newoff/8, (sz+7)/8);
+		memcpy(seg1->shadow+oldoff/8, seg0->shadow+newoff/8, (sz+7)/8);
 	if(newsz > oldsz)
-		markinvalid(seg, oldoff+oldsz, newsz-oldsz);
+		markinvalid(seg0, oldoff+oldsz, newsz-oldsz);
 	if(mallocverbose)
-		dumpmap(seg, newp-(uchar*)seg->start, "postrealloc");
+		dumpmap(seg1, newp-(uchar*)seg1->start, "postrealloc");
+	segunlock(seg0);
+	segunlock(seg1);
 }
 
 void
@@ -133,4 +136,5 @@
 	markinvalid(seg, p - (uchar*)seg->data, av[1]);
 	if(mallocverbose)
 		dumpmap(seg, p-(uchar*)seg->start, "postfree");
+	segunlock(seg);
 }