diff options
author | sotech117 <michael_foiani@brown.edu> | 2024-05-14 03:19:46 +0000 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2024-05-14 03:19:46 +0000 |
commit | 06d50155ac0bd079bfca0f5728346d8beeb205f2 (patch) | |
tree | 2f20c8ba099304d6ea06fb76e8a0807b8afa5a5f /kernel/proc | |
parent | 7585cb5ad84babe9db8c6595de464e33fb878f0c (diff) |
weenix fixes
Diffstat (limited to 'kernel/proc')
-rw-r--r-- | kernel/proc/fork.c | 50 | ||||
-rw-r--r-- | kernel/proc/proc.c | 20 |
2 files changed, 24 insertions, 46 deletions
diff --git a/kernel/proc/fork.c b/kernel/proc/fork.c index cbf5e30..b501b1e 100644 --- a/kernel/proc/fork.c +++ b/kernel/proc/fork.c @@ -60,7 +60,7 @@ long do_fork(struct regs *regs) // NOT_YET_IMPLEMENTED("VM: do_fork"); // Create a new process - proc_t *child_proc = proc_create("child from fork"); + proc_t *child_proc = proc_create("cf"); if (child_proc == NULL) { return -ENOMEM; @@ -73,53 +73,17 @@ long do_fork(struct regs *regs) return -ENOMEM; } - // Set the child process's parent to the current process - // child_thread->kt_proc = child_proc; - // list_insert_head(&child_proc->p_threads, &child_thread->kt_plink); - - // Get the new vmmap_t for the child process - // vmmap_t *child_vmmap = vmmap_clone(curproc->p_vmmap); - // if (child_vmmap == NULL) - // { - // kthread_destroy(child_thread); - // proc_destroy(child_proc); - // return -ENOMEM; - // } - - // Set the new vmmap_t for the child process - // child_proc->p_vmmap = child_vmmap; - // // Set the vmmap to the child process - // child_thread->kt_proc = child_proc; - - // Set the working directory of the child process to the current process - // vref(curproc->p_cwd); - // child_proc->p_cwd = curproc->p_cwd; - - // Copy over each file descriptor from the parent to the child - // for (int i = 0; i < NFILES; i++) - // { - // if (curproc->p_files[i] != NULL) - // { - // fref(curproc->p_files[i]); - // child_proc->p_files[i] = curproc->p_files[i]; - // } - // } - // Fix the values of the registers and the rest of the kthread's ctx regs->r_rax = 0; // Set the return value to 0 for the child - child_thread->kt_ctx.c_rsp = fork_setup_stack(regs, child_thread->kt_kstack); // Set the stack pointer for the child + child_thread->kt_ctx.c_rsp = fork_setup_stack(regs, child_thread->kt_ctx.c_kstack); // Set the stack pointer for the child child_thread->kt_ctx.c_rip = (uintptr_t) userland_entry; // Set the instruction pointer to userland_entry // child_thread->kt_ctx.c_rbp = curthr->kt_ctx.c_rbp; // Set the current thread's base pointer to the child's base pointer - child_thread->kt_ctx.c_pml4 = curproc->p_pml4; // Set the current thread's page table to the current proc's + child_thread->kt_ctx.c_pml4 = child_proc->p_pml4; // Set the current thread's page table to the child's page table child_thread->kt_proc = child_proc; // Set the child process to the child thread - // Update the list - list_insert_tail(&child_proc->p_threads, &child_thread->kt_plink); - - - // Update the brks for the child process - // child_proc->p_brk = curproc->p_brk; - // child_proc->p_start_brk = curproc->p_start_brk; + list_insert_head(&child_proc->p_threads, &child_thread->kt_plink); + child_proc->p_brk = curproc->p_brk; // Set the child's break to the parent's break + child_proc->p_start_brk = curproc->p_start_brk; // Set the child's start break to the parent's start break // Unmap the parent's page table and flush the TLB pt_unmap_range(curproc->p_pml4, USER_MEM_LOW, USER_MEM_HIGH); @@ -130,4 +94,4 @@ long do_fork(struct regs *regs) // Return the child's process id to the parent return child_proc->p_pid; -} +}
\ No newline at end of file diff --git a/kernel/proc/proc.c b/kernel/proc/proc.c index f13064a..2ade163 100644 --- a/kernel/proc/proc.c +++ b/kernel/proc/proc.c @@ -223,9 +223,6 @@ proc_t *proc_create(const char *name) proc_initproc = proc; } - proc->p_vmmap = vmmap_clone(curproc->p_vmmap); - curproc->p_vmmap->vmm_proc = proc; - #ifdef __VFS__ // clone and ref the files from curproc for (int fd = 0; fd < NFILES; fd++) @@ -243,6 +240,23 @@ proc_t *proc_create(const char *name) } #endif +#ifdef __VM__ + proc->p_vmmap = vmmap_clone(curproc->p_vmmap); + curproc->p_vmmap->vmm_proc = proc; + + KASSERT(proc->p_vmmap != NULL); //FIXME! + + // copy the table of file descriptors + for (int i = 0; i < NFILES; i++) + { + if (curproc->p_files[i] != NULL) + { + fref(curproc->p_files[i]); + proc->p_files[i] = curproc->p_files[i]; + } + } +#endif + return proc; } |