From 53b54f664ed2b4630c23cacc9e216a6a5935b57f Mon Sep 17 00:00:00 2001 From: Michael Foiani Date: Tue, 14 May 2024 17:16:42 -0400 Subject: fixes to work on dept machine --- kernel/proc/kthread.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'kernel/proc/kthread.c') 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); } -- cgit v1.2.3-70-g09d2