diff options
author | Michael Foiani <mfoiani@cs.brown.edu> | 2024-05-14 17:16:42 -0400 |
---|---|---|
committer | Michael Foiani <mfoiani@cs.brown.edu> | 2024-05-14 17:16:42 -0400 |
commit | 53b54f664ed2b4630c23cacc9e216a6a5935b57f (patch) | |
tree | f0138f1ed2f8894efa560e0e9721e510883f439b /kernel/proc | |
parent | b90313ddfa4c03f688c6c1cd5ded34aff1bf39c5 (diff) |
fixes to work on dept machine
Diffstat (limited to 'kernel/proc')
-rw-r--r-- | kernel/proc/fork.c | 2 | ||||
-rw-r--r-- | kernel/proc/kthread.c | 28 |
2 files changed, 18 insertions, 12 deletions
diff --git a/kernel/proc/fork.c b/kernel/proc/fork.c index b501b1e..a6436ba 100644 --- a/kernel/proc/fork.c +++ b/kernel/proc/fork.c @@ -75,7 +75,7 @@ long do_fork(struct regs *regs) // 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_ctx.c_kstack); // Set the stack pointer for the child + child_thread->kt_ctx.c_rsp = fork_setup_stack(regs, (void *)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 = child_proc->p_pml4; // Set the current thread's page table to the child's page table diff --git a/kernel/proc/kthread.c b/kernel/proc/kthread.c index 722d932..b837721 100644 --- a/kernel/proc/kthread.c +++ b/kernel/proc/kthread.c @@ -128,30 +128,37 @@ kthread_t *kthread_clone(kthread_t *thr) { return NULL; } - new_thread->kt_state = KT_NO_STATE; // copy the stack - new_thread->kt_ctx.c_kstack = alloc_stack(); - if (new_thread->kt_kstack == NULL) + char * stk = alloc_stack(); + if (stk == NULL) { slab_obj_free(kthread_allocator, new_thread); return NULL; } - new_thread->kt_kstack = new_thread->kt_ctx.c_kstack; + // if not null, set the stack + new_thread->kt_kstack = (char *)stk; new_thread->kt_ctx.c_kstacksz = DEFAULT_STACK_SIZE; - + new_thread->kt_ctx.c_kstack = (uintptr_t)stk; // set the retval, errno, cancelled new_thread->kt_retval = thr->kt_retval; new_thread->kt_errno = thr->kt_errno; new_thread->kt_cancelled = thr->kt_cancelled; - new_thread->kt_preemption_count = 0; new_thread->kt_recent_core = ~0UL; - new_thread->kt_wchan = NULL; + + // null fields + new_thread->kt_wchan = thr->kt_wchan; + new_thread->kt_proc = NULL; + new_thread->kt_ctx.c_rbp = 0; + new_thread->kt_ctx.c_rsp = 0; + new_thread->kt_ctx.c_rip = 0; + new_thread->kt_ctx.c_pml4 = NULL; + new_thread->kt_preemption_count = 0; // freshly initialize the rest of the fields - list_init(&new_thread->kt_mutexes); list_link_init(&new_thread->kt_plink); list_link_init(&new_thread->kt_qlink); + list_init(&new_thread->kt_mutexes); return new_thread; } @@ -194,10 +201,9 @@ void kthread_cancel(kthread_t *thr, void *retval) KASSERT(thr != curthr); // ask about the use of check_curthr_cancelled() in syscall_handler() - int status = (int) retval; dbg(DBG_THR, "Cancelling thread with proc name=%s, id=%d, status=%d\n", - thr->kt_proc->p_name, thr->kt_proc->p_pid, status); - thr->kt_retval = retval; + thr->kt_proc->p_name, thr->kt_proc->p_pid, (int) retval); + thr->kt_retval = (void *)retval; sched_cancel(thr); } |