aboutsummaryrefslogtreecommitdiff
path: root/kernel/proc/kthread.c
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2024-05-13 09:27:24 +0000
committersotech117 <michael_foiani@brown.edu>2024-05-13 09:27:24 +0000
commitf09878f6327426631d9419d825a4e8396e3b9dc4 (patch)
tree009d1f1b1386baf6d07b3b7d9a436590ada14094 /kernel/proc/kthread.c
parent0e2acbe54e5800621692c2f6e9e9590aa369e165 (diff)
weenix
Diffstat (limited to 'kernel/proc/kthread.c')
-rw-r--r--kernel/proc/kthread.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/kernel/proc/kthread.c b/kernel/proc/kthread.c
index d066dac..b614ac3 100644
--- a/kernel/proc/kthread.c
+++ b/kernel/proc/kthread.c
@@ -121,8 +121,42 @@ kthread_t *kthread_create(proc_t *proc, kthread_func_t func, long arg1,
*/
kthread_t *kthread_clone(kthread_t *thr)
{
- NOT_YET_IMPLEMENTED("VM: kthread_clone");
- return NULL;
+ // NOT_YET_IMPLEMENTED("VM: kthread_clone");
+
+ kthread_t *new_thread = slab_obj_alloc(kthread_allocator);
+ if (new_thread == NULL)
+ {
+ 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)
+ {
+ slab_obj_free(kthread_allocator, new_thread);
+ return NULL;
+ }
+ new_thread->kt_kstack = new_thread->kt_ctx.c_kstack;
+ new_thread->kt_ctx.c_kstacksz = DEFAULT_STACK_SIZE;
+
+ // context_setup(&new_thread->kt_ctx, NULL, 0, NULL, new_thread->kt_kstack,
+ // DEFAULT_STACK_SIZE, thr->kt_proc->p_pml4); (done in fork, I hope)
+
+ // 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;
+ // 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_insert_tail(&thr->kt_proc->p_threads, &new_thread->kt_plink); (done in fork)
+
+ return new_thread;
}
/*
@@ -162,7 +196,7 @@ void kthread_cancel(kthread_t *thr, void *retval)
// NOT_YET_IMPLEMENTED("PROCS: kthread_cancel");
KASSERT(thr != curthr);
- // FIXME: ask about the use of check_curthr_cancelled() in syscall_handler()
+ // 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);