Skip to content
Merged
Changes from all commits
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
28 changes: 16 additions & 12 deletions loader/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,24 +502,28 @@ mm_GetLibraryInfo(const void *libPtr, DynLibInfo &lib)
phdrCount = file->e_phnum;
phdr = reinterpret_cast<ElfPHeader *>(baseAddr + file->e_phoff);

lib.memorySize = 0;
size_t minAddr = SIZE_MAX, maxAddr = 0;
for (uint16_t i = 0; i < phdrCount; i++)
{
ElfPHeader &hdr = phdr[i];

/* We only really care about the segment with executable code */
if (hdr.p_type == PT_LOAD && hdr.p_flags == (PF_X|PF_R))
if (hdr.p_type == PT_LOAD)
{
/* From glibc, elf/dl-load.c:
* c->mapend = ((ph->p_vaddr + ph->p_filesz + GLRO(dl_pagesize) - 1)
* & ~(GLRO(dl_pagesize) - 1));
*
* In glibc, the segment file size is aligned up to the nearest page size and
* added to the virtual address of the segment. We just want the size here.
*/
lib.memorySize = PAGE_ALIGN_UP(hdr.p_filesz);
break;
if (hdr.p_vaddr < minAddr)
{
minAddr = hdr.p_vaddr;
}
if ((hdr.p_vaddr + hdr.p_memsz) > maxAddr)
{
maxAddr = hdr.p_vaddr + hdr.p_memsz;
}
}
}
if (minAddr > maxAddr)
{
return false;
}
lib.memorySize = maxAddr - minAddr;
Comment thread
Kenzzer marked this conversation as resolved.

#elif defined __APPLE__

Expand Down
Loading