shithub: riscv

Download patch

ref: 37dcb25eee726a6e207963e737e12cc5a95ca398
parent: c4ec69045e40277433a7fdc48c0ff4b19a11fa59
author: cinap_lenrek <[email protected]>
date: Sat Oct 20 15:52:54 EDT 2018

kernel: fix allocb for BLOCKALIGN*2 >= Hdrspc

--- a/sys/src/9/port/allocb.c
+++ b/sys/src/9/port/allocb.c
@@ -19,7 +19,8 @@
 	uintptr addr;
 
 	size += Tlrspc;
-	if((b = mallocz(sizeof(Block)+size+Hdrspc, 0)) == nil)
+	size = ROUND(size, BLOCKALIGN);
+	if((b = mallocz(sizeof(Block)+BLOCKALIGN+Hdrspc+size, 0)) == nil)
 		return nil;
 
 	b->next = nil;
@@ -38,11 +39,8 @@
 	addr &= ~(BLOCKALIGN-1);
 	b->lim = (uchar*)addr;
 
-	/* leave sluff at beginning for added headers */
-	b->rp = b->lim - ROUND(size, BLOCKALIGN);
-	if(b->rp < b->base)
-		panic("_allocb");
-	b->wp = b->rp;
+	/* leave room at beginning for added headers */
+	b->wp = b->rp = b->lim - size;
 
 	return b;
 }