credit miller@hamnavoe.com from the patch of the same name on sources note: much of this had already been done. we'd missed just one before. In ibrk and segattach there are two different expressions which check for expanding or newly created segments overlapping an existing segment. Neither version was general enough to catch all possible cases. This patch also includes a minimal correction for a bug reported in 9fans by cinap_lenrek on 2014-06-08 (Re: duppage) which can lead to resource starvation & deadlock: duppage() causes the freelist to be shuffled differently. without stuffing cached pages at the freelist tail, the tail accumulates a uncached "stopper" page which breaks the invariant of imagereclaim which just scans from the tail backwards as long as the pages are cached. imagereclaim does not move the pages to the head after uncaching them! so by default imagereclaim prevents the cached pages before the ones it reclaimed from being reclaimed ever. Reference: /n/atom/patch/applied/segment-overlap Date: Mon Jun 20 00:52:11 CES 2016 Signed-off-by: quanstro@quanstro.net --- /sys/src/9/port/segment.c Mon Jun 20 00:51:10 2016 +++ /sys/src/9/port/segment.c Mon Jun 20 00:51:11 2016 @@ -44,7 +44,7 @@ { Image *i, *ie; - imagealloc.free = xalloc(conf.nimage*sizeof(Image)); + imagealloc.free = malloc(conf.nimage*sizeof(Image)); if (imagealloc.free == nil) panic("initseg: no memory"); ie = &imagealloc.free[conf.nimage-1]; @@ -624,7 +624,7 @@ ns = p->seg[i]; if(ns == 0) continue; - if((newtop > ns->base && newtop <= ns->top) || + if((newtop >= ns->base && newtop <= ns->top) || (va >= ns->base && va < ns->top)) return ns; } --- /sys/src/nix/port/segment.c Mon Jun 20 00:51:13 2016 +++ /sys/src/nix/port/segment.c Mon Jun 20 00:51:14 2016 @@ -329,7 +329,7 @@ ns = p->seg[i]; if(ns == 0) continue; - if((newtop > ns->base && newtop <= ns->top) || + if((newtop >= ns->base && newtop <= ns->top) || (va >= ns->base && va < ns->top)) return ns; }