misc(ld.so): cleanup
Signed-off-by: Anhad Singh <andypython@protonmail.com>
This commit is contained in:
+6
-4
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<String>, *const usize) {
|
||||
//traverse the stack and collect argument vector
|
||||
let mut argv = Vec::new();
|
||||
|
||||
+2
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user