Kernel: We now store the processes exit code

This commit is contained in:
Bananymous 2023-06-10 17:31:56 +03:00
parent 47c69e9def
commit 4cdeb98897
5 changed files with 9 additions and 8 deletions

View File

@ -122,7 +122,7 @@ namespace IDT
{ {
auto message = BAN::String::formatted("{}, aborting\n", isr_exceptions[isr]); auto message = BAN::String::formatted("{}, aborting\n", isr_exceptions[isr]);
(void)Kernel::Process::current().write(STDERR_FILENO, message.data(), message.size()); (void)Kernel::Process::current().write(STDERR_FILENO, message.data(), message.size());
Kernel::Process::current().exit(); Kernel::Process::current().exit(1);
} }
else else
{ {

View File

@ -40,7 +40,7 @@ namespace Kernel
static BAN::ErrorOr<Process*> create_userspace(BAN::StringView); static BAN::ErrorOr<Process*> create_userspace(BAN::StringView);
~Process(); ~Process();
[[noreturn]] void exit(); [[noreturn]] void exit(int status);
void add_thread(Thread*); void add_thread(Thread*);
void on_thread_exit(Thread&); void on_thread_exit(Thread&);

View File

@ -118,12 +118,13 @@ namespace Kernel
if (m_threads[i] == &thread) if (m_threads[i] == &thread)
m_threads.remove(i); m_threads.remove(i);
if (m_threads.empty()) if (m_threads.empty())
exit(); exit(0);
} }
void Process::exit() void Process::exit(int status)
{ {
m_lock.lock(); m_lock.lock();
m_exit_status.exit_code = status;
m_exit_status.exited = true; m_exit_status.exited = true;
while (m_exit_status.waiting > 0) while (m_exit_status.waiting > 0)
{ {

View File

@ -363,7 +363,7 @@ argument_done:
} }
else if (arguments.front() == "exit") else if (arguments.front() == "exit")
{ {
Process::current().exit(); Process::current().exit(0);
} }
else if (arguments.front() == "time") else if (arguments.front() == "time")
{ {

View File

@ -7,9 +7,9 @@
namespace Kernel namespace Kernel
{ {
void sys_exit() void sys_exit(int status)
{ {
Process::current().exit(); Process::current().exit(status);
} }
long sys_read(int fd, void* buffer, size_t size) long sys_read(int fd, void* buffer, size_t size)
@ -162,7 +162,7 @@ namespace Kernel
switch (syscall) switch (syscall)
{ {
case SYS_EXIT: case SYS_EXIT:
sys_exit(); sys_exit((int)arg1);
break; break;
case SYS_READ: case SYS_READ:
ret = sys_read((int)arg1, (void*)arg2, (size_t)arg3); ret = sys_read((int)arg1, (void*)arg2, (size_t)arg3);