Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/user_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ fn init_stack(args: &[String], envs: &[String], auxv: &mut [AuxvEntry], sp: usiz
stack.push(padding_null.as_bytes(), &mut data);

stack.push("\0".repeat(stack.get_sp() % 16).as_bytes(), &mut data);
assert!(stack.get_sp() % 16 == 0);

// next things are auxv entries, envp and argv pointers, argc
// auxv entries is 16 bytes each, aligned to 16 bytes
// envp and argv pointers, argc is 8 bytes each, aligned to 8 bytes
let pointers_count = auxv.len() + envs.len() + args.len() + 3;
if pointers_count % 2 != 0 {
stack.push(padding_null.as_bytes(), &mut data);
}

// Push auxiliary vectors
for auxv_entry in auxv.iter_mut() {
if auxv_entry.get_type() == AuxvType::RANDOM {
Expand All @@ -112,6 +120,7 @@ fn init_stack(args: &[String], envs: &[String], auxv: &mut [AuxvEntry], sp: usiz
stack.push_usize_slice(argv_slice.as_slice(), &mut data);
// Push argc
stack.push_usize_slice(&[args.len()], &mut data);
assert!(stack.get_sp() % 16 == 0);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add stack.push("\0".repeat(stack.get_sp() % 16).as_bytes(), &mut data); code here instead of calculating the pointers_count.

data
}

Expand Down
Loading