From 2fa5d9ba56e93dd80b71127025d8467fc1bafff5 Mon Sep 17 00:00:00 2001 From: Blue Swirl Date: Sun, 27 Sep 2009 19:30:51 +0000 Subject: BSD user: implement GUEST_BASE Based on 379f6698d73f476de38682b3ff96ecb226728c43. Signed-off-by: Blue Swirl --- bsd-user/elfload.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'bsd-user/elfload.c') diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 48ec4ac150..06e6c63efb 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -1337,6 +1337,29 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, info->mmap = 0; elf_entry = (abi_ulong) elf_ex.e_entry; +#if defined(CONFIG_USE_GUEST_BASE) + /* + * In case where user has not explicitly set the guest_base, we + * probe here that should we set it automatically. + */ + if (!have_guest_base) { + /* + * Go through ELF program header table and find out whether + * any of the segments drop below our current mmap_min_addr and + * in that case set guest_base to corresponding address. + */ + for (i = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum; + i++, elf_ppnt++) { + if (elf_ppnt->p_type != PT_LOAD) + continue; + if (HOST_PAGE_ALIGN(elf_ppnt->p_vaddr) < mmap_min_addr) { + guest_base = HOST_PAGE_ALIGN(mmap_min_addr); + break; + } + } + } +#endif /* CONFIG_USE_GUEST_BASE */ + /* Do this so that we can load the interpreter, if need be. We will change some of these later */ info->rss = 0; -- cgit v1.2.1