[kernel] Remove status code from thread exit

The status code from thread exit had too many issues, (eg, how does it
relate to process exit code? what happens when different threads exit
with different exit codes?) and not enough value, so I'm getting rid of
it.
This commit is contained in:
Justin C. Miller
2022-10-20 21:49:40 -07:00
parent c02aa084d1
commit 194776d226
6 changed files with 21 additions and 33 deletions

View File

@@ -13,9 +13,7 @@ object thread : object {
method kill [destructor cap:kill] method kill [destructor cap:kill]
method exit [static] { method exit [static]
param status int32
}
method sleep [static] { method sleep [static] {
param duration uint64 param duration uint64

View File

@@ -55,7 +55,7 @@ process::exit(int32_t code)
m_return_code = code; m_return_code = code;
for (auto *thread : m_threads) { for (auto *thread : m_threads) {
thread->exit(code); thread->exit();
} }
if (this == current_cpu().process) if (this == current_cpu().process)
@@ -68,21 +68,17 @@ process::update()
kassert(m_threads.count() > 0, "process::update with zero threads!"); kassert(m_threads.count() > 0, "process::update with zero threads!");
size_t i = 0; size_t i = 0;
uint32_t status = 0;
while (i < m_threads.count()) { while (i < m_threads.count()) {
thread *th = m_threads[i]; thread *th = m_threads[i];
if (th->has_state(thread::state::exited)) { if (th->has_state(thread::state::exited)) {
status = th->m_return_code;
m_threads.remove_swap_at(i); m_threads.remove_swap_at(i);
continue; continue;
} }
i++; i++;
} }
if (m_threads.count() == 0) { if (m_threads.count() == 0)
// TODO: What really is the return code in this case? exit(-1);
exit(status);
}
} }
thread * thread *
@@ -106,7 +102,6 @@ bool
process::thread_exited(thread *th) process::thread_exited(thread *th)
{ {
kassert(&th->m_parent == this, "Process got thread_exited for non-child!"); kassert(&th->m_parent == this, "Process got thread_exited for non-child!");
uint32_t status = th->m_return_code;
m_threads.remove_swap(th); m_threads.remove_swap(th);
remove_handle(th->self_handle()); remove_handle(th->self_handle());
delete th; delete th;
@@ -114,7 +109,7 @@ process::thread_exited(thread *th)
// TODO: delete the thread's stack VMA // TODO: delete the thread's stack VMA
if (m_threads.count() == 0) { if (m_threads.count() == 0) {
exit(status); exit(-1);
return true; return true;
} }

View File

@@ -71,11 +71,11 @@ thread::wake_only()
} }
void void
thread::exit(int32_t code) thread::exit()
{ {
m_return_code = code;
m_wake_timeout = 0; m_wake_timeout = 0;
set_state(state::exited); set_state(state::exited);
m_join_queue.clear();
block(); block();
} }

View File

@@ -138,8 +138,7 @@ public:
inline process & parent() { return m_parent; } inline process & parent() { return m_parent; }
/// Terminate this thread. /// Terminate this thread.
/// \arg code The return code to exit with. void exit();
void exit(int32_t code);
/// Add a stack header that returns to the given address in kernel space. /// Add a stack header that returns to the given address in kernel space.
/// \arg rip The address to return to, must be kernel space /// \arg rip The address to return to, must be kernel space
@@ -188,10 +187,6 @@ private:
state m_state; state m_state;
// There should be 3 bytes of padding here
int32_t m_return_code;
uint64_t m_wake_value; uint64_t m_wake_value;
uint64_t m_wake_timeout; uint64_t m_wake_timeout;
message_data m_message_data; message_data m_message_data;

View File

@@ -28,25 +28,25 @@ thread_create(j6_handle_t *self, process *proc, uintptr_t stack_top, uintptr_t e
return j6_status_ok; return j6_status_ok;
} }
j6_status_t
thread_exit(int32_t status)
{
thread &th = thread::current();
log::verbose(logs::task, "Thread %llx exiting with code %d", th.koid(), status);
th.exit(status);
log::error(logs::task, "returned to exit syscall");
return j6_err_unexpected;
}
j6_status_t j6_status_t
thread_kill(thread *self) thread_kill(thread *self)
{ {
log::verbose(logs::task, "Killing thread %llx", self->koid()); log::verbose(logs::task, "Killing thread %llx", self->koid());
self->exit(-1); self->exit();
return j6_status_ok; return j6_status_ok;
} }
j6_status_t
thread_exit()
{
thread &th = thread::current();
log::verbose(logs::task, "Thread %llx exiting", th.koid());
th.exit();
log::error(logs::task, "returned to exit syscall");
return j6_err_unexpected;
}
j6_status_t j6_status_t
thread_sleep(uint64_t duration) thread_sleep(uint64_t duration)
{ {

View File

@@ -83,7 +83,7 @@ channel_pump_loop()
void void
pump_proc() pump_proc()
{ {
j6_thread_exit(channel_pump_loop()); j6_process_exit(channel_pump_loop());
} }
int int