diff --git a/redox-rt/src/thread.rs b/redox-rt/src/thread.rs index 84e8978875..5d0c258e7d 100644 --- a/redox-rt/src/thread.rs +++ b/redox-rt/src/thread.rs @@ -1,17 +1,18 @@ use core::mem::size_of; -use syscall::{Result, O_CLOEXEC}; +use syscall::{Error, Result, ESRCH, O_CLOEXEC}; -use crate::{arch::*, proc::*, signal::tmp_disable_signals, RtTcb}; +use crate::{arch::*, proc::*, signal::tmp_disable_signals, static_proc_info, RtTcb}; /// Spawns a new context sharing the same address space as the current one (i.e. a new thread). pub unsafe fn rlct_clone_impl(stack: *mut usize) -> Result { - // FIXME + let cur_proc_fd = static_proc_info() + .proc_fd + .as_ref() + .ok_or(Error::new(ESRCH))?; + let cur_thr_fd = RtTcb::current().thread_fd(); - let new_thr_fd = FdGuard::new(syscall::open( - "/scheme/thisproc/new-thread/open_via_dup", - O_CLOEXEC, - )?); + let new_thr_fd = FdGuard::new(syscall::dup(**cur_proc_fd, b"new-thread")?); copy_str(**cur_thr_fd, *new_thr_fd, "name")?; diff --git a/src/platform/redox/libredox.rs b/src/platform/redox/libredox.rs index d3f8fbc4fc..2324e38afd 100644 --- a/src/platform/redox/libredox.rs +++ b/src/platform/redox/libredox.rs @@ -363,3 +363,9 @@ pub unsafe extern "C" fn redox_mkns_v1( syscall::mkns(core::slice::from_raw_parts(names.cast(), num_names)) })()) } + +// ABI-UNSTABLE +#[no_mangle] +pub unsafe extern "C" fn redox_cur_thrfd_v0() -> usize { + **redox_rt::RtTcb::current().thread_fd() +}