Support non-zero p_vaddr in first PT_LOAD segment

Before changing mmap() permission to PROT_NONE in alloc_mem_region(),
such libraries once worked with a bug that uses mmap'ed region outside of
memory region allocated by alloc_mem_region().  This possibly incurs
SIGSEGV because it can overwrite memory region of previously loaded
library, but it sometimes worked, depending on loading order.

After PROT_NONE, this caused SIGSEGV earlier during calculation of
si->phdr in load_library(), but this was fixed by:

    75917c84d1  Use mmap to read an ...

Now the behaviour is the same as before applying PROT_NONE in
alloc_mem_region().

This CL fixed the original issue, supporting shared libraries that have
non-zero p_vaddr in first (= with lowest p_vaddr) PT_LOAD segment.

Bug: 6561258
Change-Id: Ib6176dd3e44c4d99a340eb1cbd16fb037586b0bc
This commit is contained in:
Ji-Hwan Lee
2012-05-31 20:20:36 +09:00
parent 31431f454a
commit f186a1819a
2 changed files with 83 additions and 40 deletions

View File

@@ -148,6 +148,10 @@ struct soinfo
Elf32_Addr gnu_relro_start;
unsigned gnu_relro_len;
/* When you read a virtual address from the ELF file, add the load
* address (= "base" field) minus this value (= "load_offset") to get the
* real, corresponding address in the process' address space */
Elf32_Addr load_offset;
};