summaryrefslogtreecommitdiff
path: root/exec.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2010-08-06 11:12:18 -0400
committerRobert Morris <[email protected]>2010-08-06 11:12:18 -0400
commitc4cc10da7ef6d65f0f654445e0af35b8309f16c2 (patch)
tree771c4791115f945fc86ea9eadc350bb22c518535 /exec.c
parent1afc9d3fcaa7c5992659bb8b69f639b746dda2bc (diff)
downloadxv6-labs-c4cc10da7ef6d65f0f654445e0af35b8309f16c2.tar.gz
xv6-labs-c4cc10da7ef6d65f0f654445e0af35b8309f16c2.tar.bz2
xv6-labs-c4cc10da7ef6d65f0f654445e0af35b8309f16c2.zip
fix corner cases in exec of ELF
put an invalid page below the stack have fork() handle invalid pages
Diffstat (limited to 'exec.c')
-rw-r--r--exec.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/exec.c b/exec.c
index 8a92e99..4f11695 100644
--- a/exec.c
+++ b/exec.c
@@ -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);