Call kernel_shutdown after last thread calls exit syscall
Currently, kernel_shutdown is only invoked when a thread calls exit_group.
However, kernel_shutdown should also be called if the last remaining thread
in the process calls the exit syscall leaving no more user threads to run.
@@ -2057,12 +2057,6 @@ sysreturn sched_yield()
thread_yield(); /* noreturn */
}
-void exit(int code)
-{
- exit_thread(current);
- syscall_finish(true);
-}
-
sysreturn exit_group(int status)
{
/* Set shutting_down to prevent user threads from being scheduled
@@ -2073,6 +2067,19 @@ sysreturn exit_group(int status)
kernel_shutdown(status);
}
+void exit(int code)
+{
+ process p = current->p;
+ exit_thread(current);
+ spin_lock(&p->threads_lock);
+ int cnt = rbtree_get_count(p->threads);
+ spin_unlock(&p->threads_lock);
+ if (cnt == 0)
+ exit_group(code);
+ else
+ syscall_finish(true);
+}
+
sysreturn pipe2(int fds[2], int flags)
{
if (!validate_user_memory(fds, 2 * sizeof(int), true))
