You are not logged in.
Pages: 1
Asking this here is probably a bit of a stretch, but it can't hurt to try.
Does anybody know how to determine the size of an arbitrary ELF image in memory? In particular, I want to find the size of a dynamic library in memory. I can just iterate through all of the ELF headers obviously, but is there some quicker way?
Offline
Well, I wasn't holding my breath, anyway...
In case anyone's interested, here's the function I've written to do it. Pass in the base address of the dynamic library, and it'll return the size.
#include <link.h> /* ElfW macro, <elf.h> include */
ElfW(Addr) dlsize(ElfW(Ehdr) *ehdr)
{
int i;
ElfW(Phdr) *phdr;
ElfW(Addr) start, end;
/* Find the first program header */
phdr = (ElfW(Phdr)*)((ElfW(Addr))ehdr + ehdr->e_phoff);
/* Find the final PT_LOAD segment's extent */
for (i = 0; i < ehdr->e_phnum; ++i)
if (phdr[i].p_type == PT_LOAD)
end = phdr[i].p_vaddr + phdr[i].p_memsz;
/* The start (virtual) address is always zero, so just return end.*/
return end;
}
Offline
Pages: 1