summaryrefslogtreecommitdiff
path: root/src/kernel/proc
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/proc')
-rw-r--r--src/kernel/proc/proc.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/kernel/proc/proc.cc b/src/kernel/proc/proc.cc
index c8b6d1d..f1f1c1d 100644
--- a/src/kernel/proc/proc.cc
+++ b/src/kernel/proc/proc.cc
@@ -8,6 +8,8 @@
#include "kernel/trap.h"
#include "kernel/riscv.h"
#include "drivers/uart.h"
+#include "fs/fs.h"
+#include "fs/file.h"
#include "lib/string.h"
#define NPROC 64
@@ -172,6 +174,9 @@ found:
p->pid = nextpid++;
p->priority = 0;
p->cpu = mycpu();
+ p->cwd = nullptr;
+ for (int i = 0; i < NOFILE; i++)
+ p->ofile[i] = nullptr;
if ((p->tf = (struct Trapframe *)PMM::alloc_page()) == 0)
{
@@ -206,6 +211,19 @@ static void freeproc(struct Proc *p)
p->kstack = 0;
if (p->pagetable)
VM::uvmfree(p->pagetable, p->sz);
+ for (int i = 0; i < NOFILE; i++)
+ {
+ if (p->ofile[i])
+ {
+ FileTable::close(p->ofile[i]);
+ p->ofile[i] = nullptr;
+ }
+ }
+ if (p->cwd)
+ {
+ VFS::iput(p->cwd);
+ p->cwd = nullptr;
+ }
p->pagetable = 0;
p->sz = 0;
p->pid = 0;
@@ -245,6 +263,19 @@ int fork()
np->parent = p;
np->priority = p->priority;
+ for (int i = 0; i < NOFILE; i++)
+ {
+ if (p->ofile[i])
+ {
+ np->ofile[i] = FileTable::dup(p->ofile[i]);
+ }
+ }
+
+ if (p->cwd)
+ {
+ np->cwd = VFS::idup(p->cwd);
+ }
+
proc_mem_lock.release();
struct cpu *c = mycpu();
@@ -394,6 +425,8 @@ namespace ProcManager
p->sz = stack_va + PGSIZE;
strcpy(p->name, "initcode");
+ p->cwd = nullptr;
+
proc_mem_lock.release();
struct cpu *c = &cpus[0];