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
......@@ -4,14 +4,9 @@ use c_str::CStr;
use header::unistd;
use platform::types::c_char;
use crate::start::Stack;
use super::linker::Linker;
#[repr(C)]
pub struct Stack {
argc: isize,
argv0: *const c_char,
}
#[no_mangle]
pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack) -> usize {
if sp.argc < 2 {
......@@ -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
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
loop {
......
......@@ -8,21 +8,27 @@ use platform::{Pal, Sys};
#[repr(C)]
pub struct Stack {
argc: isize,
argv0: *const c_char,
pub argc: isize,
pub argv0: *const c_char,
}
impl Stack {
fn argc(&self) -> isize {
self.argc
pub fn argv(&self) -> *const *const c_char {
&self.argv0 as *const _
}
fn argv(&self) -> *const *const c_char {
&self.argv0 as *const _
pub fn envp(&self) -> *const *const c_char {
unsafe { self.argv().offset(self.argc + 1) }
}
fn envp(&self) -> *const *const c_char {
unsafe { self.argv().offset(self.argc() + 1) }
pub fn auxv(&self) -> *const (usize, usize) {
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) -> ! {
relibc_verify_host();
// Set up argc and argv
let argc = sp.argc();
let argc = sp.argc;
let argv = sp.argv();
platform::inner_argv = copy_string_array(argv, argc as usize);
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