- Timestamp:
- Jul 30, 2020 9:05:37 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/ldr/ldrELFRelocatable.cpp.h
r85525 r85540 1362 1362 1363 1363 /** 1364 * Helper that locates the first allocated section. 1364 * Locate the next allocated section by RVA (sh_addr). 1365 * 1366 * This is a helper for EnumSegments and SegOffsetToRva. 1365 1367 * 1366 1368 * @returns Pointer to the section header if found, NULL if none. 1367 * @param p Shdr The section header to start searching at.1368 * @param cLeft The number of section headers left to search. Can be 0.1369 * @param pModElf The module instance. 1370 * @param iShdrCur The current section header. 1369 1371 */ 1370 static const Elf_Shdr *RTLDRELF_NAME(GetFirstAllocatedSection)(const Elf_Shdr *pShdr, unsigned cLeft) 1371 { 1372 while (cLeft-- > 0) 1373 { 1374 if (pShdr->sh_flags & SHF_ALLOC) 1375 return pShdr; 1376 pShdr++; 1377 } 1378 return NULL; 1379 } 1380 1381 /** 1382 * Helper that locates the next allocated section logically by RVA (sh_addr). 1383 * 1384 * @returns Pointer to the section header if found, NULL if none. 1385 * @param pModElf The module instance. 1386 * @param iCur The current section header. 1387 */ 1388 static const Elf_Shdr *RTLDRELF_NAME(GetNextAllocatedSection)(PRTLDRMODELF pModElf, unsigned iCur) 1372 static const Elf_Shdr *RTLDRELF_NAME(GetNextAllocatedSection)(PRTLDRMODELF pModElf, unsigned iShdrCur) 1389 1373 { 1390 1374 unsigned const cShdrs = pModElf->Ehdr.e_shnum; … … 1392 1376 if (pModElf->fShdrInOrder) 1393 1377 { 1394 for ( ; iCur < cShdrs; iCur++)1395 if (paShdrs[i Cur].sh_flags & SHF_ALLOC)1396 return &paShdrs[i Cur];1378 for (unsigned iShdr = iShdrCur + 1; iShdr < cShdrs; iShdr++) 1379 if (paShdrs[iShdr].sh_flags & SHF_ALLOC) 1380 return &paShdrs[iShdr]; 1397 1381 } 1398 1382 else 1399 1383 { 1400 Elf_Addr const uEndCur = paShdrs[i Cur].sh_addr + paShdrs[iCur].sh_size;1384 Elf_Addr const uEndCur = paShdrs[iShdrCur].sh_addr + paShdrs[iShdrCur].sh_size; 1401 1385 Elf_Addr offBest = ~(Elf_Addr)0; 1402 1386 unsigned iBest = cShdrs; 1403 for ( iCur = pModElf->iFirstSect; iCur < cShdrs; iCur++)1404 if ( paShdrs[iCur].sh_flags & SHF_ALLOC)1405 { 1406 Elf_Addr const offDelta = paShdrs[i Cur].sh_addr - uEndCur;1387 for (unsigned iShdr = pModElf->iFirstSect; iShdr < cShdrs; iShdr++) 1388 if ((paShdrs[iShdr].sh_flags & SHF_ALLOC) && iShdr != iShdrCur) 1389 { 1390 Elf_Addr const offDelta = paShdrs[iShdr].sh_addr - uEndCur; 1407 1391 if ( offDelta < offBest 1408 && paShdrs[i Cur].sh_addr >= uEndCur)1392 && paShdrs[iShdr].sh_addr >= uEndCur) 1409 1393 { 1410 1394 offBest = offDelta; 1411 iBest = iCur;1395 iBest = iShdr; 1412 1396 } 1413 1397 } … … 1417 1401 return NULL; 1418 1402 } 1403 1419 1404 1420 1405 /** @copydoc RTLDROPS::pfnEnumSegments. */ … … 1563 1548 if (offSeg > pModElf->paShdrs[iSeg].sh_size) 1564 1549 { 1565 const Elf_Shdr *pShdr2 = RTLDRELF_NAME(GetFirstAllocatedSection)(&pModElf->paShdrs[iSeg + 1], 1566 pModElf->Ehdr.e_shnum - iSeg - 1); 1550 const Elf_Shdr *pShdr2 = RTLDRELF_NAME(GetNextAllocatedSection)(pModElf, iSeg); 1567 1551 if ( !pShdr2 1568 1552 || offSeg > (pShdr2->sh_addr - pModElf->paShdrs[iSeg].sh_addr))
Note:
See TracChangeset
for help on using the changeset viewer.