fix corner cases in exec of ELF

put an invalid page below the stack
have fork() handle invalid pages
This commit is contained in:
Robert Morris 2010-08-06 11:12:18 -04:00
parent 1afc9d3fca
commit c4cc10da7e
8 changed files with 84 additions and 37 deletions

7
exec.c
View file

@ -43,13 +43,16 @@ exec(char *path, char **argv)
goto bad;
if (!allocuvm(pgdir, (char *)ph.va, ph.memsz))
goto bad;
sz += PGROUNDUP(ph.memsz);
if(ph.va + ph.memsz > sz)
sz = ph.va + ph.memsz;
if (!loaduvm(pgdir, (char *)ph.va, ip, ph.offset, ph.filesz))
goto bad;
}
iunlockput(ip);
// Allocate and initialize stack at sz
sz = PGROUNDUP(sz);
sz += PGSIZE; // leave an invalid page
if (!allocuvm(pgdir, (char *)sz, PGSIZE))
goto bad;
mem = uva2ka(pgdir, (char *)sz);
@ -95,7 +98,7 @@ exec(char *path, char **argv)
proc->tf->eip = elf.entry; // main
proc->tf->esp = sp;
loadvm(proc);
switchuvm(proc);
freevm(oldpgdir);