提交 e1c40af9 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Fix some bugs in exit() triggered by kernel threads.

Kernel threads might not have a cwd or parent. An alternative to changing exit might be to fill in some dummy values.
上级 2c5891f1
...@@ -107,7 +107,7 @@ forkret(void) ...@@ -107,7 +107,7 @@ forkret(void)
// Just for the first process. can't do it earlier // Just for the first process. can't do it earlier
// b/c file system code needs a process context // b/c file system code needs a process context
// in which to call cv_sleep(). // in which to call cv_sleep().
if(myproc()->cwd == 0) { if(myproc()->cwd == NULL) {
mtstart(forkret, myproc()); mtstart(forkret, myproc());
myproc()->cwd = namei("/"); myproc()->cwd = namei("/");
mtstop(myproc()); mtstop(myproc());
...@@ -137,8 +137,11 @@ exit(void) ...@@ -137,8 +137,11 @@ exit(void)
} }
} }
// Kernel threads might not have a cwd
if (myproc()->cwd != NULL) {
iput(myproc()->cwd); iput(myproc()->cwd);
myproc()->cwd = 0; myproc()->cwd = NULL;
}
// Pass abandoned children to init. // Pass abandoned children to init.
wakeupinit = 0; wakeupinit = 0;
...@@ -157,9 +160,9 @@ exit(void) ...@@ -157,9 +160,9 @@ exit(void)
// Parent might be sleeping in wait(). // Parent might be sleeping in wait().
acquire(&(myproc()->lock)); acquire(&(myproc()->lock));
// Kernel threads might not have a parent
if (myproc()->parent != NULL)
cv_wakeup(&(myproc()->parent->cv)); cv_wakeup(&(myproc()->parent->cv));
if (wakeupinit) if (wakeupinit)
cv_wakeup(&bootproc->cv); cv_wakeup(&bootproc->cv);
...@@ -262,7 +265,7 @@ inituser(void) ...@@ -262,7 +265,7 @@ inituser(void)
p->tf->rip = 0x0; // beginning of initcode.S p->tf->rip = 0x0; // beginning of initcode.S
safestrcpy(p->name, "initcode", sizeof(p->name)); safestrcpy(p->name, "initcode", sizeof(p->name));
p->cwd = 0; // forkret will fix in the process's context p->cwd = NULL; // forkret will fix in the process's context
acquire(&p->lock); acquire(&p->lock);
addrun(p); addrun(p);
p->state = RUNNABLE; p->state = RUNNABLE;
...@@ -677,6 +680,7 @@ threadalloc(void (*fn)(void *), void *arg) ...@@ -677,6 +680,7 @@ threadalloc(void (*fn)(void *), void *arg)
p->context->rip = (u64)threadstub; p->context->rip = (u64)threadstub;
p->context->r12 = (u64)fn; p->context->r12 = (u64)fn;
p->context->r13 = (u64)arg; p->context->r13 = (u64)arg;
p->cwd = 0; p->parent = myproc();
p->cwd = NULL;
return p; return p;
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论