don't panic if a program frees all its memory with sbrk().

if a program sbrk()'s to a non-page-boundary, don't free that page.
corresponding usertests.
This commit is contained in:
Robert Morris 2019-09-20 11:35:27 -04:00
parent ca30cac702
commit 4de161f973
3 changed files with 45 additions and 4 deletions

View file

@ -232,9 +232,7 @@ growproc(int n)
return -1;
}
} else if(n < 0){
if((sz = uvmdealloc(p->pagetable, sz, sz + n)) == 0) {
return -1;
}
sz = uvmdealloc(p->pagetable, sz, sz + n);
}
p->sz = sz;
return 0;

View file

@ -268,7 +268,10 @@ uvmdealloc(pagetable_t pagetable, uint64 oldsz, uint64 newsz)
{
if(newsz >= oldsz)
return oldsz;
uvmunmap(pagetable, newsz, oldsz - newsz, 1);
uint64 newup = PGROUNDUP(newsz);
uvmunmap(pagetable, newup, oldsz - newup, 1);
return newsz;
}