Merge branch 'init-ld-so' into 'master'

Minor ld_so init improvement

See merge request redox-os/relibc!1135
This commit is contained in:
Jeremy Soller
2026-03-28 20:25:05 -06:00
2 changed files with 24 additions and 26 deletions
+20 -24
View File
@@ -312,9 +312,10 @@ fn stage2(
// Setup TCB for ourselves.
unsafe {
#[cfg(target_os = "redox")]
let thr_fd =
crate::platform::get_auxv_raw(sp.auxv().cast(), redox_rt::auxv_defs::AT_REDOX_THR_FD)
.expect_notls("no thread fd present");
let auxv = sp.auxv().cast();
#[cfg(target_os = "redox")]
let thr_fd = crate::platform::get_auxv_raw(auxv, redox_rt::auxv_defs::AT_REDOX_THR_FD)
.expect_notls("no thread fd present");
let tcb = Tcb::new(0).expect_notls("[ld.so]: failed to allocate bootstrap TCB");
tcb.activate(
@@ -327,22 +328,17 @@ fn stage2(
);
#[cfg(target_os = "redox")]
{
let proc_fd = crate::platform::get_auxv_raw(
sp.auxv().cast(),
redox_rt::auxv_defs::AT_REDOX_PROC_FD,
)
.expect_notls("no proc fd present");
let proc_fd =
crate::platform::get_auxv_raw(auxv, redox_rt::auxv_defs::AT_REDOX_PROC_FD)
.expect_notls("no proc fd present");
let ns_fd = crate::platform::get_auxv_raw(
sp.auxv().cast(),
redox_rt::auxv_defs::AT_REDOX_NS_FD,
)
.filter(|&fd| fd != usize::MAX)
.map(|fd| {
redox_rt::proc::FdGuard::new(fd)
.to_upper()
.expect_notls("failed to move ns fd to upper table")
});
let ns_fd = crate::platform::get_auxv_raw(auxv, redox_rt::auxv_defs::AT_REDOX_NS_FD)
.filter(|&fd| fd != usize::MAX)
.map(|fd| {
redox_rt::proc::FdGuard::new(fd)
.to_upper()
.expect_notls("failed to move ns fd to upper table")
});
redox_rt::initialize(
redox_rt::proc::FdGuard::new(proc_fd)
@@ -387,12 +383,6 @@ fn stage2(
// we might need global lock for this kind of stuff
_r_debug.lock().r_ldbase = self_base;
// TODO: Fix memory leak, although minimal.
#[cfg(target_os = "redox")]
unsafe {
crate::platform::init_inner(auxv.clone());
}
let name_or_path = if is_manual {
// ld.so is run directly by user and not via execve() or similar systemcall
println!("argv: {:#?}", argv);
@@ -409,6 +399,12 @@ fn stage2(
argv[0].to_string()
};
// TODO: Fix memory leak, although minimal.
#[cfg(target_os = "redox")]
unsafe {
crate::platform::init_inner(auxv);
}
let (path, _name) = match resolve_path_name(&name_or_path, &envs) {
Some((p, n)) => (p, n),
None => {
+4 -2
View File
@@ -44,10 +44,12 @@ unsafe fn copy_string_array(array: *const *const c_char, len: usize) -> Vec<*mut
use crate::header::string::strlen;
let mut vec = Vec::with_capacity(len + 1);
let mut lengths = Vec::with_capacity(len);
let mut size = 0;
for i in 0..len {
let item = unsafe { *array.add(i) };
size += unsafe { strlen(item) } + 1;
lengths.push(unsafe { strlen(item) } + 1);
size += lengths[i];
}
// Programs unfortunately rely on the strings being contiguous in memory. For example:
@@ -58,7 +60,7 @@ unsafe fn copy_string_array(array: *const *const c_char, len: usize) -> Vec<*mut
for i in 0..len {
let dest_buf = unsafe { buf.add(offset) };
let item = unsafe { *array.add(i) };
let len = unsafe { strlen(item) } + 1;
let len = lengths[i];
unsafe {
ptr::copy_nonoverlapping(item, dest_buf, len);