relibc: fix compile errors from stub replacement
- dirent::readdir_r: use copy_nonoverlapping (dirent has flexible array member, doesn't impl Copy) - ld_so/dso.rs: make lazy_relocate pub(crate) so linker can call it
This commit is contained in:
@@ -167,7 +167,7 @@ impl DIR {
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/dirent.h.html>.
|
||||
#[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::<dirent>(),
|
||||
);
|
||||
*result = entry;
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ no_includes = true
|
||||
cpp_compat = true
|
||||
after_includes = """
|
||||
#include <bits/timespec.h> // for timespec
|
||||
#include <bits/locale-t.h> // for locale_t
|
||||
struct sigevent;
|
||||
"""
|
||||
|
||||
|
||||
@@ -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<tm> = mem::MaybeUninit::uninit();
|
||||
static GETDATE_TM: RawCell<mem::MaybeUninit<tm>> = RawCell::new(mem::MaybeUninit::uninit());
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/time.h.html>.
|
||||
#[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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-10
@@ -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::<usize>(), 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user