Infer phdr from elf loading address, skip the first page in sys_mmap and update user to musl-enabled biscuit programs

master
Jiajie Chen 6 years ago
parent cca53536d1
commit 2d77b89476

@ -141,7 +141,13 @@ impl Thread {
let mut map = BTreeMap::new();
if let Some(phdr) = elf.program_iter()
.find(|ph| ph.get_type() == Ok(Type::Phdr)) {
// if phdr exists in program header, use it
map.insert(abi::AT_PHDR, phdr.virtual_addr() as usize);
} else if let Some(elf_addr) = elf.program_iter().find(|ph| ph.get_type() == Ok(Type::Load) && ph.offset() == 0) {
// otherwise, check if elf is loaded from the beginning, then phdr can be inferred.
map.insert(abi::AT_PHDR, elf_addr.virtual_addr() as usize + elf.header.pt2.ph_offset() as usize);
} else {
debug!("new_user: no phdr found, tls might not work");
}
map.insert(abi::AT_PHENT, elf.header.pt2.ph_entry_size() as usize);
map.insert(abi::AT_PHNUM, elf.header.pt2.ph_count() as usize);

@ -1,5 +1,6 @@
use rcore_memory::memory_set::handler::Delay;
use rcore_memory::memory_set::MemoryAttr;
use rcore_memory::PAGE_SIZE;
use crate::memory::GlobalFrameAlloc;
@ -11,6 +12,12 @@ pub fn sys_mmap(mut addr: usize, len: usize, prot: usize, flags: usize, fd: i32,
info!("mmap addr={:#x}, size={:#x}, prot={:?}, flags={:?}, fd={}, offset={:#x}", addr, len, prot, flags, fd, offset);
let mut proc = process();
if addr == 0 {
// although NULL can be a valid address
// but in C, NULL is regarded as allocation failure
// so just skip it
addr = PAGE_SIZE;
}
addr = proc.memory_set.find_free_area(addr, len);
if flags.contains(MmapFlags::ANONYMOUS) {

@ -1 +1 @@
Subproject commit fb9a1d5f7014b3be4f4a234bcaecd069335a216c
Subproject commit 93bac1ce10eae9aa541b64e955316b325f8dc9cb
Loading…
Cancel
Save