Changeset 103353 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Feb 14, 2024 1:39:13 PM (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/ldr/ldrLX.cpp
r102284 r103353 1379 1379 * Look for codeview signature. 1380 1380 */ 1381 RTCVHDR const *pCvHdr = (RTCVHDR const *)pbBuf; 1382 if ( cbRead > sizeof(*pCvHdr) 1383 && pCvHdr->off >= sizeof(*pCvHdr) 1384 && pCvHdr->off < cbDbgInfo) 1385 { 1386 switch (pCvHdr->u32Magic) 1381 if (cbRead > sizeof(RTCVHDR)) 1382 { 1383 RTCVHDR const *pCvHdr = (RTCVHDR const *)pbBuf; 1384 if ( pCvHdr->off >= sizeof(*pCvHdr) 1385 && pCvHdr->off < cbDbgInfo) 1387 1386 { 1388 case RTCVHDR_MAGIC_NB11: 1389 case RTCVHDR_MAGIC_NB09: 1390 case RTCVHDR_MAGIC_NB08: 1391 case RTCVHDR_MAGIC_NB07: 1392 case RTCVHDR_MAGIC_NB06: 1393 case RTCVHDR_MAGIC_NB05: 1394 case RTCVHDR_MAGIC_NB04: 1395 case RTCVHDR_MAGIC_NB02: 1396 case RTCVHDR_MAGIC_NB01: 1397 case RTCVHDR_MAGIC_NB00: 1398 DbgInfo.enmType = RTLDRDBGINFOTYPE_CODEVIEW; 1399 DbgInfo.iDbgInfo = iDbgInfo; 1400 DbgInfo.offFile = offDbgInfo; 1401 DbgInfo.LinkAddress = NIL_RTLDRADDR; 1402 DbgInfo.cb = cbDbgInfo; 1403 DbgInfo.pszExtFile = NULL; 1404 DbgInfo.u.Cv.cbImage = pModLX->Hdr.e32_mpages * pModLX->Hdr.e32_pagesize; 1405 DbgInfo.u.Cv.uTimestamp = 0; 1406 DbgInfo.u.Cv.uMajorVer = 0; 1407 DbgInfo.u.Cv.uMinorVer = 0; 1408 1409 *pfReturn = true; 1410 return pfnCallback(&pModLX->Core, &DbgInfo, pvUser); 1387 switch (pCvHdr->u32Magic) 1388 { 1389 case RTCVHDR_MAGIC_NB11: 1390 case RTCVHDR_MAGIC_NB09: 1391 case RTCVHDR_MAGIC_NB08: 1392 case RTCVHDR_MAGIC_NB07: 1393 case RTCVHDR_MAGIC_NB06: 1394 case RTCVHDR_MAGIC_NB05: 1395 case RTCVHDR_MAGIC_NB04: 1396 case RTCVHDR_MAGIC_NB02: 1397 case RTCVHDR_MAGIC_NB01: 1398 case RTCVHDR_MAGIC_NB00: 1399 DbgInfo.enmType = RTLDRDBGINFOTYPE_CODEVIEW; 1400 DbgInfo.iDbgInfo = iDbgInfo; 1401 DbgInfo.offFile = offDbgInfo; 1402 DbgInfo.LinkAddress = NIL_RTLDRADDR; 1403 DbgInfo.cb = cbDbgInfo; 1404 DbgInfo.pszExtFile = NULL; 1405 DbgInfo.u.Cv.cbImage = pModLX->Hdr.e32_mpages * pModLX->Hdr.e32_pagesize; 1406 DbgInfo.u.Cv.uTimestamp = 0; 1407 DbgInfo.u.Cv.uMajorVer = 0; 1408 DbgInfo.u.Cv.uMinorVer = 0; 1409 1410 *pfReturn = true; 1411 return pfnCallback(&pModLX->Core, &DbgInfo, pvUser); 1412 } 1411 1413 } 1412 1414 } … … 1415 1417 * Watcom wraps its DWARF output in an ELF image, so look for and ELF magic. 1416 1418 */ 1417 Elf32_Ehdr const *pElfHdr = (Elf32_Ehdr const *)pbBuf; 1418 if ( cbRead >= sizeof(*pElfHdr) 1419 && pElfHdr->e_ident[EI_MAG0] == ELFMAG0 1420 && pElfHdr->e_ident[EI_MAG1] == ELFMAG1 1421 && pElfHdr->e_ident[EI_MAG2] == ELFMAG2 1422 && pElfHdr->e_ident[EI_MAG3] == ELFMAG3 1423 && pElfHdr->e_ident[EI_CLASS] == ELFCLASS32 1424 && pElfHdr->e_ident[EI_DATA] == ELFDATA2LSB 1425 && pElfHdr->e_ident[EI_VERSION] == EV_CURRENT 1426 && pElfHdr->e_shentsize == sizeof(Elf32_Shdr) 1427 && pElfHdr->e_shnum >= 2 1428 && pElfHdr->e_shnum < _32K + 10 1429 && pElfHdr->e_shstrndx <= pElfHdr->e_shnum 1430 && pElfHdr->e_shstrndx > 0 1431 ) 1432 { 1433 /** @todo try use pBuf for reading into and try to read more at once. */ 1434 uint32_t const offShdrs = pElfHdr->e_shoff + offDbgInfo; 1435 uint32_t const cShdrs = pElfHdr->e_shnum; 1436 uint32_t const cbShdr = pElfHdr->e_shentsize; 1437 int rc = VINF_SUCCESS; 1438 1439 /* Read the section string table. */ 1440 Elf32_Shdr Shdr; 1441 int rc2 = pModLX->Core.pReader->pfnRead(pModLX->Core.pReader, &Shdr, sizeof(Shdr), 1442 offShdrs + pElfHdr->e_shstrndx * cbShdr); 1443 if ( RT_SUCCESS(rc2) 1444 && Shdr.sh_offset > 0 1445 && Shdr.sh_size > 0 1446 && Shdr.sh_size < _256K 1447 && Shdr.sh_type == SHT_STRTAB) 1419 if (cbRead >= sizeof(Elf32_Ehdr)) 1420 { 1421 Elf32_Ehdr const *pElfHdr = (Elf32_Ehdr const *)pbBuf; 1422 if ( pElfHdr->e_ident[EI_MAG0] == ELFMAG0 1423 && pElfHdr->e_ident[EI_MAG1] == ELFMAG1 1424 && pElfHdr->e_ident[EI_MAG2] == ELFMAG2 1425 && pElfHdr->e_ident[EI_MAG3] == ELFMAG3 1426 && pElfHdr->e_ident[EI_CLASS] == ELFCLASS32 1427 && pElfHdr->e_ident[EI_DATA] == ELFDATA2LSB 1428 && pElfHdr->e_ident[EI_VERSION] == EV_CURRENT 1429 && pElfHdr->e_shentsize == sizeof(Elf32_Shdr) 1430 && pElfHdr->e_shnum >= 2 1431 && pElfHdr->e_shnum < _32K + 10 1432 && pElfHdr->e_shstrndx <= pElfHdr->e_shnum 1433 && pElfHdr->e_shstrndx > 0) 1448 1434 { 1449 uint32_t const cbStrTab = Shdr.sh_size; 1450 char * const pszStrTab = (char *)RTMemTmpAlloc(cbStrTab + 2); 1451 if (pszStrTab) 1435 /** @todo try use pBuf for reading into and try to read more at once. */ 1436 uint32_t const offShdrs = pElfHdr->e_shoff + offDbgInfo; 1437 uint32_t const cShdrs = pElfHdr->e_shnum; 1438 uint32_t const cbShdr = pElfHdr->e_shentsize; 1439 int rc = VINF_SUCCESS; 1440 1441 /* Read the section string table. */ 1442 Elf32_Shdr Shdr; 1443 int rc2 = pModLX->Core.pReader->pfnRead(pModLX->Core.pReader, &Shdr, sizeof(Shdr), 1444 offShdrs + pElfHdr->e_shstrndx * cbShdr); 1445 if ( RT_SUCCESS(rc2) 1446 && Shdr.sh_offset > 0 1447 && Shdr.sh_size > 0 1448 && Shdr.sh_size < _256K 1449 && Shdr.sh_type == SHT_STRTAB) 1452 1450 { 1453 rc2 = pModLX->Core.pReader->pfnRead(pModLX->Core.pReader, pszStrTab, Shdr.sh_size, offDbgInfo + Shdr.sh_offset); 1454 if (RT_SUCCESS(rc2)) 1451 uint32_t const cbStrTab = Shdr.sh_size; 1452 char * const pszStrTab = (char *)RTMemTmpAlloc(cbStrTab + 2); 1453 if (pszStrTab) 1455 1454 { 1456 pszStrTab[cbStrTab] = '\0'; 1457 1458 /* Iterate the sections, one by one. */ 1459 for (uint32_t i = 1; i < cShdrs; i++) 1455 rc2 = pModLX->Core.pReader->pfnRead(pModLX->Core.pReader, pszStrTab, Shdr.sh_size, 1456 offDbgInfo + Shdr.sh_offset); 1457 if (RT_SUCCESS(rc2)) 1460 1458 { 1461 rc = pModLX->Core.pReader->pfnRead(pModLX->Core.pReader, &Shdr, sizeof(Shdr), offShdrs + i * cbShdr);1462 if ( RT_SUCCESS(rc) 1463 && Shdr.sh_name < cbStrTab1464 && strncmp(&pszStrTab[Shdr.sh_name], RT_STR_TUPLE(".debug_")) == 0)1459 pszStrTab[cbStrTab] = '\0'; 1460 1461 /* Iterate the sections, one by one. */ 1462 for (uint32_t i = 1; i < cShdrs; i++) 1465 1463 { 1466 DbgInfo.enmType = RTLDRDBGINFOTYPE_DWARF; 1467 DbgInfo.iDbgInfo = iDbgInfo; 1468 DbgInfo.offFile = offDbgInfo + Shdr.sh_offset; 1469 DbgInfo.LinkAddress = NIL_RTLDRADDR; 1470 DbgInfo.cb = Shdr.sh_size; 1471 DbgInfo.pszExtFile = NULL; 1472 DbgInfo.u.Dwarf.pszSection = &pszStrTab[Shdr.sh_name]; 1473 1474 *pfReturn = true; 1475 rc = pfnCallback(&pModLX->Core, &DbgInfo, pvUser); 1476 if (rc != VINF_SUCCESS) 1477 break; 1478 iDbgInfo++; 1464 rc = pModLX->Core.pReader->pfnRead(pModLX->Core.pReader, &Shdr, sizeof(Shdr), offShdrs + i * cbShdr); 1465 if ( RT_SUCCESS(rc) 1466 && Shdr.sh_name < cbStrTab 1467 && strncmp(&pszStrTab[Shdr.sh_name], RT_STR_TUPLE(".debug_")) == 0) 1468 { 1469 DbgInfo.enmType = RTLDRDBGINFOTYPE_DWARF; 1470 DbgInfo.iDbgInfo = iDbgInfo; 1471 DbgInfo.offFile = offDbgInfo + Shdr.sh_offset; 1472 DbgInfo.LinkAddress = NIL_RTLDRADDR; 1473 DbgInfo.cb = Shdr.sh_size; 1474 DbgInfo.pszExtFile = NULL; 1475 DbgInfo.u.Dwarf.pszSection = &pszStrTab[Shdr.sh_name]; 1476 1477 *pfReturn = true; 1478 rc = pfnCallback(&pModLX->Core, &DbgInfo, pvUser); 1479 if (rc != VINF_SUCCESS) 1480 break; 1481 iDbgInfo++; 1482 } 1479 1483 } 1480 1484 } 1485 RTMemTmpFree(pszStrTab); 1481 1486 } 1482 RTMemTmpFree(pszStrTab);1483 1487 } 1488 return rc; 1484 1489 } 1485 return rc;1486 1490 } 1487 1491
Note:
See TracChangeset
for help on using the changeset viewer.