Changeset 74640 in vbox
- Timestamp:
- Oct 6, 2018 7:14:10 PM (6 years ago)
- Location:
- trunk/src/VBox/Runtime/common/ldr
- Files:
-
- 2 edited
-
ldrLX.cpp (modified) (63 diffs)
-
ldrMachO.cpp (modified) (78 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/ldr/ldrLX.cpp
r74638 r74640 152 152 static int kldrModLXDoIterData2Unpacking(uint8_t *pbDst, const uint8_t *pbSrc, int cbSrc); 153 153 static void kLdrModLXMemCopyW(uint8_t *pbDst, const uint8_t *pbSrc, int cb); 154 static int kldrModLXDoForwarderQuery(PKLDRMODLX pModLX, const struct e32_entry *pEntry, 155 PFNRTLDRIMPORT pfnGetForwarder, void *pvUser, PRTLDRADDR puValue, uint32_t *pfKind); 156 #if 0 154 157 static int kldrModLXDoProtect(PKLDRMODLX pModLX, void *pvBits, unsigned fUnprotectOrProtect); 155 158 static int kldrModLXDoCallDLL(PKLDRMODLX pModLX, void *pvMapping, unsigned uOp, uintptr_t uHandle); 156 static int kldrModLXDoForwarderQuery(PKLDRMODLX pModLX, const struct e32_entry *pEntry,157 PFNRTLDRIMPORT pfnGetForwarder, void *pvUser, PRTLDRADDR puValue, uint32_t *pfKind); 159 static int32_t kldrModLXDoCall(uintptr_t uEntrypoint, uintptr_t uHandle, uint32_t uOp, void *pvReserved); 160 #endif 158 161 static int kldrModLXDoLoadFixupSection(PKLDRMODLX pModLX); 159 static int32_t kldrModLXDoCall(uintptr_t uEntrypoint, uintptr_t uHandle, uint32_t uOp, void *pvReserved);160 162 static int kldrModLXDoReloc(uint8_t *pbPage, int off, RTLDRADDR PageAddress, const struct r32_rlc *prlc, 161 163 int iSelector, RTLDRADDR uValue, uint32_t fKind); … … 343 345 */ 344 346 rc = pRdr->pfnRead(pRdr, (void *)pModLX->pbLoaderSection, pModLX->Hdr.e32_ldrsize, pModLX->Hdr.e32_objtab + pModLX->offHdr); 345 if ( rc)347 if (RT_FAILURE(rc)) 346 348 return rc; 347 349 ((uint8_t *)pModLX->pbLoaderSectionLast)[1] = 0; … … 568 570 { 569 571 rc = kldrModLXDoNameLookup(pModLX, pchSymbol, cchSymbol, &iSymbol); 570 if ( rc)572 if (RT_FAILURE(rc)) 571 573 return rc; 572 574 } … … 644 646 + offObject 645 647 + pModLX->aSegments[pBundle->b32_obj - 1].RVA; 646 return 0;648 return VINF_SUCCESS; 647 649 } 648 650 … … 680 682 * Do name lookup. 681 683 * 682 * @returns See kLdrModQuerySymbol.684 * @returns IPRT status code. 683 685 * @param pModLX The module to lookup the symbol in. 684 686 * @param pchSymbol The symbol to lookup. … … 716 718 717 719 *piSymbol = *(const uint16_t *)(pbName + 1 + *pbName); 718 return 0;720 return VINF_SUCCESS; 719 721 } 720 722 … … 766 768 * Deal with a forwarder entry. 767 769 * 768 * @returns See kLdrModQuerySymbol.770 * @returns IPRT status code. 769 771 * @param pModLX The PE module interpreter instance. 770 772 * @param pEntry The forwarder entry. … … 811 813 { 812 814 rc = kldrModLXDoLoadFixupSection(pModLX); 813 if ( rc)815 if (RT_FAILURE(rc)) 814 816 return rc; 815 817 } … … 893 895 * The fixup section isn't loaded until it's accessed. It's also freed by kLdrModDone(). 894 896 * 895 * @returns 0 on success, non-zero kLdr or native status code on failure.897 * @returns IPRT status code. 896 898 * @param pModLX The PE module interpreter instance. 897 899 */ … … 1049 1051 szName[*pbName] = '\0'; 1050 1052 rc = pfnCallback(pMod, szName, iOrdinal, uValue, /*fKind,*/ pvUser); 1051 if (rc )1053 if (rc != VINF_SUCCESS) 1052 1054 return rc; 1053 1055 … … 1071 1073 szName[*pbName] = '\0'; 1072 1074 rc = pfnCallback(pMod, szName, iOrdinal, uValue, /*fKind,*/ pvUser); 1073 if (rc )1075 if (rc != VINF_SUCCESS) 1074 1076 return rc; 1075 1077 … … 1086 1088 RT_NOREF(fKind); 1087 1089 rc = pfnCallback(pMod, NULL /*pszName*/, iOrdinal, uValue, /*fKind,*/ pvUser); 1088 if (rc )1090 if (rc != VINF_SUCCESS) 1089 1091 return rc; 1090 1092 } … … 1110 1112 } 1111 1113 1112 return 0;1114 return VINF_SUCCESS; 1113 1115 } 1114 1116 … … 1167 1169 { 1168 1170 rc = kldrModLXDoLoadFixupSection(pModLX); 1169 if ( rc)1171 if (RT_FAILURE(rc)) 1170 1172 return rc; 1171 1173 } … … 1187 1189 memcpy(pszName, pb + 1, *pb); 1188 1190 pszName[*pb] = '\0'; 1189 rc = 0;1191 rc = VINF_SUCCESS; 1190 1192 } 1191 1193 else … … 1233 1235 else 1234 1236 { 1235 pSt ackInfo->Address = NIL_RTLDRADDR;1237 pSt0ackInfo->Address = NIL_RTLDRADDR; 1236 1238 pStackInfo->LinkAddress = NIL_RTLDRADDR; 1237 1239 } … … 1239 1241 pStackInfo->cbStackThread = 0; 1240 1242 1241 return 0;1243 return VINF_SUCCESS; 1242 1244 } 1243 1245 … … 1258 1260 ? BaseAddress + pModLX->aSegments[pModLX->Hdr.e32_startobj - 1].RVA + pModLX->Hdr.e32_eip 1259 1261 : NIL_RTLDRADDR; 1260 return 0;1262 return VINF_SUCCESS; 1261 1263 } 1262 1264 … … 1278 1280 */ 1279 1281 if (kldrModLXHasDbgInfo(pMod, pvBits)) 1280 return 0;1282 return VINF_SUCCESS; 1281 1283 #if 0 1282 1284 /* … … 1286 1288 #endif 1287 1289 1288 return 0;1290 return VINF_SUCCESS; 1289 1291 } 1290 1292 … … 1302 1304 || !pModLX->Hdr.e32_debuglen) 1303 1305 return VERR_NOT_FOUND; 1304 return 0;1306 return VINF_SUCCESS; 1305 1307 } 1306 1308 … … 1336 1338 } 1337 1339 rc = kHlpPageAlloc(&pvBase, pModLX->cbMapped, KPROT_EXECUTE_READWRITE, fFixed); 1338 if ( rc)1340 if (RT_FAILURE(rc)) 1339 1341 return rc; 1340 1342 … … 1343 1345 */ 1344 1346 rc = kldrModLXDoLoadBits(pModLX, pvBase); 1345 if ( !rc)1347 if (RT_SUCCESS(rc)) 1346 1348 rc = kldrModLXDoProtect(pModLX, pvBase, 0 /* protect */); 1347 if ( !rc)1349 if (RT_SUCCESS(rc)) 1348 1350 { 1349 1351 uint32_t i; … … 1365 1367 * Loads the LX pages into the specified memory mapping. 1366 1368 * 1367 * @returns 0 on success. 1368 * @returns non-zero kLdr or OS status code on failure. 1369 * @returns IPRT status code. 1369 1370 * 1370 1371 * @param pModLX The LX module interpreter instance. … … 1375 1376 const PRTLDRREADER pRdr = pModLX->Core.pReader; 1376 1377 uint8_t *pbTmpPage = NULL; 1377 int rc = 0;1378 int rc = VINF_SUCCESS; 1378 1379 uint32_t i; 1379 1380 … … 1391 1392 * Iterate the page map pages. 1392 1393 */ 1393 for (iPage = 0; !rc&& iPage < pObj->o32_mapsize; iPage++, pbPage += OBJPAGELEN)1394 for (iPage = 0; RT_SUCCESS(rc) && iPage < pObj->o32_mapsize; iPage++, pbPage += OBJPAGELEN) 1394 1395 { 1395 1396 const struct o32_map *pMap = &pModLX->paPageMappings[iPage + pObj->o32_pagemap - 1]; … … 1429 1430 rc = pRdr->pfnRead(pRdr, pbTmpPage, pMap->o32_pagesize, 1430 1431 pModLX->Hdr.e32_datapage + (pMap->o32_pagedataoffset << pModLX->Hdr.e32_pageshift)); 1431 if ( rc)1432 if (RT_FAILURE(rc)) 1432 1433 break; 1433 1434 memset(pbTmpPage + pMap->o32_pagesize, 0, 4); … … 1453 1454 } 1454 1455 } 1455 if ( rc)1456 if (RT_FAILURE(rc)) 1456 1457 break; 1457 1458 … … 1472 1473 * Unpacks iterdata (aka EXEPACK). 1473 1474 * 1474 * @returns 0 on success, non-zero kLdr status code on failure.1475 * @returns IPRT status code. 1475 1476 * @param pbDst Where to put the uncompressed data. (Assumes OBJPAGELEN size.) 1476 1477 * @param pbSrc The compressed source data. … … 1536 1537 memset(pbDst, 0, cbDst); 1537 1538 1538 return 0;1539 return VINF_SUCCESS; 1539 1540 } 1540 1541 … … 1543 1544 * Unpacks iterdata (aka EXEPACK). 1544 1545 * 1545 * @returns 0 on success, non-zero kLdr status code on failure.1546 * @returns IPRT status code. 1546 1547 * @param pbDst Where to put the uncompressed data. (Assumes OBJPAGELEN size.) 1547 1548 * @param pbSrc The compressed source data. … … 1751 1752 memset(pbDst, 0, cbDst); 1752 1753 1753 return 0;1754 return VINF_SUCCESS; 1754 1755 } 1755 1756 … … 1802 1803 * Unprotects or protects the specified image mapping. 1803 1804 * 1804 * @returns 0 on success. 1805 * @returns non-zero kLdr or OS status code on failure. 1805 * @returns IPRT status code. 1806 1806 * 1807 1807 * @param pModLX The LX module interpreter instance. … … 1860 1860 1861 1861 rc = kHlpPageProtect(pv, pModLX->aSegments[i].cbMapped, enmProt); 1862 if ( rc)1862 if (RT_FAILURE(rc)) 1863 1863 break; 1864 1864 … … 1866 1866 } 1867 1867 1868 return 0;1868 return VINF_SUCCESS; 1869 1869 } 1870 1870 … … 1906 1906 && pModLX->pvMapping) 1907 1907 return KLDR_ERR_NOT_MAPPED; 1908 return 0;1908 return VINF_SUCCESS; 1909 1909 } 1910 1910 … … 1936 1936 */ 1937 1937 rc = kldrModLXDoProtect(pModLX, (void *)pModLX->pvMapping, 1 /* unprotect */); 1938 if ( rc)1938 if (RT_FAILURE(rc)) 1939 1939 return rc; 1940 1940 … … 1948 1948 */ 1949 1949 rc2 = kldrModLXDoProtect(pModLX, (void *)pModLX->pvMapping, 0 /* protect */); 1950 if ( !rc && rc2)1950 if (RT_SUCCESS(rc) && RT_FAILURE(rc2)) 1951 1951 rc = rc2; 1952 1952 return rc; … … 1970 1970 */ 1971 1971 rc = kldrModLXDoProtect(pModLX, (void *)pModLX->pvMapping, 1 /* unprotect */); 1972 if ( rc)1972 if (RT_FAILURE(rc)) 1973 1973 return rc; 1974 1974 … … 1983 1983 */ 1984 1984 rc2 = kldrModLXDoProtect(pModLX, (void *)pModLX->pvMapping, 0 /* protect */); 1985 if ( !rc && rc2)1985 if (RT_SUCCESS(rc) && RT_FAILURE(rc2)) 1986 1986 rc = rc2; 1987 1987 return rc; … … 2011 2011 rc = kldrModLXDoCallDLL(pModLX, pvMapping, 0 /* attach */, uHandle); 2012 2012 else 2013 rc = 0;2013 rc = VINF_SUCCESS; 2014 2014 return rc; 2015 2015 } … … 2035 2035 if ( !pModLX->Hdr.e32_startobj 2036 2036 || pModLX->Hdr.e32_startobj > pModLX->Hdr.e32_objcnt) 2037 return 0;2037 return VINF_SUCCESS; 2038 2038 2039 2039 /* … … 2045 2045 uHandle, uOp, NULL); 2046 2046 if (rc) 2047 rc = 0;2047 rc = VINF_SUCCESS; 2048 2048 else if (uOp == 0 /* attach */) 2049 2049 rc = KLDR_ERR_MODULE_INIT_FAILED; 2050 2050 else /* detach: ignore failures */ 2051 rc = 0;2051 rc = VINF_SUCCESS; 2052 2052 return rc; 2053 2053 } … … 2138 2138 kldrModLXDoCallDLL(pModLX, pvMapping, 1 /* detach */, uHandle); 2139 2139 2140 return 0;2140 return VINF_SUCCESS; 2141 2141 } 2142 2142 … … 2150 2150 RT_NOREF(uHandle); 2151 2151 RT_NOREF(fAttachingOrDetaching); 2152 return 0;2152 return VINF_SUCCESS; 2153 2153 } 2154 2154 … … 2204 2204 && NewBaseAddress == pModLX->paObjs[0].o32_base 2205 2205 && !pModLX->Hdr.e32_impmodcnt) 2206 return 0;2206 return VINF_SUCCESS; 2207 2207 2208 2208 /* … … 2212 2212 { 2213 2213 rc = kldrModLXDoLoadFixupSection(pModLX); 2214 if ( rc)2214 if (RT_FAILURE(rc)) 2215 2215 return rc; 2216 2216 } … … 2229 2229 * Iterate the page map pages. 2230 2230 */ 2231 for (iPage = 0, rc = 0; !rc && iPage < pObj->o32_mapsize; iPage++, pbPage += OBJPAGELEN, PageAddress += OBJPAGELEN) 2231 for (iPage = 0, rc = VINF_SUCCESS; 2232 RT_SUCCESS(rc) && iPage < pObj->o32_mapsize; 2233 iPage++, pbPage += OBJPAGELEN, PageAddress += OBJPAGELEN) 2232 2234 { 2233 2235 const uint8_t * const pbFixupRecEnd = pModLX->pbFixupRecs + pModLX->paoffPageFixups[iPage + pObj->o32_pagemap]; … … 2252 2254 union _rel 2253 2255 { 2254 const uint8_t * pb; 2256 2257 const uint8_t *pb; 2255 2258 const struct r32_rlc *prlc; 2256 2259 } u; … … 2356 2359 /* resolve it. */ 2357 2360 rc = pfnGetImport(pMod, szImpModule, NULL, iSymbol, &uValue, /*&fKind,*/ pvUser); 2358 if ( rc)2361 if (RT_FAILURE(rc)) 2359 2362 return rc; 2360 2363 iSelector = -1; … … 2413 2416 /* resolve it. */ 2414 2417 rc = pfnGetImport(pMod, szImpModule, szSymbol, UINT32_MAX, &uValue, /*&fKind,*/ pvUser); 2415 if ( rc)2418 if (RT_FAILURE(rc)) 2416 2419 return rc; 2417 2420 iSelector = -1; … … 2463 2466 /* generic */ 2464 2467 rc = kldrModLXDoReloc(pbPage, off, PageAddress, u.prlc, iSelector, uValue, fKind); 2465 if ( rc)2468 if (RT_FAILURE(rc)) 2466 2469 return rc; 2467 2470 } … … 2483 2486 { 2484 2487 rc = kldrModLXDoReloc(pbPage, off, PageAddress, u.prlc, iSelector, uValue, fKind); 2485 if ( rc)2488 if (RT_FAILURE(rc)) 2486 2489 return rc; 2487 2490 } … … 2498 2501 { 2499 2502 rc = kldrModLXDoReloc(pbPage, off, PageAddress, u.prlc, iSelector, uValue, fKind); 2500 if ( rc)2503 if (RT_FAILURE(rc)) 2501 2504 return rc; 2502 2505 } … … 2508 2511 { 2509 2512 rc = kldrModLXDoReloc(pbPage, *poffSrc++, PageAddress, u.prlc, iSelector, uValue, fKind); 2510 if ( rc)2513 if (RT_FAILURE(rc)) 2511 2514 return rc; 2512 2515 } … … 2524 2527 } 2525 2528 2526 return 0;2529 return VINF_SUCCESS; 2527 2530 } 2528 2531 … … 2534 2537 * are dealt with seperately. 2535 2538 * 2536 * @returns 0 on success, non-zero kLdr status code on failure.2539 * @returns IPRT status code. 2537 2540 * @param pbPage The page in which to apply the fixup. 2538 2541 * @param off Page relative offset of where to apply the offset. … … 2554 2557 uint16_t off; 2555 2558 uint16_t Sel; 2556 } Far16;2559 } Far16; 2557 2560 struct 2558 2561 { 2559 2562 uint32_t off; 2560 2563 uint16_t Sel; 2561 } Far32;2562 } uData;2564 } Far32; 2565 } uData; 2563 2566 #pragma pack() 2564 2567 const uint8_t *pbSrc; … … 2634 2637 } 2635 2638 2636 return 0;2639 return VINF_SUCCESS; 2637 2640 } 2638 2641 … … 2647 2650 for (uint32_t iSeg = 0; iSeg < cSegments; iSeg++) 2648 2651 { 2649 RTLDRSEG Seg = pThis->aSegments[iSeg]; 2650 int rc = pfnCallback(pMod, &Seg, pvUser); 2652 int rc = pfnCallback(pMod, &pThis->aSegments[iSeg], pvUser); 2651 2653 if (rc != VINF_SUCCESS) 2652 2654 return rc; … … 2753 2755 static DECLCALLBACK(int) rtldrLX_ReadDbgInfo(PRTLDRMODINTERNAL pMod, uint32_t iDbgInfo, RTFOFF off, size_t cb, void *pvBuf) 2754 2756 { 2755 //PKLDRMODLX pThis = RT_FROM_MEMBER(pMod, KLDRMODLX, Core); 2756 RT_NOREF(pMod, iDbgInfo, off, cb, pvBuf); 2757 PKLDRMODLX pThis = RT_FROM_MEMBER(pMod, KLDRMODLX, Core); 2758 if (iDbgInfo == 0) 2759 return pThis->Core.pReader->pfnRead(pThis->Core.pReader, pvBuf, cb, off); 2757 2760 return VERR_OUT_OF_RANGE; 2758 2761 } 2759 2762 2760 2763 2761 /** @interface_method_impl{RTLDROPS,pfnQueryProp} */ 2764 /** 2765 * @interface_method_impl{RTLDROPS,pfnQueryProp} 2766 */ 2762 2767 static DECLCALLBACK(int) rtldrLX_QueryProp(PRTLDRMODINTERNAL pMod, RTLDRPROP enmProp, void const *pvBits, 2763 2768 void *pvBuf, size_t cbBuf, size_t *pcbRet) … … 2821 2826 rtldrLX_SegOffsetToRva, 2822 2827 rtldrLX_RvaToSegOffset, 2823 NULL,2828 rtldrLX_ReadDbgInfo, 2824 2829 rtldrLX_QueryProp, 2825 2830 NULL /*pfnVerifySignature*/, … … 2853 2858 pThis->Core.u32Magic = RTLDRMOD_MAGIC; 2854 2859 *phLdrMod = &pThis->Core; 2855 return 0;2860 return VINF_SUCCESS; 2856 2861 } 2857 2862 rc = VERR_LDR_ARCH_MISMATCH; -
trunk/src/VBox/Runtime/common/ldr/ldrMachO.cpp
r74638 r74640 342 342 RTLDRADDR LinkAddress = NIL_RTLDRADDR; 343 343 uint8_t uEffFileType = 0; 344 if ( !rc)344 if (RT_SUCCESS(rc)) 345 345 rc = kldrModMachOPreParseLoadCommands(pbLoadCommands, &s.Hdr32, pRdr, offImage, fOpenFlags, 346 346 &cSegments, &cSections, &cbStringPool, &fCanLoad, &LinkAddress, &uEffFileType); 347 if ( rc)347 if (RT_FAILURE(rc)) 348 348 { 349 349 RTMemFree(pbLoadCommands); … … 475 475 */ 476 476 rc = kldrModMachOParseLoadCommands(pThis, (char *)pThis + cbModAndSegs, cbStringPool); 477 if (rc)478 return rc;479 477 480 478 /* 481 479 * We're done. 482 480 */ 483 return 0;481 return rc; 484 482 } 485 483 … … 505 503 * debug enumeration callback API. 506 504 * 507 * @returns 0 on success. 508 * @returns VERR_LDRMACHO_* on failure. 505 * @returns IPRT status code. 509 506 * @param pbLoadCommands The load commands to parse. 510 507 * @param pHdr The header. … … 579 576 section_32_t *pSect = pFirstSect; 580 577 uint32_t cSectionsLeft = pSrcSeg->nsects; 581 uint64_t offSect = 0;578 uint64_t offSect = 0; 582 579 583 580 /* Convert and verify the segment. */ … … 1051 1048 *pcbStringPool = (uint32_t)cbStringPool; 1052 1049 1053 return 0;1050 return VINF_SUCCESS; 1054 1051 } 1055 1052 … … 1060 1057 * This fills in the segment table and perhaps some other properties. 1061 1058 * 1062 * @returns 0 on success. 1063 * @returns VERR_LDRMACHO_* on failure. 1064 * @param pThis The module. 1059 * @returns IPRT status code. 1060 * @param pThis The module. 1065 1061 * @param pbStringPool The string pool 1066 1062 * @param cbStringPool The size of the string pool. … … 1105 1101 1106 1102 /* Adds a segment, used by the macro below and thus shared with the 64-bit segment variant. */ 1107 #define NEW_SEGMENT(a_cBits, a_achName1, a_fObjFile, a_achName2, a_SegAddr, a_cbSeg, a_fFileBits, a_offFile, a_cbFile) \1103 #define NEW_SEGMENT(a_cBits, a_achName1, a_fObjFile, a_achName2, a_SegAddr, a_cbSeg, a_fFileBits, a_offFile, a_cbFile) \ 1108 1104 do { \ 1109 1105 pDstSeg->SegInfo.pszName = pbStringPool; \ … … 1146 1142 1147 1143 /* Closes the new segment - part of NEW_SEGMENT. */ 1148 #define CLOSE_SEGMENT() \1144 #define CLOSE_SEGMENT() \ 1149 1145 do { \ 1150 1146 pDstSeg->cSections = (uint32_t)(pSectExtra - pDstSeg->paSections); \ … … 1154 1150 1155 1151 /* Shared with the 64-bit variant. */ 1156 #define ADD_SEGMENT_AND_ITS_SECTIONS(a_cBits) \1152 #define ADD_SEGMENT_AND_ITS_SECTIONS(a_cBits) \ 1157 1153 do { \ 1158 1154 bool fAddSegOuter = false; \ … … 1175 1171 && strcmp(pSrcSeg->segname, "__CTF") ) \ 1176 1172 { \ 1177 NEW_SEGMENT(a_cBits, pSrcSeg->segname, false /*a_fObjFile*/, 0/*a_achName2*/, \1173 NEW_SEGMENT(a_cBits, pSrcSeg->segname, false /*a_fObjFile*/, "" /*a_achName2*/, \ 1178 1174 pSrcSeg->vmaddr, pSrcSeg->vmsize, \ 1179 1175 pSrcSeg->filesize != 0, pSrcSeg->fileoff, pSrcSeg->filesize); \ … … 1409 1405 } 1410 1406 1411 return 0;1407 return VINF_SUCCESS; 1412 1408 } 1413 1409 … … 1419 1415 { 1420 1416 PKLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core); 1421 int rc = 0;1417 int rc = VINF_SUCCESS; 1422 1418 KLDRMODMACHO_ASSERT(!pThis->pvMapping); 1423 1419 … … 1454 1450 * Gets the right base address. 1455 1451 * 1456 * @returns 0 on success.1457 * @returns A non-zero status code if the BaseAddress isn't right.1458 1452 * @param pThis The interpreter module instance 1459 1453 * @param pBaseAddress The base address, IN & OUT. Optional. 1460 1454 */ 1461 static intkldrModMachOAdjustBaseAddress(PKLDRMODMACHO pThis, PRTLDRADDR pBaseAddress)1455 static void kldrModMachOAdjustBaseAddress(PKLDRMODMACHO pThis, PRTLDRADDR pBaseAddress) 1462 1456 { 1463 1457 /* … … 1466 1460 if (*pBaseAddress == RTLDR_BASEADDRESS_LINK) 1467 1461 *pBaseAddress = pThis->LinkAddress; 1468 return 0;1469 1462 } 1470 1463 … … 1476 1469 * and segments. This function checks for these and returns the right value. 1477 1470 * 1478 * @returns 0or VERR_SYMBOL_NOT_FOUND.1479 * @param pThis The interpreter module instance.1471 * @returns VINF_SUCCESS or VERR_SYMBOL_NOT_FOUND. 1472 * @param pThis The interpreter module instance. 1480 1473 * @param pchSymbol The symbol. 1481 1474 * @param cchSymbol The length of the symbol. … … 1611 1604 *puValue = uValue; 1612 1605 1613 return 0;1606 return VINF_SUCCESS; 1614 1607 } 1615 1608 … … 1633 1626 * Resolve defaults. 1634 1627 */ 1635 int rc = kldrModMachOAdjustBaseAddress(pThis, &BaseAddress); 1636 if (rc) 1637 return rc; 1628 kldrModMachOAdjustBaseAddress(pThis, &BaseAddress); 1638 1629 1639 1630 /* … … 1647 1638 * Take action according to file type. 1648 1639 */ 1640 int rc; 1649 1641 if ( pThis->Hdr.filetype == MH_OBJECT 1650 1642 || pThis->Hdr.filetype == MH_EXECUTE /** @todo dylib, execute, dsym: symbols */ … … 1655 1647 { 1656 1648 rc = kldrModMachOLoadObjSymTab(pThis); 1657 if ( !rc)1649 if (RT_SUCCESS(rc)) 1658 1650 { 1659 1651 if ( pThis->Hdr.magic == IMAGE_MACHO32_SIGNATURE … … 1696 1688 * Lookup a symbol in a 32-bit symbol table. 1697 1689 * 1698 * @returns See kLdrModQuerySymbol.1690 * @returns IPRT status code. 1699 1691 * @param pThis 1700 1692 * @param paSyms Pointer to the symbol table. … … 1817 1809 } 1818 1810 1819 return 0;1811 return VINF_SUCCESS; 1820 1812 } 1821 1813 … … 1824 1816 * Lookup a symbol in a 64-bit symbol table. 1825 1817 * 1826 * @returns See kLdrModQuerySymbol.1818 * @returns IPRT status code. 1827 1819 * @param pThis 1828 1820 * @param paSyms Pointer to the symbol table. … … 1945 1937 } 1946 1938 1947 return 0;1939 return VINF_SUCCESS; 1948 1940 } 1949 1941 … … 1956 1948 { 1957 1949 PKLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core); 1950 RT_NOREF(pvBits); 1951 1952 /* 1953 * Resolve defaults. 1954 */ 1955 kldrModMachOAdjustBaseAddress(pThis, &BaseAddress); 1956 1957 /* 1958 * Take action according to file type. 1959 */ 1958 1960 int rc; 1959 RT_NOREF(pvBits);1960 1961 /*1962 * Resolve defaults.1963 */1964 rc = kldrModMachOAdjustBaseAddress(pThis, &BaseAddress);1965 if (rc)1966 return rc;1967 1968 /*1969 * Take action according to file type.1970 */1971 1961 if ( pThis->Hdr.filetype == MH_OBJECT 1972 1962 || pThis->Hdr.filetype == MH_EXECUTE /** @todo dylib, execute, dsym: symbols */ … … 1977 1967 { 1978 1968 rc = kldrModMachOLoadObjSymTab(pThis); 1979 if ( !rc)1969 if (RT_SUCCESS(rc)) 1980 1970 { 1981 1971 if ( pThis->Hdr.magic == IMAGE_MACHO32_SIGNATURE … … 2000 1990 * Enum a 32-bit symbol table. 2001 1991 * 2002 * @returns See kLdrModQuerySymbol.1992 * @returns IPRT status code. 2003 1993 * @param pThis 2004 1994 * @param paSyms Pointer to the symbol table. … … 2102 2092 */ 2103 2093 rc = pfnCallback(&pThis->Core, psz, iSym, uValue/*, fKind*/, pvUser); 2104 if (rc )2094 if (rc != VINF_SUCCESS) 2105 2095 return rc; 2106 2096 } 2107 return 0;2097 return VINF_SUCCESS; 2108 2098 } 2109 2099 … … 2112 2102 * Enum a 64-bit symbol table. 2113 2103 * 2114 * @returns See kLdrModQuerySymbol.2104 * @returns IPRT status code. 2115 2105 * @param pThis 2116 2106 * @param paSyms Pointer to the symbol table. … … 2214 2204 */ 2215 2205 rc = pfnCallback(&pThis->Core, psz, iSym, uValue/*, fKind*/, pvUser); 2216 if (rc )2206 if (rc != VINF_SUCCESS) 2217 2207 return rc; 2218 2208 } 2219 return 0;2209 return VINF_SUCCESS; 2220 2210 } 2221 2211 … … 2247 2237 2248 2238 if (pThis->Hdr.filetype == MH_OBJECT) 2249 return 0;2239 return VINF_SUCCESS; 2250 2240 2251 2241 /* later */ 2252 return 0;2242 return VINF_SUCCESS; 2253 2243 } 2254 2244 … … 2267 2257 /* later */ 2268 2258 2269 return 0; 2270 } 2271 2272 #endif 2259 return VINF_SUCCESS; 2260 } 2273 2261 2274 2262 … … 2284 2272 */ 2285 2273 rc = kldrModMachOBitsAndBaseAddress(pThis, NULL, &BaseAddress); 2286 if ( rc)2274 if (RT_FAILURE(rc)) 2287 2275 return rc; 2288 2276 … … 2299 2287 RT_NOREF(pMod); 2300 2288 #endif 2301 return 0; 2302 } 2303 2289 return VINF_SUCCESS; 2290 } 2291 2292 #endif 2304 2293 2305 2294 /** @copydoc kLdrModQueryImageUuid */ … … 2369 2358 || !pThis->Hdrs.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress) 2370 2359 return KLDR_ERR_NO_DEBUG_INFO; 2371 return 0;2360 return VINF_SUCCESS; 2372 2361 #else 2373 2362 RT_NOREF(pMod); … … 2413 2402 /* try do the prepare */ 2414 2403 rc = kRdrMap(pMod->pRdr, &pvBase, pMod->cSegments, pMod->aSegments, fFixed); 2415 if ( rc)2404 if (RT_FAILURE(rc)) 2416 2405 return rc; 2417 2406 … … 2426 2415 pThis->pvMapping = pvBase; 2427 2416 2428 return 0;2417 return VINF_SUCCESS; 2429 2418 } 2430 2419 … … 2447 2436 */ 2448 2437 rc = kRdrUnmap(pMod->pRdr, pThis->pvMapping, pMod->cSegments, pMod->aSegments); 2449 if ( rc)2438 if (RT_FAILURE(rc)) 2450 2439 return rc; 2451 2440 … … 2457 2446 pMod->aSegments[i].MapAddress = 0; 2458 2447 2459 return 0;2448 return VINF_SUCCESS; 2460 2449 } 2461 2450 … … 2472 2461 && !pThis->pvMapping ) 2473 2462 return KLDR_ERR_NOT_MAPPED; 2474 return 0;2463 return VINF_SUCCESS; 2475 2464 } 2476 2465 … … 2517 2506 */ 2518 2507 rc = kRdrProtect(pMod->pRdr, pThis->pvMapping, pMod->cSegments, pMod->aSegments, 1 /* unprotect */); 2519 if ( rc)2508 if (RT_FAILURE(rc)) 2520 2509 return rc; 2521 2510 … … 2530 2519 */ 2531 2520 rc2 = kRdrProtect(pMod->pRdr, pThis->pvMapping, pMod->cSegments, pMod->aSegments, 0 /* protect */); 2532 if ( !rc &&rc2)2521 if (RT_SUCCESS(rc) && RT_FAILURE(rc2) 2533 2522 rc = rc2; 2534 2523 return rc; … … 2540 2529 * MH_OBJECT: Resolves undefined symbols (imports). 2541 2530 * 2542 * @returns 0 on success, non-zero kLdr status code on failure.2543 * @param pThis The Mach-O module interpreter instance.2531 * @returns IPRT status code. 2532 * @param pThis The Mach-O module interpreter instance. 2544 2533 * @param pfnGetImport The callback for resolving an imported symbol. 2545 2534 * @param pvUser User argument to the callback. … … 2549 2538 const uint32_t cSyms = pThis->cSymbols; 2550 2539 uint32_t iSym; 2551 int rc;2552 2540 2553 2541 /* 2554 2542 * Ensure that we've got the symbol table and section fixups handy. 2555 2543 */ 2556 rc = kldrModMachOLoadObjSymTab(pThis);2557 if ( rc)2544 int rc = kldrModMachOLoadObjSymTab(pThis); 2545 if (RT_FAILURE(rc)) 2558 2546 return rc; 2559 2547 … … 2596 2584 2597 2585 /* Ask the user for an address to the symbol. */ 2598 if ( rc)2586 if (RT_FAILURE_NP(rc)) 2599 2587 rc = pfnGetImport(&pThis->Core, NULL /*pszModule*/, pszSymbol, iSym, &Value/*, &fKind*/, pvUser); 2600 if ( rc)2588 if (RT_FAILURE(rc)) 2601 2589 { 2602 2590 /* weak reference? */ … … 2655 2643 2656 2644 /* Ask the user for an address to the symbol. */ 2657 if ( rc)2645 if (RT_FAILURE_NP(rc)) 2658 2646 rc = pfnGetImport(&pThis->Core, NULL, pszSymbol, iSym, &Value, /*&fKind,*/ pvUser); 2659 if ( rc)2647 if (RT_FAILURE(rc)) 2660 2648 { 2661 2649 /* weak reference? */ … … 2688 2676 * MH_OBJECT: Applies base relocations to a (unprotected) image mapping. 2689 2677 * 2690 * @returns 0 on success, non-zero kLdr status code on failure.2691 * @param pThis The Mach-O module interpreter instance.2678 * @returns IPRT status code. 2679 * @param pThis The Mach-O module interpreter instance. 2692 2680 * @param pvMapping The mapping to fixup. 2693 2681 * @param NewBaseAddress The address to fixup the mapping to. … … 2696 2684 static int kldrModMachOObjDoFixups(PKLDRMODMACHO pThis, void *pvMapping, RTLDRADDR NewBaseAddress) 2697 2685 { 2698 uint32_t iSeg;2699 int rc;2700 2701 2702 2686 /* 2703 2687 * Ensure that we've got the symbol table and section fixups handy. 2704 2688 */ 2705 rc = kldrModMachOLoadObjSymTab(pThis);2706 if ( rc)2689 int rc = kldrModMachOLoadObjSymTab(pThis); 2690 if (RT_FAILURE(rc)) 2707 2691 return rc; 2708 2692 … … 2710 2694 * Iterate over the segments and their sections and apply fixups. 2711 2695 */ 2712 for (iSeg = rc = 0; !rc && iSeg < pThis->cSegments; iSeg++) 2696 rc = VINF_SUCCESS; 2697 for (uint32_t iSeg = 0; RT_SUCCESS(rc) && iSeg < pThis->cSegments; iSeg++) 2713 2698 { 2714 2699 PKLDRMODMACHOSEG pSeg = &pThis->aSegments[iSeg]; 2715 uint32_t iSect; 2716 2717 for (iSect = 0; iSect < pSeg->cSections; iSect++) 2700 for (uint32_t iSect = 0; iSect < pSeg->cSections; iSect++) 2718 2701 { 2719 2702 PKLDRMODMACHOSECT pSect = &pSeg->paSections[iSect]; 2720 uint8_t *pbSectBits;2721 2703 2722 2704 /* skip sections without fixups. */ … … 2728 2710 { 2729 2711 rc = kldrModMachOLoadFixups(pThis, pSect->offFixups, pSect->cFixups, &pSect->paFixups); 2730 if ( rc)2712 if (RT_FAILURE(rc)) 2731 2713 break; 2732 2714 } … … 2735 2717 * Apply the fixups. 2736 2718 */ 2737 pbSectBits = (uint8_t *)pvMapping + (uintptr_t)pSect->RVA;2719 uint8_t *pbSectBits = (uint8_t *)pvMapping + (uintptr_t)pSect->RVA; 2738 2720 if (pThis->Hdr.magic == IMAGE_MACHO32_SIGNATURE) /** @todo this aint right. */ 2739 2721 rc = kldrModMachOFixupSectionGeneric32Bit(pThis, pbSectBits, pSect, … … 2747 2729 else 2748 2730 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 2749 if ( rc)2731 if (RT_FAILURE(rc)) 2750 2732 break; 2751 2733 } … … 2760 2742 * as the host CPU. 2761 2743 * 2762 * @returns 0 on success, non-zero kLdr status code on failure.2763 * @param pThis The Mach-O module interpreter instance.2744 * @returns IPRT status code. 2745 * @param pThis The Mach-O module interpreter instance. 2764 2746 * @param pbSectBits Pointer to the section bits. 2765 2747 * @param pFixupSect The section being fixed up. … … 2783 2765 { 2784 2766 rc = kldrModMachOMapVirginBits(pThis); 2785 if ( rc)2767 if (RT_FAILURE(rc)) 2786 2768 return rc; 2787 2769 pbSectVirginBits = (const uint8_t *)pThis->pvBits + pFixupSect->offFile; … … 2954 2936 } 2955 2937 2956 return 0;2938 return VINF_SUCCESS; 2957 2939 } 2958 2940 … … 2961 2943 * Applies AMD64 fixups to a section. 2962 2944 * 2963 * @returns 0 on success, non-zero kLdr status code on failure.2964 * @param pThis The Mach-O module interpreter instance.2945 * @returns IPRT status code. 2946 * @param pThis The Mach-O module interpreter instance. 2965 2947 * @param pbSectBits Pointer to the section bits. 2966 2948 * @param pFixupSect The section being fixed up. … … 2984 2966 { 2985 2967 rc = kldrModMachOMapVirginBits(pThis); 2986 if ( rc)2968 if (RT_FAILURE(rc)) 2987 2969 return rc; 2988 2970 pbSectVirginBits = (const uint8_t *)pThis->pvBits + pFixupSect->offFile; … … 3270 3252 } 3271 3253 3272 return 0;3254 return VINF_SUCCESS; 3273 3255 } 3274 3256 … … 3279 3261 * The symbol table is pointed to by KLDRMODMACHO::pvaSymbols. 3280 3262 * 3281 * @returns 0 on success, non-zero kLdr status code on failure.3263 * @returns IPRT status code. 3282 3264 * @param pThis The Mach-O module interpreter instance. 3283 3265 */ 3284 3266 static int kldrModMachOLoadObjSymTab(PKLDRMODMACHO pThis) 3285 3267 { 3286 int rc = 0;3268 int rc = VINF_SUCCESS; 3287 3269 3288 3270 if ( !pThis->pvaSymbols … … 3318 3300 /* read */ 3319 3301 rc = pThis->Core.pReader->pfnRead(pThis->Core.pReader, pvSyms, cbSyms, pThis->offSymbols); 3320 if ( !rc&& pThis->cchStrings)3302 if (RT_SUCCESS(rc) && pThis->cchStrings) 3321 3303 rc = pThis->Core.pReader->pfnRead(pThis->Core.pReader, pvStrings, 3322 3304 pThis->cchStrings, pThis->offStrings); 3323 if ( !rc)3305 if (RT_SUCCESS(rc)) 3324 3306 { 3325 3307 pThis->pvaSymbols = pvSyms; … … 3352 3334 } 3353 3335 3354 return 0;3336 return VINF_SUCCESS; 3355 3337 } 3356 3338 RTMemFree(pvStrings); … … 3370 3352 * conversion if necessary. 3371 3353 * 3372 * @returns 0 on success, non-zero kLdr status code on failure.3373 * @param pThis The Mach-O module interpreter instance.3354 * @returns IPRT status code. 3355 * @param pThis The Mach-O module interpreter instance. 3374 3356 * @param offFixups The file offset of the fixups. 3375 3357 * @param cFixups The number of fixups to load. … … 3380 3362 macho_relocation_info_t *paFixups; 3381 3363 size_t cbFixups; 3382 int rc;3383 3364 3384 3365 /* allocate the memory. */ … … 3390 3371 3391 3372 /* read the fixups. */ 3392 rc = pThis->Core.pReader->pfnRead(pThis->Core.pReader, paFixups, cbFixups, offFixups);3393 if ( !rc)3373 int rc = pThis->Core.pReader->pfnRead(pThis->Core.pReader, paFixups, cbFixups, offFixups); 3374 if (RT_SUCCESS(rc)) 3394 3375 { 3395 3376 *ppaFixups = paFixups; … … 3417 3398 * Maps the virgin file bits into memory if not already done. 3418 3399 * 3419 * @returns 0 on success, non-zero kLdr status code on failure.3400 * @returns IPRT status code. 3420 3401 * @param pThis The Mach-O module interpreter instance. 3421 3402 */ 3422 3403 static int kldrModMachOMapVirginBits(PKLDRMODMACHO pThis) 3423 3404 { 3424 int rc = 0;3405 int rc = VINF_SUCCESS; 3425 3406 if (!pThis->pvBits) 3426 3407 rc = pThis->Core.pReader->pfnMap(pThis->Core.pReader, &pThis->pvBits); … … 3437 3418 RT_NOREF(pvMapping); 3438 3419 RT_NOREF(uHandle); 3439 return 0;3420 return VINF_SUCCESS; 3440 3421 } 3441 3422 … … 3448 3429 RT_NOREF(pvMapping); 3449 3430 RT_NOREF(uHandle); 3450 return 0;3431 return VINF_SUCCESS; 3451 3432 } 3452 3433 … … 3460 3441 RT_NOREF(uHandle); 3461 3442 RT_NOREF(fAttachingOrDetaching); 3462 return 0;3443 return VINF_SUCCESS; 3463 3444 } 3464 3445 … … 3469 3450 * @interface_method_impl{RTLDROPS,pfnGetImageSize} 3470 3451 */ 3471 static size_trtldrMachO_GetImageSize(PRTLDRMODINTERNAL pMod)3452 static DECLCALLBACK(size_t) rtldrMachO_GetImageSize(PRTLDRMODINTERNAL pMod) 3472 3453 { 3473 3454 PKLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core); … … 3504 3485 continue; 3505 3486 int rc = pThis->Core.pReader->pfnRead(pThis->Core.pReader, 3506 (uint8_t *)pvBits + pThis->aSegments[i].SegInfo.RVA,3507 pThis->aSegments[i].SegInfo.cbFile,3508 pThis->aSegments[i].SegInfo.offFile);3509 if ( rc)3487 (uint8_t *)pvBits + pThis->aSegments[i].SegInfo.RVA, 3488 pThis->aSegments[i].SegInfo.cbFile, 3489 pThis->aSegments[i].SegInfo.offFile); 3490 if (RT_FAILURE(rc)) 3510 3491 return rc; 3511 3492 } … … 3534 3515 { 3535 3516 rc = kldrModMachOObjDoImports(pThis, NewBaseAddress, pfnGetImport, pvUser); 3536 if ( !rc)3517 if (RT_SUCCESS(rc)) 3537 3518 rc = kldrModMachOObjDoFixups(pThis, pvBits, NewBaseAddress); 3538 3519 … … 3542 3523 /*{ 3543 3524 rc = kldrModMachODoFixups(pThis, pvBits, NewBaseAddress, OldBaseAddress, pfnGetImport, pvUser); 3544 if ( !rc)3525 if (RT_SUCCESS(rc)) 3545 3526 rc = kldrModMachODoImports(pThis, pvBits, pfnGetImport, pvUser); 3546 3527 }*/ … … 3550 3531 * segment when present. 3551 3532 */ 3552 if ( !rc&& pThis->fMakeGot)3533 if (RT_SUCCESS(rc) && pThis->fMakeGot) 3553 3534 rc = kldrModMachOMakeGOT(pThis, pvBits, NewBaseAddress); 3554 3535 … … 3657 3638 } 3658 3639 } 3659 return 0;3640 return VINF_SUCCESS; 3660 3641 } 3661 3642 … … 3670 3651 for (uint32_t iSeg = 0; iSeg < cSegments; iSeg++) 3671 3652 { 3672 RTLDRSEG Seg = pThis->aSegments[iSeg].SegInfo; 3673 int rc = pfnCallback(pMod, &Seg, pvUser); 3653 int rc = pfnCallback(pMod, &pThis->aSegments[iSeg].SegInfo, pvUser); 3674 3654 if (rc != VINF_SUCCESS) 3675 3655 return rc; … … 3779 3759 3780 3760 /** @todo May have to apply fixups here. */ 3781 if (iDbgInfo == iDbgInfo)3761 if (iDbgInfo < pThis->cSections) 3782 3762 return pThis->Core.pReader->pfnRead(pThis->Core.pReader, pvBuf, cb, off); 3783 if (iDbgInfo < pThis->cSections)3784 {3785 return pThis->Core.pReader->pfnRead(pThis->Core.pReader, pvBuf, cb, off);3786 }3787 3763 return VERR_OUT_OF_RANGE; 3788 3764 } … … 3840 3816 rtldrMachO_SegOffsetToRva, 3841 3817 rtldrMachO_RvaToSegOffset, 3842 NULL,3818 rtldrMachO_ReadDbgInfo, 3843 3819 rtldrMachO_QueryProp, 3844 3820 NULL /*pfnVerifySignature*/, … … 3872 3848 pThis->Core.u32Magic = RTLDRMOD_MAGIC; 3873 3849 *phLdrMod = &pThis->Core; 3874 return 0;3850 return VINF_SUCCESS; 3875 3851 } 3876 3852 rc = VERR_LDR_ARCH_MISMATCH; … … 3909 3885 { 3910 3886 fat_arch_t FatEntry; 3911 intrc = pReader->pfnRead(pReader, &FatEntry, sizeof(FatEntry), offEntry);3887 rc = pReader->pfnRead(pReader, &FatEntry, sizeof(FatEntry), offEntry); 3912 3888 if (RT_FAILURE(rc)) 3913 3889 return RTErrInfoSetF(pErrInfo, rc, "Read error at offset 0: %Rrc", rc);
Note:
See TracChangeset
for help on using the changeset viewer.

