From 0fed45d1c61f40cd1e5d871bdf17cad95327a8f3 Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 11 Jul 2023 11:49:10 +0200 Subject: [PATCH] libc: Implement _exit() Apparently, I implemented _Exit in stdlib.h but forgot to add _exit to unistd.h... --- libc/include/bits/attrs.h | 3 ++- libc/include/unistd.h | 7 +++++++ libc/src/unistd.cpp | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libc/include/bits/attrs.h b/libc/include/bits/attrs.h index 12e1b0b2..94dad549 100644 --- a/libc/include/bits/attrs.h +++ b/libc/include/bits/attrs.h @@ -3,7 +3,8 @@ #ifndef _BITS_ATTRS_H #define _BITS_ATTRS_H -#if !defined(_STDLIB_H) && !defined(_STRING_H) && !defined(_ASSERT_H) && !defined(_SETJMP_H) && !defined(_SYS_TIME_H) +#if !defined(_STDLIB_H) && !defined(_UNISTD_H) && !defined(_STRING_H) && !defined(_ASSERT_H) && !defined(_SETJMP_H) && \ + !defined(_SYS_TIME_H) #error "Never include bits/attrs.h directly; use one of the standard library headers." #endif diff --git a/libc/include/unistd.h b/libc/include/unistd.h index 7dac09b3..a4c56f14 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -56,6 +57,9 @@ extern "C" /* Set the current process' effective group ID. */ int setegid(gid_t gid); + /* Set the current process or a child process's process group. */ + int setpgid(pid_t pid, pid_t pgid); + /* Change the owner and group of a file. */ int chown(const char* path, uid_t uid, gid_t gid); @@ -86,6 +90,9 @@ extern "C" /* Call the operating system kernel for a specific service. */ long syscall(long num, ...); + /* Exit the process immediately, without performing any cleanup actions. */ + __noreturn void _exit(int status); + /* Sleep for X microseconds. */ int usleep(useconds_t us); diff --git a/libc/src/unistd.cpp b/libc/src/unistd.cpp index 27f334b5..cbf5a826 100644 --- a/libc/src/unistd.cpp +++ b/libc/src/unistd.cpp @@ -246,6 +246,12 @@ extern "C" return rc; } + __noreturn void _exit(int status) + { + syscall(SYS_exit, status); + __builtin_unreachable(); + } + int usleep(useconds_t us) { long rc = syscall(SYS_usleep, us);