kernel: Add support for exit codes and start preparing for waitpid()

This commit is contained in:
apio 2023-03-23 22:25:56 +01:00
parent 355dd6c32b
commit 41c7e3780d
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 17 additions and 7 deletions

View File

@ -1,7 +1,14 @@
#include "sys/Syscall.h" #include "sys/Syscall.h"
#include "thread/Scheduler.h" #include "thread/Scheduler.h"
Result<u64> sys_exit(Registers*, SyscallArgs) Result<u64> sys_exit(Registers*, SyscallArgs args)
{ {
kernel_exit(); u8 status = (u8)args[0];
Thread* current = Scheduler::current();
current->status = status;
current->state = ThreadState::Exited;
kernel_yield();
} }

View File

@ -19,6 +19,7 @@ enum class ThreadState
Idle, Idle,
Runnable, Runnable,
Sleeping, Sleeping,
Exited,
Dying Dying
}; };
@ -64,6 +65,8 @@ struct Thread : public LinkedListNode<Thread>
bool is_kernel { true }; bool is_kernel { true };
u8 status { 0 };
PageDirectory* directory; PageDirectory* directory;
bool is_idle() bool is_idle()

View File

@ -95,10 +95,10 @@ extern "C"
void srand(int); void srand(int);
/* Exit the program normally, performing any registered cleanup actions. */ /* Exit the program normally, performing any registered cleanup actions. */
__noreturn void exit(int); __noreturn void exit(int status);
/* Exit the program abnormally, without performing any registered cleanup actions. */ /* Exit the program abnormally, without performing any registered cleanup actions. */
__noreturn void _Exit(int); __noreturn void _Exit(int status);
int system(const char*); int system(const char*);

View File

@ -94,13 +94,13 @@ extern "C"
__noreturn void abort() __noreturn void abort()
{ {
syscall(SYS_exit); syscall(SYS_exit, 255);
__builtin_unreachable(); __builtin_unreachable();
} }
__noreturn void _Exit(int) __noreturn void _Exit(int status)
{ {
syscall(SYS_exit); syscall(SYS_exit, status);
__builtin_unreachable(); __builtin_unreachable();
} }