From 87ef210759a6e127c58f0b8c2cab6abb65b0adac Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 17 Oct 2022 19:55:01 +0200 Subject: [PATCH] Kernel, libc: Remove spawn() Now, fork() and exec() are both implemented. More POSIX-y, thus spawn can be removed. --- kernel/include/sys/Syscall.h | 6 ++---- kernel/src/sys/Syscall.cpp | 1 - kernel/src/sys/exec.cpp | 22 ---------------------- libs/libc/include/luna.h | 3 --- libs/libc/include/luna/syscall.h | 5 ++--- libs/libc/src/luna.cpp | 5 ----- libs/libc/src/unistd.cpp | 1 - 7 files changed, 4 insertions(+), 39 deletions(-) diff --git a/kernel/include/sys/Syscall.h b/kernel/include/sys/Syscall.h index 618f1f17..6974dcb9 100644 --- a/kernel/include/sys/Syscall.h +++ b/kernel/include/sys/Syscall.h @@ -18,9 +18,8 @@ #define SYS_fcntl 13 #define SYS_mprotect 14 #define SYS_clock 15 -#define SYS_spawn 16 -#define SYS_mkdir 17 -#define SYS_fork 18 +#define SYS_mkdir 16 +#define SYS_fork 17 namespace Syscall { @@ -45,6 +44,5 @@ void sys_exec(Context* context, const char* pathname); void sys_fcntl(Context* context, int fd, int command, uintptr_t arg); void sys_mprotect(Context* context, void* address, size_t size, int prot); void sys_clock(Context* context); -void sys_spawn(Context* context, const char* pathname); void sys_mkdir(Context* context, const char* filename); void sys_fork(Context* context); \ No newline at end of file diff --git a/kernel/src/sys/Syscall.cpp b/kernel/src/sys/Syscall.cpp index 1aad8b1d..eba6416d 100644 --- a/kernel/src/sys/Syscall.cpp +++ b/kernel/src/sys/Syscall.cpp @@ -28,7 +28,6 @@ void Syscall::entry(Context* context) case SYS_mprotect: sys_mprotect(context, (void*)context->rdi, context->rsi, (int)context->rdx); break; case SYS_clock: sys_clock(context); break; case SYS_mkdir: sys_mkdir(context, (const char*)context->rdi); break; - case SYS_spawn: sys_spawn(context, (const char*)context->rdi); break; case SYS_fork: sys_fork(context); break; default: context->rax = -ENOSYS; break; } diff --git a/kernel/src/sys/exec.cpp b/kernel/src/sys/exec.cpp index b5c4aa36..4f7acfb9 100644 --- a/kernel/src/sys/exec.cpp +++ b/kernel/src/sys/exec.cpp @@ -124,27 +124,5 @@ void sys_exec(Context* context, const char* pathname) kfree(kpathname); - return; -} - -void sys_spawn(Context* context, const char* pathname) -{ - char* kpathname = Syscall::strdup_from_user(pathname); - if (!kpathname) - { - context->rax = -EFAULT; - return; - } - - kinfoln("spawn(): spawning %s", kpathname); - - Task* current_task = Scheduler::current_task(); - - context->rax = Scheduler::load_user_task(kpathname); - - kfree(kpathname); - - VMM::switch_to_user_address_space(current_task->address_space); - return; } \ No newline at end of file diff --git a/libs/libc/include/luna.h b/libs/libc/include/luna.h index 758574af..cfcfafb4 100644 --- a/libs/libc/include/luna.h +++ b/libs/libc/include/luna.h @@ -18,9 +18,6 @@ extern "C" /* Prints a message to standard error and aborts the program. */ __lc_noreturn void __luna_abort(const char* message); - /* Creates a new process from the executable at pathname and returns its PID. */ - pid_t spawn(const char* pathname); - #ifdef __cplusplus } #endif diff --git a/libs/libc/include/luna/syscall.h b/libs/libc/include/luna/syscall.h index dd4a6c10..a15caf98 100644 --- a/libs/libc/include/luna/syscall.h +++ b/libs/libc/include/luna/syscall.h @@ -17,9 +17,8 @@ #define SYS_fcntl 13 #define SYS_mprotect 14 #define SYS_clock 15 -#define SYS_spawn 16 -#define SYS_mkdir 17 -#define SYS_fork 18 +#define SYS_mkdir 16 +#define SYS_fork 17 #ifndef __want_syscalls #ifdef __cplusplus diff --git a/libs/libc/src/luna.cpp b/libs/libc/src/luna.cpp index c8576179..7c7af050 100644 --- a/libs/libc/src/luna.cpp +++ b/libs/libc/src/luna.cpp @@ -22,9 +22,4 @@ extern "C" fputs(message, stderr); abort(); } - - pid_t spawn(const char* pathname) - { - return syscall(SYS_spawn, pathname); - } } \ No newline at end of file diff --git a/libs/libc/src/unistd.cpp b/libs/libc/src/unistd.cpp index 6fe67356..7836038b 100644 --- a/libs/libc/src/unistd.cpp +++ b/libs/libc/src/unistd.cpp @@ -41,7 +41,6 @@ extern "C" case SYS_close: case SYS_exec: case SYS_mkdir: - case SYS_spawn: case SYS_sleep: result = __luna_syscall1(number, va_arg(ap, arg)); break; case SYS_munmap: case SYS_open: {