Skip to content

PS2 games in the browser: static recompilation to WebAssembly with a native runtime

C++

A thread that returns from its entry function exits as with ExitThread

Dusan Bako2a3ffc56fc7e
diff --git a/runtime/src/kernel.cpp b/runtime/src/kernel.cpp
index 4e5b000..ed6fbed 100644
--- a/runtime/src/kernel.cpp
+++ b/runtime/src/kernel.cpp
@@ -428,7 +428,11 @@ void service(Cpu &c) {
else run_intc(c, static_cast<unsigned>(std::countr_zero(pending)));
}
}
- if (g_reschedule || c.pc == kIdle) reschedule(c);
+ // A thread whose entry function returns lands on kIdle, the ra it was started
+ // with, and the PS2 kernel ends it there the way ExitThread does.
+ const Thread *t = current();
+ if (c.pc == kIdle && t && t->status == kRun) exit_current(c, false);
+ else if (g_reschedule || c.pc == kIdle) reschedule(c);
c.pc &= ~kUnwind;
}