From 4cb66441812d8ff926948636fb5c7cbe96d0498a Mon Sep 17 00:00:00 2001
From: 4lDO2 <4lDO2@protonmail.com>
Date: Mon, 15 Jul 2024 14:01:09 +0200
Subject: [PATCH] Implement exit_this_thread on Redox.

---
 redox-rt/src/thread.rs    | 8 ++++++++
 src/platform/redox/mod.rs | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/redox-rt/src/thread.rs b/redox-rt/src/thread.rs
index a63edeaf..19b3efc6 100644
--- a/redox-rt/src/thread.rs
+++ b/redox-rt/src/thread.rs
@@ -47,3 +47,11 @@ pub unsafe fn rlct_clone_impl(stack: *mut usize) -> Result<FdGuard> {
 
     Ok(new_thr_fd)
 }
+
+pub fn exit_this_thread() -> ! {
+    let thread_fd = RtTcb::current().thread_fd();
+    // TODO: modify interface so it writes directly to the thread fd?
+    let status_fd = syscall::dup(**thread_fd, b"status").unwrap();
+    syscall::write(status_fd, &0_usize.to_ne_bytes()).unwrap();
+    unreachable!()
+}
diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs
index 81b0d334..0729cc98 100644
--- a/src/platform/redox/mod.rs
+++ b/src/platform/redox/mod.rs
@@ -1138,6 +1138,6 @@ impl Pal for Sys {
     }
 
     fn exit_thread() -> ! {
-        Self::exit(0)
+        redox_rt::thread::exit_this_thread()
     }
 }
-- 
GitLab