ref: 46f5db52b9897e656cde27fa21930466d6920354
parent: 014f5bb2e14d89cbbbe2841b6d287a1f7e3ef715
	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
--
⑨