diff options
| -rw-r--r-- | arch/riscv64/kernel/smp.c | 1 | ||||
| -rw-r--r-- | src/tcb.c | 1 | ||||
| -rw-r--r-- | src/uapi/proc.c | 1 | ||||
| -rw-r--r-- | tests/create/init.c | 41 | ||||
| -rw-r--r-- | tests/create/source.mk | 2 | ||||
| -rw-r--r-- | tests/fork/init.c | 1 |
6 files changed, 45 insertions, 2 deletions
diff --git a/arch/riscv64/kernel/smp.c b/arch/riscv64/kernel/smp.c index 425d3ce..acb5f04 100644 --- a/arch/riscv64/kernel/smp.c +++ b/arch/riscv64/kernel/smp.c @@ -142,7 +142,6 @@ __noreturn void core_bringup(long hartid) alloc_stack(t); /* init is special in that all threads jump to the entrypoint of the * program */ - t->callback = init->callback; t->exec = init->exec; t->cpu_id = cpuid; /** @todo this is pretty hacky, should really be a separate function? */ @@ -149,6 +149,7 @@ struct tcb *create_thread(struct tcb *p) * structure, this works on riscv but in the event that other * systems don't we can easily turn this into a clone_uvmem. */ t->proc.vmem = p->proc.vmem; + t->callback = p->callback; } else { if (!(t->proc.vmem = create_vmem())) { diff --git a/src/uapi/proc.c b/src/uapi/proc.c index b90433f..a99acb5 100644 --- a/src/uapi/proc.c +++ b/src/uapi/proc.c @@ -42,6 +42,7 @@ SYSCALL_DEFINE5(create)(struct tcb *t, sys_arg_t func, * core_bringup() is doing, might separate this out into its own * function? */ alloc_stack(c); + set_thread(c); set_ret5(c, c->tid, d0, d1, d2, d3); set_return(c, func); diff --git a/tests/create/init.c b/tests/create/init.c new file mode 100644 index 0000000..ca38c22 --- /dev/null +++ b/tests/create/init.c @@ -0,0 +1,41 @@ +#include <common/test.h> + +static int data = 0; + +void callback(id_t tid, int d0, int d1, int d2, int d3) +{ + UNUSED(tid); + printf("hello from new thread\n"); + check(d0 == 1, "wrong d0\n"); + check(d1 == 2, "wrond d1\n"); + check(d2 == 3, "wrong d2\n"); + check(d3 == 4, "wrong d3\n"); + check(data == 16, "wrong data\n"); + + printf("returning to old thread\n"); + sys_swap(1); + check(0, "swap to old thread failed\n"); +} + +START(pid, tid, d0, d1, d2, d3) +{ + UNUSED(pid); + UNUSED(tid); + UNUSED(d0); + UNUSED(d1); + UNUSED(d2); + UNUSED(d3); + + printf("setting data to non-zero value\n"); + data = 16; + + printf("creating new thread\n"); + id_t new_thread = sys_create((uintptr_t)callback, 1, 2, 3, 4); + check(new_thread > 0, "create failed\n"); + + printf("swapping to new thread\n"); + enum sys_status r = sys_swap(new_thread); + check(r == OK, "swap to new thread failed\n"); + + ok(); +} diff --git a/tests/create/source.mk b/tests/create/source.mk new file mode 100644 index 0000000..b9f8efe --- /dev/null +++ b/tests/create/source.mk @@ -0,0 +1,2 @@ +DO != ./scripts/gen-prog -n create -p init init.c +DO != ./scripts/gen-simple -n create -p init diff --git a/tests/fork/init.c b/tests/fork/init.c index c64af93..b6cebe7 100644 --- a/tests/fork/init.c +++ b/tests/fork/init.c @@ -9,7 +9,6 @@ START(pid, tid, d0, d1, d2, d3) UNUSED(d2); UNUSED(d3); - /** @todo fork until we run out of memory? */ check(pid == 0, "illegal pid for init\n"); id_t our_id = 0; printf("forking\n"); |
