Return error from fork when we run out of stacks.

..running the GC and retrying doesn't usually help free up stacks. The parent thread needs to wait.
上级 b72f261e
...@@ -86,8 +86,6 @@ proc::proc(int npid) : ...@@ -86,8 +86,6 @@ proc::proc(int npid) :
proc::~proc(void) proc::~proc(void)
{ {
magic = 0; magic = 0;
if (kstack)
ksfree(slab_stack, kstack);
destroylock(&lock); destroylock(&lock);
destroycondvar(&cv); destroycondvar(&cv);
} }
...@@ -316,7 +314,7 @@ proc::alloc(void) ...@@ -316,7 +314,7 @@ proc::alloc(void)
p = new proc(xnspid->allockey()); p = new proc(xnspid->allockey());
if (p == nullptr) if (p == nullptr)
return nullptr; throw_bad_alloc();
p->cpuid = mycpu()->id; p->cpuid = mycpu()->id;
initprocgc(p); initprocgc(p);
...@@ -456,7 +454,7 @@ fork(int flags) ...@@ -456,7 +454,7 @@ fork(int flags)
// Allocate process. // Allocate process.
if((np = proc::alloc()) == 0) if((np = proc::alloc()) == 0)
throw_bad_alloc(); return -1;
auto proc_cleanup = scoped_cleanup([&np]() { auto proc_cleanup = scoped_cleanup([&np]() {
if (!xnspid->remove(np->pid, &np)) if (!xnspid->remove(np->pid, &np))
...@@ -522,6 +520,9 @@ finishproc(struct proc *p, bool removepid) ...@@ -522,6 +520,9 @@ finishproc(struct proc *p, bool removepid)
p->pgmap->dec(); p->pgmap->dec();
if (p->uwq != nullptr) if (p->uwq != nullptr)
p->uwq->dec(); p->uwq->dec();
if (p->kstack)
ksfree(slab_stack, p->kstack);
p->pid = 0; p->pid = 0;
p->parent = 0; p->parent = 0;
p->name[0] = 0; p->name[0] = 0;
...@@ -561,8 +562,10 @@ wait(void) ...@@ -561,8 +562,10 @@ wait(void)
w->rip = (void*) finishproc; w->rip = (void*) finishproc;
w->arg0 = p; w->arg0 = p;
w->arg1 = 0; w->arg1 = 0;
assert(wqcrit_push(w, p->run_cpuid_) >= 0); if (wqcrit_push(w, p->run_cpuid_) < 0) {
delete w;
finishproc(p, 0);
}
return pid; return pid;
} }
release(&p->lock); release(&p->lock);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论