allow sbrk(-x) to de-allocate user memory

This commit is contained in:
Robert Morris 2010-08-10 17:08:41 -04:00
parent c4cc10da7e
commit 83d2db91f7
4 changed files with 89 additions and 4 deletions

9
proc.c
View file

@ -142,8 +142,13 @@ userinit(void)
int
growproc(int n)
{
if (!allocuvm(proc->pgdir, (char *)proc->sz, n))
return -1;
if(n > 0){
if (!allocuvm(proc->pgdir, (char *)proc->sz, n))
return -1;
} else if(n < 0){
if (!deallocuvm(proc->pgdir, (char *)(proc->sz + n), 0 - n))
return -1;
}
proc->sz += n;
switchuvm(proc);
return 0;