From fe4c623cb9320226866829317cea8ba0c49e7dbc Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sun, 7 Jul 2024 18:12:55 +0300 Subject: make executable entrypoint universal callback + Effectively means that all executables can be called into, but if an exe doesn't want to deal with anyone else it should just set a flag like `not_really_a_server` or whatever --- arch/riscv64/conf/init | Bin 3960 -> 3960 bytes arch/riscv64/conf/init.c | 16 +++------------- arch/riscv64/conf/initrd | Bin 4608 -> 4608 bytes arch/riscv64/kernel/proc.c | 9 +++++---- include/kmi/syscalls.h | 3 --- include/kmi/uapi.h | 14 -------------- src/proc.c | 5 +---- src/uapi/dispatch.c | 1 - src/uapi/ipc.c | 15 +-------------- src/uapi/proc.c | 3 +++ 10 files changed, 13 insertions(+), 53 deletions(-) diff --git a/arch/riscv64/conf/init b/arch/riscv64/conf/init index 5b06586..5248f8f 100755 Binary files a/arch/riscv64/conf/init and b/arch/riscv64/conf/init differ diff --git a/arch/riscv64/conf/init.c b/arch/riscv64/conf/init.c index c61848e..c3e8334 100644 --- a/arch/riscv64/conf/init.c +++ b/arch/riscv64/conf/init.c @@ -178,14 +178,6 @@ static uint64_t sys_swap(long tid) return 0; } -static void sys_ipc_server(void *f) -{ - struct sys_ret r = ecall2(SYS_IPC_SERVER, (long)f); - - if (r.s != 0) - print_value("ipc_server() failed with error ", r.s); -} - static inline struct sys_ret sys_ipc_req(sys_arg_t pid, sys_arg_t d0, sys_arg_t d1, sys_arg_t d2, @@ -381,14 +373,12 @@ static void handle_kernel(long a0, long a1, long d0, long d1, long d2, long d3) sys_poweroff(0); } -void _start(long a0, long a1, long d0, long d1, long d2, long d3) +void _start(long pid, long tid, long d0, long d1, long d2, long d3) { - if (a0 == 0) - handle_kernel(a0, a1, d0, d1, d2, d3); + if (pid == 0) + handle_kernel(pid, tid, d0, d1, d2, d3); /* otherwise, implement test functionality */ - long pid = a0; - long tid = a1; if (d0 == 1) { void *cbuf = 0; rw_buf = sys_req_sharedmem(pid, rw_buf_size, &cbuf); diff --git a/arch/riscv64/conf/initrd b/arch/riscv64/conf/initrd index a792456..bc0858e 100644 Binary files a/arch/riscv64/conf/initrd and b/arch/riscv64/conf/initrd differ diff --git a/arch/riscv64/kernel/proc.c b/arch/riscv64/kernel/proc.c index 4310378..413c078 100644 --- a/arch/riscv64/kernel/proc.c +++ b/arch/riscv64/kernel/proc.c @@ -31,15 +31,16 @@ void run_init(struct tcb *t, vm_t fdt, vm_t initrd) bkl_unlock(); __asm__ volatile ("mv sp, %0\n" "li a0, %1\n" - "li a1, %2\n" - "mv a2, %3\n" + "mv a1, %2\n" + "li a2, %3\n" "mv a3, %4\n" "mv a4, %5\n" + "li a5, %6\n" "sret\n" : : "r" (stack_top), - "K" (0), "K" (SYS_USER_BOOTED), - "r" (t->tid), "r" (fdt), "r" (initrd) + "K" (0), "r" (t->tid), "K" (SYS_USER_BOOTED), + "r" (fdt), "r" (initrd), "K" (1) : "memory"); /* we should never reach this */ unreachable(); diff --git a/include/kmi/syscalls.h b/include/kmi/syscalls.h index 93b99a3..0826a6b 100644 --- a/include/kmi/syscalls.h +++ b/include/kmi/syscalls.h @@ -83,9 +83,6 @@ enum sys_code { /** @name IPC. */ /** @{ */ - /** Inform kernel that process should be treated as server. */ - SYS_IPC_SERVER, - /** Send IPC request as client. */ SYS_IPC_REQ, /* IPC request to server */ diff --git a/include/kmi/uapi.h b/include/kmi/uapi.h index 87b1895..53ae9cb 100644 --- a/include/kmi/uapi.h +++ b/include/kmi/uapi.h @@ -459,20 +459,6 @@ SYSCALL_DECLARE1(free_timer, cid); /** @name IPC syscalls. */ /** @{ */ -/** - * Report process status as server syscall. - * - * @param t Current tcb. - * @param callback Callback to request handler. - * @param b Unused. - * @param c Unused. - * @param d Unused. - * @param e Unused. - * - * Returns \ref OK. - */ -SYSCALL_DECLARE1(ipc_server, callback); - /** * Request syscall. * diff --git a/src/proc.c b/src/proc.c index eaa25d8..09dcc5f 100644 --- a/src/proc.c +++ b/src/proc.c @@ -24,6 +24,7 @@ stat_t prepare_proc(struct tcb *t, vm_t bin, vm_t interp) if (!entry) return ERR_INVAL; + t->callback = entry; alloc_stack(t); set_thread(t); set_return(t, entry); @@ -61,10 +62,6 @@ stat_t init_proc(void *fdt, vm_t *proc_fdt, vm_t *proc_initrd) stat_t ret = prepare_proc(t, get_init_base(fdt), 0); assert(ret == OK); - /** In the init process, can the entry be the callback? Is that too - * unergonomic? */ - t->callback = t->exec; - /** \todo start one thread per core, with special handling for init in * that each thread starts at the entry point of init? */ diff --git a/src/uapi/dispatch.c b/src/uapi/dispatch.c index b5dbda2..16a17d2 100644 --- a/src/uapi/dispatch.c +++ b/src/uapi/dispatch.c @@ -60,7 +60,6 @@ void handle_syscall(sys_arg_t syscall, sys_arg_t a, sys_arg_t b, break; case SYS_REQ_REL_TIMER: sys_req_rel_timer(t, a, b, c, d, e); break; case SYS_REQ_ABS_TIMER: sys_req_abs_timer(t, a, b, c, d, e); break; - case SYS_IPC_SERVER: sys_ipc_server(t, a, b, c, d, e); break; case SYS_IPC_REQ: sys_ipc_req(t, a, b, c, d, e); break; case SYS_IPC_FWD: sys_ipc_fwd(t, a, b, c, d, e); break; case SYS_IPC_KICK: sys_ipc_kick(t, a, b, c, d, e); break; diff --git a/src/uapi/ipc.c b/src/uapi/ipc.c index 613d4a9..3ac4727 100644 --- a/src/uapi/ipc.c +++ b/src/uapi/ipc.c @@ -166,7 +166,7 @@ static __noreturn void __run_notify(struct tcb *t, struct tcb *r) /* signal to whoever is receiving us that we're from the kernel * ("pid 0"), and we are notifying the current thread */ vm_t s = enter_rpc(t, - SYS_RET5(0, code, flags, t->eid, t->tid), + SYS_RET5(0, t->tid, code, flags, t->eid), IPC_REQ); finalize_rpc(t, r, s); @@ -270,19 +270,6 @@ static void leave_rpc(struct tcb *t, struct sys_ret a) use_vmem(t->proc.vmem); } -/** - * IPC server notification syscall handler. - * - * @param t Current tcb. - * @param callback Address of server callback. - * @return \ref OK and \c 0. - */ -SYSCALL_DEFINE1(ipc_server)(struct tcb *t, sys_arg_t callback) -{ - get_cproc(t)->callback = callback; - return_args1(t, OK); -} - /** * Actual IPC syscall handler. * diff --git a/src/uapi/proc.c b/src/uapi/proc.c index ff02113..293a01f 100644 --- a/src/uapi/proc.c +++ b/src/uapi/proc.c @@ -37,6 +37,9 @@ SYSCALL_DEFINE5(create)(struct tcb *t, sys_arg_t func, if (!c) return_args1(t, ERR_OOMEM); + /** @todo there's quite a bit of overlap between this and what + * core_bringup() is doing, might separate this out into its own + * function? */ alloc_stack(c); set_args5(c, c->tid, d0, d1, d2, d3); -- cgit v1.3