Dealloc TCB on detach/join rather than exit.

This commit is contained in:
4lDO2
2026-07-04 13:48:31 +02:00
parent 1ef6fb94e2
commit 0434043c44
3 changed files with 17 additions and 8 deletions
-5
View File
@@ -58,11 +58,6 @@ pub unsafe fn exit_this_thread(stack_base: *mut (), stack_size: usize) -> ! {
// TODO: modify interface so it writes directly to the thread fd?
let status_fd = tcb.thread_fd().dup_into_upper(b"status").unwrap();
let tcb_ptr = unsafe { crate::Tcb::current_ptr() };
if let Some(tcb_ptr) = tcb_ptr {
let _ = unsafe { syscall::funmap(tcb_ptr as usize, syscall::PAGE_SIZE) };
}
let mut buf = [0; size_of::<usize>() * 3];
plain::slice_from_mut_bytes(&mut buf)
.unwrap()
+1
View File
@@ -107,6 +107,7 @@ impl Tcb {
stack_base: core::ptr::null_mut(),
stack_size: 0,
os_tid: UnsafeCell::new(OsTid::default()),
tcb_selfref: UnsafeCell::new(tcb_ptr),
},
dtv_ptr: ptr::null_mut(),
+16 -3
View File
@@ -32,6 +32,8 @@ pub unsafe fn init() {
stack_base: ptr::null_mut(),
stack_size: 0,
tcb_selfref: UnsafeCell::new(core::ptr::null_mut()),
os_tid: UnsafeCell::new(Sys::current_os_tid()),
};
@@ -43,9 +45,11 @@ pub unsafe fn init() {
thread.stack_size = STACK_SIZE;
}
unsafe { Tcb::current() }
.expect_notls("no TCB present for main thread")
.pthread = thread;
let current_tcb = unsafe { Tcb::current() }.expect_notls("no TCB present for main thread");
current_tcb.pthread = thread;
unsafe {
current_tcb.pthread.tcb_selfref.get().write(current_tcb);
}
}
//static NEXT_INDEX: AtomicU32 = AtomicU32::new(FIRST_THREAD_IDX + 1);
@@ -73,6 +77,8 @@ pub struct Pthread {
pub(crate) stack_base: *mut c_void,
pub(crate) stack_size: usize,
pub(crate) tcb_selfref: UnsafeCell<*mut Tcb>,
pub os_tid: UnsafeCell<OsTid>,
}
@@ -317,6 +323,13 @@ unsafe fn dealloc_thread(thread: &Pthread) {
unsafe {
OS_TID_TO_PTHREAD.lock().remove(&thread.os_tid.get().read());
}
#[cfg(target_os = "redox")]
unsafe {
let tcb = thread.tcb_selfref.get().read();
if !tcb.is_null() {
let _ = syscall::funmap(tcb as usize, syscall::PAGE_SIZE);
}
}
}
pub const SIGRT_RLCT_CANCEL: usize = 33;
pub const SIGRT_RLCT_TIMER: usize = 34;