From 4cdeb988978e80ac30328f37e0aedfbacfe960cf Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sat, 10 Jun 2023 17:31:56 +0300 Subject: [PATCH] Kernel: We now store the processes exit code --- kernel/arch/x86_64/IDT.cpp | 2 +- kernel/include/kernel/Process.h | 2 +- kernel/kernel/Process.cpp | 5 +++-- kernel/kernel/Shell.cpp | 2 +- kernel/kernel/Syscall.cpp | 6 +++--- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/kernel/arch/x86_64/IDT.cpp b/kernel/arch/x86_64/IDT.cpp index 93a6a46918..124febd790 100644 --- a/kernel/arch/x86_64/IDT.cpp +++ b/kernel/arch/x86_64/IDT.cpp @@ -122,7 +122,7 @@ namespace IDT { auto message = BAN::String::formatted("{}, aborting\n", isr_exceptions[isr]); (void)Kernel::Process::current().write(STDERR_FILENO, message.data(), message.size()); - Kernel::Process::current().exit(); + Kernel::Process::current().exit(1); } else { diff --git a/kernel/include/kernel/Process.h b/kernel/include/kernel/Process.h index 74bf406126..6dc28e7bbf 100644 --- a/kernel/include/kernel/Process.h +++ b/kernel/include/kernel/Process.h @@ -40,7 +40,7 @@ namespace Kernel static BAN::ErrorOr create_userspace(BAN::StringView); ~Process(); - [[noreturn]] void exit(); + [[noreturn]] void exit(int status); void add_thread(Thread*); void on_thread_exit(Thread&); diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index b82efb61f2..4ad9465ee0 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -118,12 +118,13 @@ namespace Kernel if (m_threads[i] == &thread) m_threads.remove(i); if (m_threads.empty()) - exit(); + exit(0); } - void Process::exit() + void Process::exit(int status) { m_lock.lock(); + m_exit_status.exit_code = status; m_exit_status.exited = true; while (m_exit_status.waiting > 0) { diff --git a/kernel/kernel/Shell.cpp b/kernel/kernel/Shell.cpp index 5b89ceca8c..4b83611f4b 100644 --- a/kernel/kernel/Shell.cpp +++ b/kernel/kernel/Shell.cpp @@ -363,7 +363,7 @@ argument_done: } else if (arguments.front() == "exit") { - Process::current().exit(); + Process::current().exit(0); } else if (arguments.front() == "time") { diff --git a/kernel/kernel/Syscall.cpp b/kernel/kernel/Syscall.cpp index 51505a42a9..9b2d863012 100644 --- a/kernel/kernel/Syscall.cpp +++ b/kernel/kernel/Syscall.cpp @@ -7,9 +7,9 @@ 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) @@ -162,7 +162,7 @@ namespace Kernel switch (syscall) { case SYS_EXIT: - sys_exit(); + sys_exit((int)arg1); break; case SYS_READ: ret = sys_read((int)arg1, (void*)arg2, (size_t)arg3);