diff --git a/src/header/dirent/mod.rs b/src/header/dirent/mod.rs index 761980c041..30df2a167e 100644 --- a/src/header/dirent/mod.rs +++ b/src/header/dirent/mod.rs @@ -167,7 +167,7 @@ impl DIR { /// See . #[repr(C)] -#[derive(Clone)] +#[derive(Clone, Copy)] pub struct dirent { pub d_ino: ino_t, pub d_off: off_t, @@ -305,9 +305,15 @@ pub extern "C" fn readdir_r( }; unsafe { - ptr::write(entry, *src); - *result = entry; - } + // Copy the dirent bytes (dirent doesn't impl Copy because it has a + // flexible array member). Use a byte-level copy. + core::ptr::copy_nonoverlapping( + src as *const u8, + entry as *mut u8, + core::mem::size_of::(), + ); + *result = entry; +} 0 } diff --git a/src/header/time/cbindgen.toml b/src/header/time/cbindgen.toml index d2476bd3b3..2aaa2a47df 100644 --- a/src/header/time/cbindgen.toml +++ b/src/header/time/cbindgen.toml @@ -6,6 +6,7 @@ no_includes = true cpp_compat = true after_includes = """ #include // for timespec +#include // for locale_t struct sigevent; """ diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 34774ec004..cfcfedf27b 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -142,7 +142,7 @@ pub static mut tzname: TzName = TzName([ptr::null_mut(); 2]); #[unsafe(no_mangle)] pub static mut getdate_err: c_int = 0; -static mut GETDATE_TM: mem::MaybeUninit = mem::MaybeUninit::uninit(); +static GETDATE_TM: RawCell> = RawCell::new(mem::MaybeUninit::uninit()); /// See . #[repr(C)] @@ -389,11 +389,12 @@ pub unsafe extern "C" fn getdate(string: *const c_char) -> *const tm { if !end.is_null() && unsafe { *end } == 0 { let t = unsafe { mktime(&raw mut parsed) }; if t != -1 { - unsafe { - GETDATE_TM.write(parsed); - getdate_err = 0; - return GETDATE_TM.as_ptr(); - } + unsafe { + let p = GETDATE_TM.as_mut_ptr(); + (*p).write(parsed); + getdate_err = 0; + return (*p).as_ptr(); + } } } } diff --git a/src/ld_so/dso.rs b/src/ld_so/dso.rs index fda351bd94..6638ea93a8 100644 --- a/src/ld_so/dso.rs +++ b/src/ld_so/dso.rs @@ -865,9 +865,7 @@ impl DSO { if self.dlopened { #[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))] { - return Err(object::Error( - "TLSDESC relocations are unsupported on this architecture", - )); + panic!("TLSDESC relocations are unsupported on this architecture"); } let mut tls_index = crate::header::dl_tls::dl_tls_index { @@ -997,16 +995,14 @@ impl DSO { self.do_tlsdesc_reloc(reloc, ptr.cast::(), global_scope) } _ => { - return Err(object::Error( - "unsupported relocation type", - )); + panic!("unsupported relocation type: {:?}", reloc.kind); } } Ok(()) } - fn lazy_relocate(&self, global_scope: &Scope, resolve: Resolve) -> object::Result<()> { + pub(crate) fn lazy_relocate(&self, global_scope: &Scope, resolve: Resolve) -> object::Result<()> { let Some(got) = self.got() else { assert_eq!(self.dynamic.jmprel, 0); return Ok(()); @@ -1075,9 +1071,7 @@ impl DSO { } _ => { - return Err(object::Error( - "unsupported relocation type", - )); + panic!("unsupported relocation type: {:?}", reloc.kind); } } } diff --git a/src/start.rs b/src/start.rs index 753ab1fe15..f2c3107f74 100644 --- a/src/start.rs +++ b/src/start.rs @@ -6,6 +6,9 @@ use core::ptr; #[cfg(target_os = "redox")] use generic_rt::ExpectTlsFree; +#[cfg(target_os = "redox")] +use syscall; + use crate::{ ALLOCATOR, header::{libgen, stdio, stdlib}, @@ -161,11 +164,9 @@ pub unsafe extern "C" fn relibc_start_v1( } // DEBUG: Earliest possible output before any other init - if let Ok(fd) = unsafe { - redox_rt::sys::open("/scheme/debug/no-preserve", redox_rt::sys::O_WRONLY) - } { - let _ = redox_rt::sys::write(fd, b"START: relibc_start_v1 entered\n"); - let _ = redox_rt::sys::close(fd); + if let Ok(fd) = redox_rt::sys::open("/scheme/debug/no-preserve", syscall::O_WRONLY) { + let _ = syscall::write(fd, b"START: relibc_start_v1 entered\n"); + let _ = syscall::close(fd); } // Ensure correct host system before executing more system calls