Don't read() the individual program and section headers, but rather read()
the respective tables at once. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34405 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -538,12 +538,21 @@ ResourceFile::_InitELFXFile(BFile& file, uint64 fileSize)
|
|||||||
resourceOffset = std::max(resourceOffset,
|
resourceOffset = std::max(resourceOffset,
|
||||||
programHeaderTableOffset + programHeaderTableSize);
|
programHeaderTableOffset + programHeaderTableSize);
|
||||||
|
|
||||||
|
// load the program headers into memory
|
||||||
|
uint8* programHeaders = (uint8*)malloc(
|
||||||
|
programHeaderCount * programHeaderSize);
|
||||||
|
if (programHeaders == NULL)
|
||||||
|
throw Exception(B_NO_MEMORY);
|
||||||
|
MemoryDeleter programHeadersDeleter(programHeaders);
|
||||||
|
|
||||||
|
read_exactly(file, programHeaderTableOffset, programHeaders,
|
||||||
|
programHeaderCount * programHeaderSize,
|
||||||
|
"Failed to read ELF program headers.");
|
||||||
|
|
||||||
// iterate through the program headers
|
// iterate through the program headers
|
||||||
for (uint32 i = 0; i < programHeaderCount; i++) {
|
for (uint32 i = 0; i < programHeaderCount; i++) {
|
||||||
uint64 shOffset = programHeaderTableOffset + i * programHeaderSize;
|
ElfProgramHeader& programHeader
|
||||||
ElfProgramHeader programHeader;
|
= *(ElfProgramHeader*)(programHeaders + i * programHeaderSize);
|
||||||
read_exactly(file, shOffset, &programHeader,
|
|
||||||
sizeof(ElfProgramHeader), "Failed to read ELF program header.");
|
|
||||||
|
|
||||||
// get the header values
|
// get the header values
|
||||||
uint32 type = _GetInt(programHeader.p_type);
|
uint32 type = _GetInt(programHeader.p_type);
|
||||||
@@ -587,12 +596,21 @@ ResourceFile::_InitELFXFile(BFile& file, uint64 fileSize)
|
|||||||
resourceOffset = std::max(resourceOffset,
|
resourceOffset = std::max(resourceOffset,
|
||||||
sectionHeaderTableOffset + sectionHeaderTableSize);
|
sectionHeaderTableOffset + sectionHeaderTableSize);
|
||||||
|
|
||||||
|
// load the section headers into memory
|
||||||
|
uint8* sectionHeaders = (uint8*)malloc(
|
||||||
|
sectionHeaderCount * sectionHeaderSize);
|
||||||
|
if (sectionHeaders == NULL)
|
||||||
|
throw Exception(B_NO_MEMORY);
|
||||||
|
MemoryDeleter sectionHeadersDeleter(sectionHeaders);
|
||||||
|
|
||||||
|
read_exactly(file, sectionHeaderTableOffset, sectionHeaders,
|
||||||
|
sectionHeaderCount * sectionHeaderSize,
|
||||||
|
"Failed to read ELF section headers.");
|
||||||
|
|
||||||
// iterate through the section headers
|
// iterate through the section headers
|
||||||
for (uint32 i = 0; i < sectionHeaderCount; i++) {
|
for (uint32 i = 0; i < sectionHeaderCount; i++) {
|
||||||
uint32 shOffset = sectionHeaderTableOffset + i * sectionHeaderSize;
|
ElfSectionHeader& sectionHeader
|
||||||
ElfSectionHeader sectionHeader;
|
= *(ElfSectionHeader*)(sectionHeaders + i * sectionHeaderSize);
|
||||||
read_exactly(file, shOffset, §ionHeader,
|
|
||||||
sizeof(ElfSectionHeader), "Failed to read ELF section header.");
|
|
||||||
|
|
||||||
// get the header values
|
// get the header values
|
||||||
uint32 type = _GetInt(sectionHeader.sh_type);
|
uint32 type = _GetInt(sectionHeader.sh_type);
|
||||||
|
|||||||
Reference in New Issue
Block a user