From 531afc3d6f6a2432bc1b04d281c8aa8186d8c476 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 12 Oct 2022 17:45:58 +0200 Subject: [PATCH] libc: Add support for the new exec() system call execv() is a temporary wrapper that ignores the second parameter, while execve() and execvp() still error out. --- kernel/src/sys/Syscall.cpp | 2 +- libs/libc/include/luna/syscall.h | 1 + libs/libc/include/unistd.h | 6 ++++-- libs/libc/src/unistd.cpp | 5 +++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/kernel/src/sys/Syscall.cpp b/kernel/src/sys/Syscall.cpp index 5c3a21e6..8a3434b9 100644 --- a/kernel/src/sys/Syscall.cpp +++ b/kernel/src/sys/Syscall.cpp @@ -21,7 +21,7 @@ void Syscall::entry(Context* context) case SYS_read: sys_read(context, (int)context->rdi, context->rsi, (char*)context->rdx); break; case SYS_close: sys_close(context, (int)context->rdi); break; case SYS_seek: sys_seek(context, (int)context->rdi, (long)context->rsi, (int)context->rdx); break; - case SYS_exec: sys_exec(context, (const char*)context->rdi); + case SYS_exec: sys_exec(context, (const char*)context->rdi); break; default: context->rax = -ENOSYS; break; } } \ No newline at end of file diff --git a/libs/libc/include/luna/syscall.h b/libs/libc/include/luna/syscall.h index 21e3fb47..cc0c24ce 100644 --- a/libs/libc/include/luna/syscall.h +++ b/libs/libc/include/luna/syscall.h @@ -14,6 +14,7 @@ #define SYS_read 10 #define SYS_close 11 #define SYS_seek 12 +#define SYS_exec 13 #ifndef __want_syscalls #ifdef __cplusplus diff --git a/libs/libc/include/unistd.h b/libs/libc/include/unistd.h index 5a029030..871b3646 100644 --- a/libs/libc/include/unistd.h +++ b/libs/libc/include/unistd.h @@ -9,8 +9,10 @@ extern "C" { #endif - /* Not implemented. */ - int execv(const char*, char* const[]); + /* Executes the program program. On success, does not return. The second parameter (arguments) is not implemented + * for now. You can pass NULL to it. */ + int execv(const char* program, char* const[]); + /* Not implemented. */ int execve(const char*, char* const[], char* const[]); /* Not implemented. */ diff --git a/libs/libc/src/unistd.cpp b/libs/libc/src/unistd.cpp index 0cd572f6..8b1da12e 100644 --- a/libs/libc/src/unistd.cpp +++ b/libs/libc/src/unistd.cpp @@ -6,9 +6,9 @@ extern "C" { - int execv(const char*, char* const[]) + int execv(const char* program, char* const[]) { - NOT_IMPLEMENTED("execv"); + return (int)syscall(SYS_exec, program); } int execve(const char*, char* const[], char* const[]) { @@ -36,6 +36,7 @@ extern "C" case SYS_rand: result = __luna_syscall0(number); break; case SYS_exit: case SYS_close: + case SYS_exec: case SYS_sleep: result = __luna_syscall1(number, va_arg(ap, arg)); break; case SYS_munmap: case SYS_open: {