From f46e2a31a7a23f2fa71b4b57c2224e901f739271 Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Tue, 14 Jul 2026 22:26:47 +0900 Subject: [PATCH] fix: import upstream relibc fdtbl sync fix --- redox-rt/src/sys.rs | 14 +++++++++++--- src/start.rs | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/redox-rt/src/sys.rs b/redox-rt/src/sys.rs index addcaefef7..672d3d086f 100644 --- a/redox-rt/src/sys.rs +++ b/redox-rt/src/sys.rs @@ -1010,7 +1010,6 @@ impl FdTbl { let mut fdtbl = Self::new(); let files_reader_fd = filetable_fd.as_raw_fd(); let _ = filetable_fd.lseek(0, syscall::flag::SEEK_SET); - fdtbl.set_fd(filetable_fd); fdtbl.resize(Self::DEFAULT_CAPACITY); let mut reader = crate::proc::FileBufReader::from_fd(files_reader_fd); @@ -1019,6 +1018,8 @@ impl FdTbl { // Manually mark the filetable_fd itself as occupied in userspace FILETABLE fdtbl.override_at(files_reader_fd, files_reader_fd)?; + fdtbl.set_fd(filetable_fd); + Ok(fdtbl) } @@ -1110,7 +1111,7 @@ impl FdTbl { fn sync_size(fd: Option<&FdGuardUpper>, new_size: usize, tag: usize) -> Result<()> { if let Some(fd) = fd { - fd.call_wo( + let res = fd.call_wo( &[], CallFlags::empty(), &[ @@ -1118,7 +1119,14 @@ impl FdTbl { tag as u64, new_size as u64, ], - )?; + ); + if let Err(err) = res { + if err.errno == EINVAL { + // Ignore EINVAL, because it means the kernel table is already larger than new_size. + } else { + return Err(err); + } + } } Ok(()) } diff --git a/src/start.rs b/src/start.rs index 52eb9b1f1b..59f8299dff 100644 --- a/src/start.rs +++ b/src/start.rs @@ -198,6 +198,11 @@ pub unsafe extern "C" fn relibc_start_v1( ) }; + #[cfg(target_os = "redox")] + { + redox_rt::TLS_ACTIVATED.store(true, core::sync::atomic::Ordering::Relaxed); + } + // Set up the right allocator... // if any memory rust based memory allocation happen before this step .. we are doomed. alloc_init();