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

10
proc.c
View file

@ -145,7 +145,7 @@ growproc(int n)
if (!allocuvm(proc->pgdir, (char *)proc->sz, n))
return -1;
proc->sz += n;
loadvm(proc);
switchuvm(proc);
return 0;
}
@ -214,9 +214,10 @@ scheduler(void)
// to release ptable.lock and then reacquire it
// before jumping back to us.
proc = p;
loadvm(p);
switchuvm(p);
p->state = RUNNING;
swtch(&cpu->scheduler, proc->context);
switchkvm();
// Process is done running for now.
// It should have changed its p->state before coming back.
@ -242,7 +243,6 @@ sched(void)
panic("sched running");
if(readeflags()&FL_IF)
panic("sched interruptible");
lcr3(PADDR(kpgdir)); // Switch to the kernel page table
intena = cpu->intena;
swtch(&proc->context, cpu->scheduler);
cpu->intena = intena;
@ -414,8 +414,8 @@ wait(void)
// Found one.
pid = p->pid;
kfree(p->kstack, KSTACKSIZE);
p->kstack = 0;
freevm(p->pgdir);
p->kstack = 0;
freevm(p->pgdir);
p->state = UNUSED;
p->pid = 0;
p->parent = 0;