Skip to content
Snippets Groups Projects
Verified Commit 2a68c68d authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Use the same Stack struct for ld_so start as for relibc start

parent a72c5f4a
No related branches found
No related tags found
No related merge requests found
Pipeline #4972 failed
...@@ -4,14 +4,9 @@ use c_str::CStr; ...@@ -4,14 +4,9 @@ use c_str::CStr;
use header::unistd; use header::unistd;
use platform::types::c_char; use platform::types::c_char;
use crate::start::Stack;
use super::linker::Linker; use super::linker::Linker;
#[repr(C)]
pub struct Stack {
argc: isize,
argv0: *const c_char,
}
#[no_mangle] #[no_mangle]
pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize { pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize {
if sp.argc < 2 { if sp.argc < 2 {
...@@ -26,7 +21,7 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize { ...@@ -26,7 +21,7 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize {
// Pop the first argument (path to ld_so), and get the path of the program // Pop the first argument (path to ld_so), and get the path of the program
let path_c = unsafe { let path_c = unsafe {
let mut argv = &mut sp.argv0 as *mut *const c_char as *mut usize; let mut argv = sp.argv() as *mut usize;
// Move arguments // Move arguments
loop { loop {
......
...@@ -8,21 +8,27 @@ use platform::{Pal, Sys}; ...@@ -8,21 +8,27 @@ use platform::{Pal, Sys};
#[repr(C)] #[repr(C)]
pub struct Stack { pub struct Stack {
argc: isize, pub argc: isize,
argv0: *const c_char, pub argv0: *const c_char,
} }
impl Stack { impl Stack {
fn argc(&self) -> isize { pub fn argv(&self) -> *const *const c_char {
self.argc &self.argv0 as *const _
} }
fn argv(&self) -> *const *const c_char { pub fn envp(&self) -> *const *const c_char {
&self.argv0 as *const _ unsafe { self.argv().offset(self.argc + 1) }
} }
fn envp(&self) -> *const *const c_char { pub fn auxv(&self) -> *const (usize, usize) {
unsafe { self.argv().offset(self.argc() + 1) } unsafe {
let mut envp = self.envp();
while !(*envp).is_null() {
envp = envp.add(1);
}
envp.add(1) as *const (usize, usize)
}
} }
} }
...@@ -72,7 +78,7 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! { ...@@ -72,7 +78,7 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
relibc_verify_host(); relibc_verify_host();
// Set up argc and argv // Set up argc and argv
let argc = sp.argc(); let argc = sp.argc;
let argv = sp.argv(); let argv = sp.argv();
platform::inner_argv = copy_string_array(argv, argc as usize); platform::inner_argv = copy_string_array(argv, argc as usize);
platform::argv = platform::inner_argv.as_mut_ptr(); platform::argv = platform::inner_argv.as_mut_ptr();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment