aboutsummaryrefslogtreecommitdiff
path: root/kernel/proc/kthread.c
diff options
context:
space:
mode:
authorMichael Foiani <mfoiani@cs.brown.edu>2024-05-14 17:16:42 -0400
committerMichael Foiani <mfoiani@cs.brown.edu>2024-05-14 17:16:42 -0400
commit53b54f664ed2b4630c23cacc9e216a6a5935b57f (patch)
treef0138f1ed2f8894efa560e0e9721e510883f439b /kernel/proc/kthread.c
parentb90313ddfa4c03f688c6c1cd5ded34aff1bf39c5 (diff)
fixes to work on dept machine
Diffstat (limited to 'kernel/proc/kthread.c')
-rw-r--r--kernel/proc/kthread.c28
1 files changed, 17 insertions, 11 deletions
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);
}