shithub: front

Download patch

ref: a45630c13680de2884d05ac63105ee78875a4021
parent: 1c69507294bb5f6f4841b96b07b2c4dcc9bfbe28
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Aug 9 10:49:44 EDT 2025

kernel: fix rounding of bss size in exec (broke mntgen on arm64)

We must not round up bss size to pages, as this breaks sbrk()
thinking we are shrinkng the segment on first sbrk() call.

--- a/sys/src/9/port/sysproc.c
+++ b/sys/src/9/port/sysproc.c
@@ -333,7 +333,7 @@
 	char *a, *e, *charp, *file;
 	int i, n, indir;
 	ulong magic, ssize, nargs, nbytes;
-	uintptr entry, text, data, bss, adata, abss, tstk, align;
+	uintptr entry, text, data, bss, adata, abss, ebss, tstk, align;
 	Segment *s, *ts;
 	Image *img;
 	Tos *tos;
@@ -432,8 +432,10 @@
 	data = beswal(u.ehdr.data);
 	bss = beswal(u.ehdr.bss);
 	align = BY2PG-1;
+	
 	abss = (adata + data + align) & ~align;
-	if(adata >= (USTKTOP-USTKSIZE) || abss >= (USTKTOP-USTKSIZE) || (abss+PGROUND(bss)) >= (USTKTOP-USTKSIZE))
+	ebss = (adata + data + bss + align) & ~align;
+	if(adata >= (USTKTOP-USTKSIZE) || abss >= (USTKTOP-USTKSIZE) || ebss >= (USTKTOP-USTKSIZE))
 		error(Ebadexec);
 
 	/*
@@ -616,7 +618,7 @@
 	up->seg[DSEG] = s;
 
 	/* BSS. Zero fill on demand */
-	up->seg[BSEG] = newseg(SG_BSS, abss, PGROUND(bss)>>PGSHIFT);
+	up->seg[BSEG] = newseg(SG_BSS, abss, (ebss - abss)>>PGSHIFT);
 
 	/*
 	 * Move the stack
--