From bf2455ea2e39599e78cede8240dd7107917d9653 Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Wed, 15 Jul 2026 22:06:59 +1000 Subject: [PATCH] misc(ld.so): cleanup Signed-off-by: Anhad Singh --- src/ld_so/dso.rs | 10 ++++++---- src/ld_so/linker.rs | 5 ++++- src/ld_so/start.rs | 6 ------ src/start.rs | 6 ++---- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/ld_so/dso.rs b/src/ld_so/dso.rs index 5d4da486da..2a4eb17699 100644 --- a/src/ld_so/dso.rs +++ b/src/ld_so/dso.rs @@ -372,7 +372,7 @@ pub struct DSO { pub pie: bool, /// Whether this DSO *and* its dependencies have been successfully loaded. - pub is_ready: AtomicBool, + is_ready: AtomicBool, /// Is this DSO for ld.so? is_me: bool, @@ -476,7 +476,7 @@ impl DSO { } #[inline] - pub fn mark_ready(&self) { + pub unsafe fn mark_ready(&self) { self.is_ready.store(true, Ordering::SeqCst); } @@ -537,7 +537,7 @@ impl DSO { } } - pub fn run_fini(&self) { + pub unsafe fn run_fini(&self) { for f in self.dynamic.fini_array.iter().rev() { unsafe { f() } } @@ -1266,7 +1266,9 @@ impl Drop for DSO { if self.is_ready.load(Ordering::SeqCst) { // `run_fini` should not be called if we are being prematurely // dropped (e.g. failed to satisfy dependencies). - self.run_fini(); + unsafe { + self.run_fini(); + } } } } diff --git a/src/ld_so/linker.rs b/src/ld_so/linker.rs index ab9727451c..7beca76567 100644 --- a/src/ld_so/linker.rs +++ b/src/ld_so/linker.rs @@ -714,7 +714,10 @@ impl Linker { } for obj in new_objects.into_iter() { - obj.mark_ready(); + // SAFETY: `obj` and its dependencies have been successfuly loaded. + unsafe { + obj.mark_ready(); + } self.run_init(&obj); self.register_object(obj); } diff --git a/src/ld_so/start.rs b/src/ld_so/start.rs index c2ac4cd86f..53f2f532a6 100644 --- a/src/ld_so/start.rs +++ b/src/ld_so/start.rs @@ -41,12 +41,6 @@ use super::{ tcb::Tcb, }; -#[cfg(target_pointer_width = "32")] -pub const SIZEOF_EHDR: usize = 52; - -#[cfg(target_pointer_width = "64")] -pub const SIZEOF_EHDR: usize = 64; - unsafe fn get_argv(mut ptr: *const usize) -> (Vec, *const usize) { //traverse the stack and collect argument vector let mut argv = Vec::new(); diff --git a/src/start.rs b/src/start.rs index 4d82878837..1289cd39ff 100644 --- a/src/start.rs +++ b/src/start.rs @@ -90,8 +90,6 @@ static mut __relibc_init_environ: *mut *mut c_char = ptr::null_mut(); extern "C" fn init_array() { // The thing is that we cannot guarantee if // init_array runs first or if relibc_start runs first - // Still whoever gets to run first must initialize rust - // memory allocator before doing anything else. unsafe { if INIT_COMPLETE { @@ -99,14 +97,14 @@ extern "C" fn init_array() { } } - io_init(); - unsafe { if platform::environ.is_null() { platform::environ = __relibc_init_environ; } } + io_init(); + unsafe { crate::pthread::init(); INIT_COMPLETE = true