kernel: Add support for exit codes and start preparing for waitpid()
This commit is contained in:
parent
355dd6c32b
commit
41c7e3780d
@ -1,7 +1,14 @@
|
||||
#include "sys/Syscall.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();
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ enum class ThreadState
|
||||
Idle,
|
||||
Runnable,
|
||||
Sleeping,
|
||||
Exited,
|
||||
Dying
|
||||
};
|
||||
|
||||
@ -64,6 +65,8 @@ struct Thread : public LinkedListNode<Thread>
|
||||
|
||||
bool is_kernel { true };
|
||||
|
||||
u8 status { 0 };
|
||||
|
||||
PageDirectory* directory;
|
||||
|
||||
bool is_idle()
|
||||
|
@ -95,10 +95,10 @@ extern "C"
|
||||
void srand(int);
|
||||
|
||||
/* 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. */
|
||||
__noreturn void _Exit(int);
|
||||
__noreturn void _Exit(int status);
|
||||
|
||||
int system(const char*);
|
||||
|
||||
|
@ -94,13 +94,13 @@ extern "C"
|
||||
|
||||
__noreturn void abort()
|
||||
{
|
||||
syscall(SYS_exit);
|
||||
syscall(SYS_exit, 255);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
__noreturn void _Exit(int)
|
||||
__noreturn void _Exit(int status)
|
||||
{
|
||||
syscall(SYS_exit);
|
||||
syscall(SYS_exit, status);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user