Merge pull request #325 from artart78/master

Load ELFs at the correct place
This commit is contained in:
Henrik Rydgård 2013-01-04 14:40:23 -08:00
commit 796f1111d3

View File

@ -201,10 +201,21 @@ bool ElfReader::LoadInto(u32 loadAddress)
}
}
u32 totalSize = totalEnd - totalStart;
if (loadAddress)
vaddr = userMemory.AllocAt(loadAddress, totalSize, "ELF");
if (!bRelocate)
{
// Binary is prerelocated, load it where the first segment starts
vaddr = userMemory.AllocAt(totalStart, totalSize, "ELF");
}
else if (loadAddress)
{
// Binary needs to be relocated: add loadAddress to the binary start address
vaddr = userMemory.AllocAt(loadAddress + totalStart, totalSize, "ELF");
}
else
{
// Just put it where there is room
vaddr = userMemory.Alloc(totalSize, false, "ELF");
}
if (vaddr == -1) {
ERROR_LOG(LOADER, "Failed to allocate memory for ELF!");