提交 296bdfb1 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

separate flags for fork() to share vmap, filetable

上级 3a2a1212
...@@ -4,3 +4,7 @@ ...@@ -4,3 +4,7 @@
#define O_CREATE 0x200 #define O_CREATE 0x200
#define AT_FDCWD -100 #define AT_FDCWD -100
#define FORK_SHARE_VMAP (1<<0)
#define FORK_SHARE_FD (1<<1)
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "kalloc.hh" #include "kalloc.hh"
#include "vm.hh" #include "vm.hh"
#include "ns.hh" #include "ns.hh"
#include "fcntl.h"
u64 u64
proc_hash(const u32 &p) proc_hash(const u32 &p)
...@@ -344,7 +345,10 @@ fork(int flags) ...@@ -344,7 +345,10 @@ fork(int flags)
if((np = proc::alloc()) == 0) if((np = proc::alloc()) == 0)
return -1; return -1;
if(flags == 0) { if(flags & FORK_SHARE_VMAP) {
np->vmap = myproc()->vmap;
np->vmap->ref++;
} else {
// Copy process state from p. // Copy process state from p.
if((np->vmap = myproc()->vmap->copy(cow)) == 0){ if((np->vmap = myproc()->vmap->copy(cow)) == 0){
ksfree(slab_stack, np->kstack); ksfree(slab_stack, np->kstack);
...@@ -354,9 +358,6 @@ fork(int flags) ...@@ -354,9 +358,6 @@ fork(int flags)
freeproc(np); freeproc(np);
return -1; return -1;
} }
} else {
np->vmap = myproc()->vmap;
np->vmap->ref++;
} }
np->parent = myproc(); np->parent = myproc();
...@@ -366,16 +367,16 @@ fork(int flags) ...@@ -366,16 +367,16 @@ fork(int flags)
// Clear %eax so that fork returns 0 in the child. // Clear %eax so that fork returns 0 in the child.
np->tf->rax = 0; np->tf->rax = 0;
if (flags == 0) { if (flags & FORK_SHARE_FD) {
myproc()->ftable->incref();
np->ftable = myproc()->ftable;
} else {
np->ftable = new filetable(*myproc()->ftable); np->ftable = new filetable(*myproc()->ftable);
if (np->ftable == nullptr) { if (np->ftable == nullptr) {
// XXX(sbw) leaking? // XXX(sbw) leaking?
freeproc(np); freeproc(np);
return -1; return -1;
} }
} else {
myproc()->ftable->incref();
np->ftable = myproc()->ftable;
} }
np->cwd = idup(myproc()->cwd); np->cwd = idup(myproc()->cwd);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论