Changeset 74647 in vbox for trunk/src/VBox
- Timestamp:
- Oct 6, 2018 9:29:40 PM (6 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/ldr/ldrMachO.cpp
r74646 r74647 51 51 * Defined Constants And Macros * 52 52 *********************************************************************************************************************************/ 53 /** @def KLDRMODMACHO_STRICT54 * Define KLDRMODMACHO_STRICT to enabled strict checks in KLDRMODMACHO. */55 #define KLDRMODMACHO_STRICT 156 57 /** @def KLDRMODMACHO_ASSERT53 /** @def RTLDRMODMACHO_STRICT 54 * Define RTLDRMODMACHO_STRICT to enabled strict checks in RTLDRMODMACHO. */ 55 #define RTLDRMODMACHO_STRICT 1 56 57 /** @def RTLDRMODMACHO_ASSERT 58 58 * Assert that an expression is true when KLDR_STRICT is defined. 59 59 */ 60 #ifdef KLDRMODMACHO_STRICT61 # define KLDRMODMACHO_ASSERT(expr) Assert(expr)60 #ifdef RTLDRMODMACHO_STRICT 61 # define RTLDRMODMACHO_ASSERT(expr) Assert(expr) 62 62 #else 63 # define KLDRMODMACHO_ASSERT(expr) do {} while (0)63 # define RTLDRMODMACHO_ASSERT(expr) do {} while (0) 64 64 #endif 65 65 66 /** @def KLDRMODMACHO_CHECK_RETURN66 /** @def RTLDRMODMACHO_CHECK_RETURN 67 67 * Checks that an expression is true and return if it isn't. 68 68 * This is a debug aid. 69 69 */ 70 #ifdef KLDRMODMACHO_STRICT271 # define KLDRMODMACHO_CHECK_RETURN(expr, rc) AssertReturn(expr, rc)70 #ifdef RTLDRMODMACHO_STRICT2 71 # define RTLDRMODMACHO_CHECK_RETURN(expr, rc) AssertReturn(expr, rc) 72 72 #else 73 # define KLDRMODMACHO_CHECK_RETURN(expr, rc) do { if (!(expr)) { return (rc); } } while (0)73 # define RTLDRMODMACHO_CHECK_RETURN(expr, rc) do { if (!(expr)) { return (rc); } } while (0) 74 74 #endif 75 75 76 /** @def KLDRMODMACHO_CHECK_RETURN76 /** @def RTLDRMODMACHO_CHECK_RETURN 77 77 * Checks that an expression is true and return if it isn't. 78 78 * This is a debug aid. 79 79 */ 80 #ifdef KLDRMODMACHO_STRICT281 # define KLDRMODMACHO_FAILED_RETURN(rc) AssertFailedReturn(rc)80 #ifdef RTLDRMODMACHO_STRICT2 81 # define RTLDRMODMACHO_FAILED_RETURN(rc) AssertFailedReturn(rc) 82 82 #else 83 # define KLDRMODMACHO_FAILED_RETURN(rc) return (rc)83 # define RTLDRMODMACHO_FAILED_RETURN(rc) return (rc) 84 84 #endif 85 85 … … 91 91 * Mach-O section details. 92 92 */ 93 typedef struct KLDRMODMACHOSECT93 typedef struct RTLDRMODMACHOSECT 94 94 { 95 95 /** The size of the section (in bytes). */ … … 115 115 /** Pointer to the Mach-O section structure. */ 116 116 void *pvMachoSection; 117 } KLDRMODMACHOSECT, *PKLDRMODMACHOSECT;117 } RTLDRMODMACHOSECT, *PRTLDRMODMACHOSECT; 118 118 119 119 /** … … 122 122 * This is corresponds to a kLdr segment, not a Mach-O segment! 123 123 */ 124 typedef struct KLDRMODMACHOSEG124 typedef struct RTLDRMODMACHOSEG 125 125 { 126 126 /** Common segment info. */ … … 134 134 * The array resides in the big memory chunk allocated for 135 135 * the module handle, so it doesn't need freeing. */ 136 P KLDRMODMACHOSECTpaSections;137 138 } KLDRMODMACHOSEG, *PKLDRMODMACHOSEG;136 PRTLDRMODMACHOSECT paSections; 137 138 } RTLDRMODMACHOSEG, *PRTLDRMODMACHOSEG; 139 139 140 140 /** … … 142 142 * @todo interpret the other MH_* formats. 143 143 */ 144 typedef struct KLDRMODMACHO144 typedef struct RTLDRMODMACHO 145 145 { 146 146 /** Core module structure. */ … … 209 209 uint32_t cSections; 210 210 /** Pointer to the section array running in parallel to the Mach-O one. */ 211 P KLDRMODMACHOSECTpaSections;211 PRTLDRMODMACHOSECT paSections; 212 212 213 213 /** Array of segments parallel to the one in KLDRMOD. */ 214 KLDRMODMACHOSEGaSegments[1];215 } KLDRMODMACHO, *PKLDRMODMACHO;214 RTLDRMODMACHOSEG aSegments[1]; 215 } RTLDRMODMACHO, *PRTLDRMODMACHO; 216 216 217 217 … … 231 231 uint32_t fOpenFlags, uint32_t *pcSegments, uint32_t *pcSections, uint32_t *pcbStringPool, 232 232 bool *pfCanLoad, PRTLDRADDR pLinkAddress, uint8_t *puEffFileType, PRTERRINFO pErrInfo); 233 static int kldrModMachOParseLoadCommands(P KLDRMODMACHO pThis, char *pbStringPool, uint32_t cbStringPool);234 235 static int kldrModMachOLoadObjSymTab(P KLDRMODMACHO pThis);236 static int kldrModMachOLoadFixups(P KLDRMODMACHO pThis, RTFOFF offFixups, uint32_t cFixups, macho_relocation_info_t **ppaFixups);237 static int kldrModMachOMapVirginBits(P KLDRMODMACHO pThis);238 239 static int kldrModMachODoQuerySymbol32Bit(P KLDRMODMACHO pThis, const macho_nlist_32_t *paSyms, uint32_t cSyms, const char *pchStrings,233 static int kldrModMachOParseLoadCommands(PRTLDRMODMACHO pThis, char *pbStringPool, uint32_t cbStringPool); 234 235 static int kldrModMachOLoadObjSymTab(PRTLDRMODMACHO pThis); 236 static int kldrModMachOLoadFixups(PRTLDRMODMACHO pThis, RTFOFF offFixups, uint32_t cFixups, macho_relocation_info_t **ppaFixups); 237 static int kldrModMachOMapVirginBits(PRTLDRMODMACHO pThis); 238 239 static int kldrModMachODoQuerySymbol32Bit(PRTLDRMODMACHO pThis, const macho_nlist_32_t *paSyms, uint32_t cSyms, const char *pchStrings, 240 240 uint32_t cchStrings, RTLDRADDR BaseAddress, uint32_t iSymbol, const char *pchSymbol, 241 241 uint32_t cchSymbol, PRTLDRADDR puValue, uint32_t *pfKind); 242 static int kldrModMachODoQuerySymbol64Bit(P KLDRMODMACHO pThis, const macho_nlist_64_t *paSyms, uint32_t cSyms, const char *pchStrings,242 static int kldrModMachODoQuerySymbol64Bit(PRTLDRMODMACHO pThis, const macho_nlist_64_t *paSyms, uint32_t cSyms, const char *pchStrings, 243 243 uint32_t cchStrings, RTLDRADDR BaseAddress, uint32_t iSymbol, const char *pchSymbol, 244 244 uint32_t cchSymbol, PRTLDRADDR puValue, uint32_t *pfKind); 245 static int kldrModMachODoEnumSymbols32Bit(P KLDRMODMACHO pThis, const macho_nlist_32_t *paSyms, uint32_t cSyms,245 static int kldrModMachODoEnumSymbols32Bit(PRTLDRMODMACHO pThis, const macho_nlist_32_t *paSyms, uint32_t cSyms, 246 246 const char *pchStrings, uint32_t cchStrings, RTLDRADDR BaseAddress, 247 247 uint32_t fFlags, PFNRTLDRENUMSYMS pfnCallback, void *pvUser); 248 static int kldrModMachODoEnumSymbols64Bit(P KLDRMODMACHO pThis, const macho_nlist_64_t *paSyms, uint32_t cSyms,248 static int kldrModMachODoEnumSymbols64Bit(PRTLDRMODMACHO pThis, const macho_nlist_64_t *paSyms, uint32_t cSyms, 249 249 const char *pchStrings, uint32_t cchStrings, RTLDRADDR BaseAddress, 250 250 uint32_t fFlags, PFNRTLDRENUMSYMS pfnCallback, void *pvUser); 251 static int kldrModMachOObjDoImports(P KLDRMODMACHO pThis, RTLDRADDR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser);252 static int kldrModMachOObjDoFixups(P KLDRMODMACHO pThis, void *pvMapping, RTLDRADDR NewBaseAddress);253 static int kldrModMachOFixupSectionGeneric32Bit(P KLDRMODMACHO pThis, uint8_t *pbSectBits, PKLDRMODMACHOSECT pFixupSect,251 static int kldrModMachOObjDoImports(PRTLDRMODMACHO pThis, RTLDRADDR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser); 252 static int kldrModMachOObjDoFixups(PRTLDRMODMACHO pThis, void *pvMapping, RTLDRADDR NewBaseAddress); 253 static int kldrModMachOFixupSectionGeneric32Bit(PRTLDRMODMACHO pThis, uint8_t *pbSectBits, PRTLDRMODMACHOSECT pFixupSect, 254 254 macho_nlist_32_t *paSyms, uint32_t cSyms, RTLDRADDR NewBaseAddress); 255 static int kldrModMachOFixupSectionAMD64(P KLDRMODMACHO pThis, uint8_t *pbSectBits, PKLDRMODMACHOSECT pFixupSect,255 static int kldrModMachOFixupSectionAMD64(PRTLDRMODMACHO pThis, uint8_t *pbSectBits, PRTLDRMODMACHOSECT pFixupSect, 256 256 macho_nlist_64_t *paSyms, uint32_t cSyms, RTLDRADDR NewBaseAddress); 257 257 258 static int kldrModMachOMakeGOT(P KLDRMODMACHO pThis, void *pvBits, RTLDRADDR NewBaseAddress);259 260 /*static int kldrModMachODoFixups(P KLDRMODMACHO pThis, void *pvMapping, RTLDRADDR NewBaseAddress, RTLDRADDR OldBaseAddress);261 static int kldrModMachODoImports(P KLDRMODMACHO pThis, void *pvMapping, PFNRTLDRIMPORT pfnGetImport, void *pvUser);*/258 static int kldrModMachOMakeGOT(PRTLDRMODMACHO pThis, void *pvBits, RTLDRADDR NewBaseAddress); 259 260 /*static int kldrModMachODoFixups(PRTLDRMODMACHO pThis, void *pvMapping, RTLDRADDR NewBaseAddress, RTLDRADDR OldBaseAddress); 261 static int kldrModMachODoImports(PRTLDRMODMACHO pThis, void *pvMapping, PFNRTLDRIMPORT pfnGetImport, void *pvUser);*/ 262 262 263 263 … … 268 268 */ 269 269 static int kldrModMachODoCreate(PRTLDRREADER pRdr, RTFOFF offImage, uint32_t fOpenFlags, 270 P KLDRMODMACHO *ppModMachO, PRTERRINFO pErrInfo)270 PRTLDRMODMACHO *ppModMachO, PRTERRINFO pErrInfo) 271 271 { 272 272 *ppModMachO = NULL; … … 357 357 * Calc the instance size, allocate and initialize it. 358 358 */ 359 size_t const cbModAndSegs = RT_ALIGN_Z(RT_UOFFSETOF_DYN( KLDRMODMACHO, aSegments[cSegments])360 + sizeof( KLDRMODMACHOSECT) * cSections, 16);361 P KLDRMODMACHO pThis = (PKLDRMODMACHO)RTMemAlloc(cbModAndSegs + cbStringPool);359 size_t const cbModAndSegs = RT_ALIGN_Z(RT_UOFFSETOF_DYN(RTLDRMODMACHO, aSegments[cSegments]) 360 + sizeof(RTLDRMODMACHOSECT) * cSections, 16); 361 PRTLDRMODMACHO pThis = (PRTLDRMODMACHO)RTMemAlloc(cbModAndSegs + cbStringPool); 362 362 if (!pThis) 363 363 return VERR_NO_MEMORY; … … 445 445 } 446 446 447 /* KLDRMODMACHO */447 /* RTLDRMODMACHO */ 448 448 pThis->cSegments = cSegments; 449 449 pThis->pvBits = NULL; … … 470 470 pThis->JmpStubsRVA = NIL_RTLDRADDR; 471 471 pThis->cSections = cSections; 472 pThis->paSections = (P KLDRMODMACHOSECT)&pThis->aSegments[pThis->cSegments];472 pThis->paSections = (PRTLDRMODMACHOSECT)&pThis->aSegments[pThis->cSegments]; 473 473 474 474 /* … … 560 560 * Convert and validate command header. 561 561 */ 562 KLDRMODMACHO_CHECK_RETURN(cbLeft >= sizeof(load_command_t), VERR_LDRMACHO_BAD_LOAD_COMMAND);562 RTLDRMODMACHO_CHECK_RETURN(cbLeft >= sizeof(load_command_t), VERR_LDRMACHO_BAD_LOAD_COMMAND); 563 563 if (fConvertEndian) 564 564 { … … 566 566 u.pLoadCmd->cmdsize = RT_BSWAP_U32(u.pLoadCmd->cmdsize); 567 567 } 568 KLDRMODMACHO_CHECK_RETURN(u.pLoadCmd->cmdsize <= cbLeft, VERR_LDRMACHO_BAD_LOAD_COMMAND);568 RTLDRMODMACHO_CHECK_RETURN(u.pLoadCmd->cmdsize <= cbLeft, VERR_LDRMACHO_BAD_LOAD_COMMAND); 569 569 cbLeft -= u.pLoadCmd->cmdsize; 570 570 pb += u.pLoadCmd->cmdsize; … … 584 584 585 585 /* Convert and verify the segment. */ 586 KLDRMODMACHO_CHECK_RETURN(u.pLoadCmd->cmdsize >= sizeof(segment_command_32_t), VERR_LDRMACHO_BAD_LOAD_COMMAND);587 KLDRMODMACHO_CHECK_RETURN( pHdr->magic == IMAGE_MACHO32_SIGNATURE_OE586 RTLDRMODMACHO_CHECK_RETURN(u.pLoadCmd->cmdsize >= sizeof(segment_command_32_t), VERR_LDRMACHO_BAD_LOAD_COMMAND); 587 RTLDRMODMACHO_CHECK_RETURN( pHdr->magic == IMAGE_MACHO32_SIGNATURE_OE 588 588 || pHdr->magic == IMAGE_MACHO32_SIGNATURE, VERR_LDRMACHO_BIT_MIX); 589 589 if (fConvertEndian) … … 613 613 *puEffFileType = uEffFileType = MH_OBJECT; \ 614 614 \ 615 KLDRMODMACHO_CHECK_RETURN( pSrcSeg->filesize == 0 \615 RTLDRMODMACHO_CHECK_RETURN( pSrcSeg->filesize == 0 \ 616 616 || ( pSrcSeg->fileoff <= cbFile \ 617 617 && (uint64_t)pSrcSeg->fileoff + pSrcSeg->filesize <= cbFile), \ 618 618 VERR_LDRMACHO_BAD_LOAD_COMMAND); \ 619 KLDRMODMACHO_CHECK_RETURN( pSrcSeg->filesize <= pSrcSeg->vmsize \619 RTLDRMODMACHO_CHECK_RETURN( pSrcSeg->filesize <= pSrcSeg->vmsize \ 620 620 || (fSkipSeg && !strcmp(pSrcSeg->segname, "__CTF") /* see above */), \ 621 621 VERR_LDRMACHO_BAD_LOAD_COMMAND); \ 622 KLDRMODMACHO_CHECK_RETURN(!(~pSrcSeg->maxprot & pSrcSeg->initprot), \622 RTLDRMODMACHO_CHECK_RETURN(!(~pSrcSeg->maxprot & pSrcSeg->initprot), \ 623 623 VERR_LDRMACHO_BAD_LOAD_COMMAND); \ 624 KLDRMODMACHO_CHECK_RETURN(!(pSrcSeg->flags & ~(SG_HIGHVM | SG_FVMLIB | SG_NORELOC | SG_PROTECTED_VERSION_1)), \624 RTLDRMODMACHO_CHECK_RETURN(!(pSrcSeg->flags & ~(SG_HIGHVM | SG_FVMLIB | SG_NORELOC | SG_PROTECTED_VERSION_1)), \ 625 625 VERR_LDRMACHO_BAD_LOAD_COMMAND); \ 626 KLDRMODMACHO_CHECK_RETURN( pSrcSeg->nsects * sizeof(section_##a_cBits##_t) \626 RTLDRMODMACHO_CHECK_RETURN( pSrcSeg->nsects * sizeof(section_##a_cBits##_t) \ 627 627 <= u.pLoadCmd->cmdsize - sizeof(segment_command_##a_cBits##_t), \ 628 628 VERR_LDRMACHO_BAD_LOAD_COMMAND); \ 629 KLDRMODMACHO_CHECK_RETURN( uEffFileType != MH_OBJECT \629 RTLDRMODMACHO_CHECK_RETURN( uEffFileType != MH_OBJECT \ 630 630 || cSegmentCommands == 0 \ 631 631 || ( cSegmentCommands == 1 \ … … 675 675 /* validate */ \ 676 676 if (uEffFileType != MH_OBJECT) \ 677 KLDRMODMACHO_CHECK_RETURN(!strcmp(pSect->segname, pSrcSeg->segname),\677 RTLDRMODMACHO_CHECK_RETURN(!strcmp(pSect->segname, pSrcSeg->segname),\ 678 678 VERR_LDRMACHO_BAD_SECTION); \ 679 679 \ … … 681 681 { \ 682 682 case S_ZEROFILL: \ 683 KLDRMODMACHO_CHECK_RETURN(!pSect->reserved1, VERR_LDRMACHO_BAD_SECTION); \684 KLDRMODMACHO_CHECK_RETURN(!pSect->reserved2, VERR_LDRMACHO_BAD_SECTION); \683 RTLDRMODMACHO_CHECK_RETURN(!pSect->reserved1, VERR_LDRMACHO_BAD_SECTION); \ 684 RTLDRMODMACHO_CHECK_RETURN(!pSect->reserved2, VERR_LDRMACHO_BAD_SECTION); \ 685 685 fFileBits = 0; \ 686 686 break; \ … … 691 691 case S_8BYTE_LITERALS: \ 692 692 case S_16BYTE_LITERALS: \ 693 KLDRMODMACHO_CHECK_RETURN(!pSect->reserved1, VERR_LDRMACHO_BAD_SECTION); \694 KLDRMODMACHO_CHECK_RETURN(!pSect->reserved2, VERR_LDRMACHO_BAD_SECTION); \693 RTLDRMODMACHO_CHECK_RETURN(!pSect->reserved1, VERR_LDRMACHO_BAD_SECTION); \ 694 RTLDRMODMACHO_CHECK_RETURN(!pSect->reserved2, VERR_LDRMACHO_BAD_SECTION); \ 695 695 fFileBits = 1; \ 696 696 break; \ 697 697 \ 698 698 case S_SYMBOL_STUBS: \ 699 KLDRMODMACHO_CHECK_RETURN(!pSect->reserved1, VERR_LDRMACHO_BAD_SECTION); \699 RTLDRMODMACHO_CHECK_RETURN(!pSect->reserved1, VERR_LDRMACHO_BAD_SECTION); \ 700 700 /* reserved2 == stub size. 0 has been seen (corecrypto.kext) */ \ 701 KLDRMODMACHO_CHECK_RETURN(pSect->reserved2 < 64, VERR_LDRMACHO_BAD_SECTION); \701 RTLDRMODMACHO_CHECK_RETURN(pSect->reserved2 < 64, VERR_LDRMACHO_BAD_SECTION); \ 702 702 fFileBits = 1; \ 703 703 break; \ … … 707 707 case S_LAZY_DYLIB_SYMBOL_POINTERS: \ 708 708 /* (reserved 1 = is indirect symbol table index) */ \ 709 KLDRMODMACHO_CHECK_RETURN(!pSect->reserved2, VERR_LDRMACHO_BAD_SECTION); \709 RTLDRMODMACHO_CHECK_RETURN(!pSect->reserved2, VERR_LDRMACHO_BAD_SECTION); \ 710 710 *pfCanLoad = false; \ 711 711 fFileBits = -1; /* __DATA.__got in the 64-bit mach_kernel has bits, any things without bits? */ \ … … 714 714 case S_MOD_INIT_FUNC_POINTERS: \ 715 715 /** @todo this requires a query API or flag... (e.g. C++ constructors) */ \ 716 KLDRMODMACHO_CHECK_RETURN(fOpenFlags & RTLDR_O_FOR_DEBUG, \716 RTLDRMODMACHO_CHECK_RETURN(fOpenFlags & RTLDR_O_FOR_DEBUG, \ 717 717 VERR_LDRMACHO_UNSUPPORTED_INIT_SECTION); \ 718 718 /* Falls through. */ \ 719 719 case S_MOD_TERM_FUNC_POINTERS: \ 720 720 /** @todo this requires a query API or flag... (e.g. C++ destructors) */ \ 721 KLDRMODMACHO_CHECK_RETURN(fOpenFlags & RTLDR_O_FOR_DEBUG, \721 RTLDRMODMACHO_CHECK_RETURN(fOpenFlags & RTLDR_O_FOR_DEBUG, \ 722 722 VERR_LDRMACHO_UNSUPPORTED_TERM_SECTION); \ 723 KLDRMODMACHO_CHECK_RETURN(!pSect->reserved1, VERR_LDRMACHO_BAD_SECTION); \724 KLDRMODMACHO_CHECK_RETURN(!pSect->reserved2, VERR_LDRMACHO_BAD_SECTION); \723 RTLDRMODMACHO_CHECK_RETURN(!pSect->reserved1, VERR_LDRMACHO_BAD_SECTION); \ 724 RTLDRMODMACHO_CHECK_RETURN(!pSect->reserved2, VERR_LDRMACHO_BAD_SECTION); \ 725 725 fFileBits = 1; \ 726 726 break; /* ignored */ \ … … 728 728 case S_LITERAL_POINTERS: \ 729 729 case S_DTRACE_DOF: \ 730 KLDRMODMACHO_CHECK_RETURN(!pSect->reserved1, VERR_LDRMACHO_BAD_SECTION); \731 KLDRMODMACHO_CHECK_RETURN(!pSect->reserved2, VERR_LDRMACHO_BAD_SECTION); \730 RTLDRMODMACHO_CHECK_RETURN(!pSect->reserved1, VERR_LDRMACHO_BAD_SECTION); \ 731 RTLDRMODMACHO_CHECK_RETURN(!pSect->reserved2, VERR_LDRMACHO_BAD_SECTION); \ 732 732 fFileBits = 1; \ 733 733 break; \ … … 735 735 case S_INTERPOSING: \ 736 736 case S_GB_ZEROFILL: \ 737 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_UNSUPPORTED_SECTION); \737 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_UNSUPPORTED_SECTION); \ 738 738 \ 739 739 default: \ 740 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_UNKNOWN_SECTION); \740 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_UNKNOWN_SECTION); \ 741 741 } \ 742 KLDRMODMACHO_CHECK_RETURN(!(pSect->flags & ~( S_ATTR_PURE_INSTRUCTIONS | S_ATTR_NO_TOC | S_ATTR_STRIP_STATIC_SYMS \742 RTLDRMODMACHO_CHECK_RETURN(!(pSect->flags & ~( S_ATTR_PURE_INSTRUCTIONS | S_ATTR_NO_TOC | S_ATTR_STRIP_STATIC_SYMS \ 743 743 | S_ATTR_NO_DEAD_STRIP | S_ATTR_LIVE_SUPPORT | S_ATTR_SELF_MODIFYING_CODE \ 744 744 | S_ATTR_DEBUG | S_ATTR_SOME_INSTRUCTIONS | S_ATTR_EXT_RELOC \ 745 745 | S_ATTR_LOC_RELOC | SECTION_TYPE)), \ 746 746 VERR_LDRMACHO_BAD_SECTION); \ 747 KLDRMODMACHO_CHECK_RETURN((pSect->flags & S_ATTR_DEBUG) == (pFirstSect->flags & S_ATTR_DEBUG), \747 RTLDRMODMACHO_CHECK_RETURN((pSect->flags & S_ATTR_DEBUG) == (pFirstSect->flags & S_ATTR_DEBUG), \ 748 748 VERR_LDRMACHO_MIXED_DEBUG_SECTION_FLAGS); \ 749 749 \ 750 KLDRMODMACHO_CHECK_RETURN(pSect->addr - pSrcSeg->vmaddr <= pSrcSeg->vmsize, \750 RTLDRMODMACHO_CHECK_RETURN(pSect->addr - pSrcSeg->vmaddr <= pSrcSeg->vmsize, \ 751 751 VERR_LDRMACHO_BAD_SECTION); \ 752 KLDRMODMACHO_CHECK_RETURN( pSect->addr - pSrcSeg->vmaddr + pSect->size <= pSrcSeg->vmsize \752 RTLDRMODMACHO_CHECK_RETURN( pSect->addr - pSrcSeg->vmaddr + pSect->size <= pSrcSeg->vmsize \ 753 753 || !strcmp(pSrcSeg->segname, "__CTF") /* see above */, \ 754 754 VERR_LDRMACHO_BAD_SECTION); \ 755 KLDRMODMACHO_CHECK_RETURN(pSect->align < 31, \755 RTLDRMODMACHO_CHECK_RETURN(pSect->align < 31, \ 756 756 VERR_LDRMACHO_BAD_SECTION); \ 757 757 /* Workaround for buggy ld64 (or as, llvm, ++) that produces a misaligned __TEXT.__unwind_info. */ \ … … 761 761 && strcmp(pSect->sectname, "__unwind_info") == 0) \ 762 762 pSect->align = 2; \ 763 KLDRMODMACHO_CHECK_RETURN(!((RT_BIT_32(pSect->align) - UINT32_C(1)) & pSect->addr), \763 RTLDRMODMACHO_CHECK_RETURN(!((RT_BIT_32(pSect->align) - UINT32_C(1)) & pSect->addr), \ 764 764 VERR_LDRMACHO_BAD_SECTION); \ 765 KLDRMODMACHO_CHECK_RETURN(!((RT_BIT_32(pSect->align) - UINT32_C(1)) & pSrcSeg->vmaddr), \765 RTLDRMODMACHO_CHECK_RETURN(!((RT_BIT_32(pSect->align) - UINT32_C(1)) & pSrcSeg->vmaddr), \ 766 766 VERR_LDRMACHO_BAD_SECTION); \ 767 767 \ … … 770 770 if (pSect->addr) \ 771 771 { \ 772 KLDRMODMACHO_CHECK_RETURN(offSect <= pSect->addr - pSrcSeg->vmaddr, VERR_LDRMACHO_BAD_SECTION); \772 RTLDRMODMACHO_CHECK_RETURN(offSect <= pSect->addr - pSrcSeg->vmaddr, VERR_LDRMACHO_BAD_SECTION); \ 773 773 if (offSect < pSect->addr - pSrcSeg->vmaddr) \ 774 774 offSect = pSect->addr - pSrcSeg->vmaddr; \ … … 781 781 if (uEffFileType != MH_OBJECT) \ 782 782 { \ 783 KLDRMODMACHO_CHECK_RETURN(pSect->offset == pSrcSeg->fileoff + offSect, \783 RTLDRMODMACHO_CHECK_RETURN(pSect->offset == pSrcSeg->fileoff + offSect, \ 784 784 VERR_LDRMACHO_NON_CONT_SEG_BITS); \ 785 KLDRMODMACHO_CHECK_RETURN(pSect->offset - pSrcSeg->fileoff <= pSrcSeg->filesize, \785 RTLDRMODMACHO_CHECK_RETURN(pSect->offset - pSrcSeg->fileoff <= pSrcSeg->filesize, \ 786 786 VERR_LDRMACHO_BAD_SECTION); \ 787 787 } \ 788 KLDRMODMACHO_CHECK_RETURN(pSect->offset <= cbFile, \788 RTLDRMODMACHO_CHECK_RETURN(pSect->offset <= cbFile, \ 789 789 VERR_LDRMACHO_BAD_SECTION); \ 790 KLDRMODMACHO_CHECK_RETURN((uint64_t)pSect->offset + pSect->size <= cbFile, \790 RTLDRMODMACHO_CHECK_RETURN((uint64_t)pSect->offset + pSect->size <= cbFile, \ 791 791 VERR_LDRMACHO_BAD_SECTION); \ 792 792 } \ 793 793 else \ 794 KLDRMODMACHO_CHECK_RETURN(pSect->offset == 0, VERR_LDRMACHO_BAD_SECTION); \794 RTLDRMODMACHO_CHECK_RETURN(pSect->offset == 0, VERR_LDRMACHO_BAD_SECTION); \ 795 795 \ 796 796 if (!pSect->nreloc) \ 797 KLDRMODMACHO_CHECK_RETURN(!pSect->reloff, \797 RTLDRMODMACHO_CHECK_RETURN(!pSect->reloff, \ 798 798 VERR_LDRMACHO_BAD_SECTION); \ 799 799 else \ 800 800 { \ 801 KLDRMODMACHO_CHECK_RETURN(pSect->reloff <= cbFile, \801 RTLDRMODMACHO_CHECK_RETURN(pSect->reloff <= cbFile, \ 802 802 VERR_LDRMACHO_BAD_SECTION); \ 803 KLDRMODMACHO_CHECK_RETURN( (uint64_t)pSect->reloff \803 RTLDRMODMACHO_CHECK_RETURN( (uint64_t)pSect->reloff \ 804 804 + (RTFOFF)pSect->nreloc * sizeof(macho_relocation_info_t) \ 805 805 <= cbFile, \ … … 829 829 break; \ 830 830 default: \ 831 KLDRMODMACHO_FAILED_RETURN(VERR_INVALID_PARAMETER); \831 RTLDRMODMACHO_FAILED_RETURN(VERR_INVALID_PARAMETER); \ 832 832 } \ 833 833 \ … … 853 853 854 854 /* Convert and verify the segment. */ 855 KLDRMODMACHO_CHECK_RETURN(u.pLoadCmd->cmdsize >= sizeof(segment_command_64_t), VERR_LDRMACHO_BAD_LOAD_COMMAND);856 KLDRMODMACHO_CHECK_RETURN( pHdr->magic == IMAGE_MACHO64_SIGNATURE_OE855 RTLDRMODMACHO_CHECK_RETURN(u.pLoadCmd->cmdsize >= sizeof(segment_command_64_t), VERR_LDRMACHO_BAD_LOAD_COMMAND); 856 RTLDRMODMACHO_CHECK_RETURN( pHdr->magic == IMAGE_MACHO64_SIGNATURE_OE 857 857 || pHdr->magic == IMAGE_MACHO64_SIGNATURE, VERR_LDRMACHO_BIT_MIX); 858 858 if (fConvertEndian) … … 915 915 if ( u.pSymTab->symoff >= cbFile 916 916 || (uint64_t)u.pSymTab->symoff + u.pSymTab->nsyms * cbSym > cbFile) 917 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND);917 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND); 918 918 if ( u.pSymTab->stroff >= cbFile 919 919 || (uint64_t)u.pSymTab->stroff + u.pSymTab->strsize > cbFile) 920 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND);920 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND); 921 921 922 922 /* only one string in objects, please. */ … … 924 924 if ( uEffFileType == MH_OBJECT 925 925 && cSymbolTabs != 1) 926 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_OBJECT_FILE);926 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_OBJECT_FILE); 927 927 break; 928 928 } … … 941 941 /* convert & verify header items ([0] == flavor, [1] == uint32_t count). */ 942 942 if (cItemsLeft < 2) 943 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND);943 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND); 944 944 if (fConvertEndian) 945 945 { … … 948 948 } 949 949 if (pu32[1] + 2 > cItemsLeft) 950 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND);950 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND); 951 951 952 952 /* convert & verify according to flavor. */ … … 967 967 case LC_UUID: 968 968 if (u.pUuid->cmdsize != sizeof(uuid_command_t)) 969 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND);969 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND); 970 970 /** @todo Check anything here need converting? */ 971 971 break; … … 973 973 case LC_CODE_SIGNATURE: 974 974 if (u.pUuid->cmdsize != sizeof(linkedit_data_command_t)) 975 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND);975 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND); 976 976 break; 977 977 … … 979 979 case LC_VERSION_MIN_IPHONEOS: 980 980 if (u.pUuid->cmdsize != sizeof(version_min_command_t)) 981 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND);981 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND); 982 982 break; 983 983 … … 1007 1007 /** @todo valid command size. */ 1008 1008 if (!(fOpenFlags & RTLDR_O_FOR_DEBUG)) 1009 KLDRMODMACHO_FAILED_RETURN(RTErrInfoSetF(pErrInfo, VERR_LDRMACHO_UNSUPPORTED_LOAD_COMMAND,1009 RTLDRMODMACHO_FAILED_RETURN(RTErrInfoSetF(pErrInfo, VERR_LDRMACHO_UNSUPPORTED_LOAD_COMMAND, 1010 1010 "cmd=%#x", u.pLoadCmd->cmd)); 1011 1011 *pfCanLoad = false; … … 1026 1026 case LC_PREBIND_CKSUM: 1027 1027 case LC_SYMSEG: 1028 KLDRMODMACHO_FAILED_RETURN(RTErrInfoSetF(pErrInfo, VERR_LDRMACHO_UNSUPPORTED_LOAD_COMMAND,1028 RTLDRMODMACHO_FAILED_RETURN(RTErrInfoSetF(pErrInfo, VERR_LDRMACHO_UNSUPPORTED_LOAD_COMMAND, 1029 1029 "cmd=%#x", u.pLoadCmd->cmd)); 1030 1030 1031 1031 default: 1032 KLDRMODMACHO_FAILED_RETURN(RTErrInfoSetF(pErrInfo, VERR_LDRMACHO_UNKNOWN_LOAD_COMMAND,1032 RTLDRMODMACHO_FAILED_RETURN(RTErrInfoSetF(pErrInfo, VERR_LDRMACHO_UNKNOWN_LOAD_COMMAND, 1033 1033 "cmd=%#x", u.pLoadCmd->cmd)); 1034 1034 } … … 1037 1037 /* be strict. */ 1038 1038 if (cbLeft) 1039 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND);1039 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_LOAD_COMMAND); 1040 1040 1041 1041 switch (uEffFileType) … … 1048 1048 case MH_KEXT_BUNDLE: 1049 1049 if (!cSegments) 1050 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_OBJECT_FILE);1050 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_OBJECT_FILE); 1051 1051 break; 1052 1052 } … … 1070 1070 * @param cbStringPool The size of the string pool. 1071 1071 */ 1072 static int kldrModMachOParseLoadCommands(P KLDRMODMACHO pThis, char *pbStringPool, uint32_t cbStringPool)1072 static int kldrModMachOParseLoadCommands(PRTLDRMODMACHO pThis, char *pbStringPool, uint32_t cbStringPool) 1073 1073 { 1074 1074 union … … 1084 1084 uint32_t cbLeft = pThis->Hdr.sizeofcmds; 1085 1085 const uint8_t *pb = pThis->pbLoadCommands; 1086 P KLDRMODMACHOSEG pDstSeg = &pThis->aSegments[0];1087 P KLDRMODMACHOSECT pSectExtra = pThis->paSections;1086 PRTLDRMODMACHOSEG pDstSeg = &pThis->aSegments[0]; 1087 PRTLDRMODMACHOSECT pSectExtra = pThis->paSections; 1088 1088 const uint32_t cSegments = pThis->cSegments; 1089 P KLDRMODMACHOSEG pSegItr;1089 PRTLDRMODMACHOSEG pSegItr; 1090 1090 RT_NOREF(cbStringPool); 1091 1091 … … 1169 1169 for (pSegItr = &pThis->aSegments[0]; pSegItr != pDstSeg; pSegItr++) \ 1170 1170 if (!strncmp(pSegItr->SegInfo.pszName, pSrcSeg->segname, sizeof(pSrcSeg->segname))) \ 1171 KLDRMODMACHO_FAILED_RETURN(VERR_LDR_DUPLICATE_SEGMENT_NAME); \1171 RTLDRMODMACHO_FAILED_RETURN(VERR_LDR_DUPLICATE_SEGMENT_NAME); \ 1172 1172 \ 1173 1173 /* \ … … 1287 1287 { 1288 1288 bool fLoadLinkEdit = false; 1289 P KLDRMODMACHOSECTpSectExtraItr;1289 PRTLDRMODMACHOSECT pSectExtraItr; 1290 1290 RTLDRADDR uNextRVA = 0; 1291 1291 RTLDRADDR cb; … … 1325 1325 for (pDstSeg = &pThis->aSegments[0]; c-- > 0; pDstSeg++) 1326 1326 { 1327 uNextRVA = RTLDR_ALIGN_ADDR(uNextRVA, pDstSeg->SegInfo.Alignment); 1327 1328 cb = pDstSeg->SegInfo.RVA - uNextRVA; 1328 1329 if (cb >= 0x00100000) /* 1MB */ … … 1331 1332 //pThis->pMod->fFlags |= KLDRMOD_FLAGS_NON_CONTIGUOUS_LINK_ADDRS; 1332 1333 } 1333 uNextRVA = pDstSeg->SegInfo.RVA + RTLDR_ALIGN_ADDR(pDstSeg->SegInfo.cb, pDstSeg->SegInfo.Alignment);1334 uNextRVA = pDstSeg->SegInfo.RVA + pDstSeg->SegInfo.cb; 1334 1335 } 1335 1336 … … 1422 1423 static DECLCALLBACK(int) rtldrMachO_Close(PRTLDRMODINTERNAL pMod) 1423 1424 { 1424 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);1425 KLDRMODMACHO_ASSERT(!pThis->pvMapping);1425 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 1426 RTLDRMODMACHO_ASSERT(!pThis->pvMapping); 1426 1427 1427 1428 uint32_t i = pThis->cSegments; … … 1453 1454 * @param pBaseAddress The base address, IN & OUT. Optional. 1454 1455 */ 1455 static void kldrModMachOAdjustBaseAddress(P KLDRMODMACHO pThis, PRTLDRADDR pBaseAddress)1456 static void kldrModMachOAdjustBaseAddress(PRTLDRMODMACHO pThis, PRTLDRADDR pBaseAddress) 1456 1457 { 1457 1458 /* … … 1477 1478 * @param puValue Where to return the symbol value. 1478 1479 */ 1479 static int kldrModMachOQueryLinkerSymbol(P KLDRMODMACHO pThis, const char *pchSymbol, size_t cchSymbol,1480 static int kldrModMachOQueryLinkerSymbol(PRTLDRMODMACHO pThis, const char *pchSymbol, size_t cchSymbol, 1480 1481 RTLDRADDR BaseAddress, PRTLDRADDR puValue) 1481 1482 { … … 1614 1615 uint32_t iOrdinal, const char *pszSymbol, RTUINTPTR *pValue) 1615 1616 { 1616 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);1617 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 1617 1618 RT_NOREF(pvBits); 1618 1619 //RT_NOREF(pszVersion); … … 1631 1632 * Refuse segmented requests for now. 1632 1633 */ 1633 KLDRMODMACHO_CHECK_RETURN( !pfKind1634 RTLDRMODMACHO_CHECK_RETURN( !pfKind 1634 1635 || (*pfKind & RTLDRSYMKIND_REQ_TYPE_MASK) == RTLDRSYMKIND_REQ_FLAT, 1635 1636 VERR_LDRMACHO_TODO); … … 1701 1702 * @param pfKind See kLdrModQuerySymbol. 1702 1703 */ 1703 static int kldrModMachODoQuerySymbol32Bit(P KLDRMODMACHO pThis, const macho_nlist_32_t *paSyms, uint32_t cSyms,1704 static int kldrModMachODoQuerySymbol32Bit(PRTLDRMODMACHO pThis, const macho_nlist_32_t *paSyms, uint32_t cSyms, 1704 1705 const char *pchStrings, uint32_t cchStrings, RTLDRADDR BaseAddress, uint32_t iSymbol, 1705 1706 const char *pchSymbol, uint32_t cchSymbol, PRTLDRADDR puValue, uint32_t *pfKind) … … 1775 1776 case MACHO_N_SECT: 1776 1777 { 1777 P KLDRMODMACHOSECT pSect;1778 PRTLDRMODMACHOSECT pSect; 1778 1779 RTLDRADDR offSect; 1779 KLDRMODMACHO_CHECK_RETURN((uint32_t)(paSyms[iSymbol].n_sect - 1) < pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL);1780 RTLDRMODMACHO_CHECK_RETURN((uint32_t)(paSyms[iSymbol].n_sect - 1) < pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL); 1780 1781 pSect = &pThis->paSections[paSyms[iSymbol].n_sect - 1]; 1781 1782 1782 1783 offSect = paSyms[iSymbol].n_value - pSect->LinkAddress; 1783 KLDRMODMACHO_CHECK_RETURN( offSect <= pSect->cb1784 RTLDRMODMACHO_CHECK_RETURN( offSect <= pSect->cb 1784 1785 || ( paSyms[iSymbol].n_sect == 1 /* special hack for __mh_execute_header */ 1785 1786 && offSect == 0U - pSect->RVA … … 1806 1807 /** @todo implement indirect and prebound symbols. */ 1807 1808 default: 1808 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);1809 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 1809 1810 } 1810 1811 … … 1829 1830 * @param pfKind See kLdrModQuerySymbol. 1830 1831 */ 1831 static int kldrModMachODoQuerySymbol64Bit(P KLDRMODMACHO pThis, const macho_nlist_64_t *paSyms, uint32_t cSyms,1832 static int kldrModMachODoQuerySymbol64Bit(PRTLDRMODMACHO pThis, const macho_nlist_64_t *paSyms, uint32_t cSyms, 1832 1833 const char *pchStrings, uint32_t cchStrings, RTLDRADDR BaseAddress, uint32_t iSymbol, 1833 1834 const char *pchSymbol, uint32_t cchSymbol, PRTLDRADDR puValue, uint32_t *pfKind) … … 1903 1904 case MACHO_N_SECT: 1904 1905 { 1905 P KLDRMODMACHOSECT pSect;1906 PRTLDRMODMACHOSECT pSect; 1906 1907 RTLDRADDR offSect; 1907 KLDRMODMACHO_CHECK_RETURN((uint32_t)(paSyms[iSymbol].n_sect - 1) < pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL);1908 RTLDRMODMACHO_CHECK_RETURN((uint32_t)(paSyms[iSymbol].n_sect - 1) < pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL); 1908 1909 pSect = &pThis->paSections[paSyms[iSymbol].n_sect - 1]; 1909 1910 1910 1911 offSect = paSyms[iSymbol].n_value - pSect->LinkAddress; 1911 KLDRMODMACHO_CHECK_RETURN( offSect <= pSect->cb1912 RTLDRMODMACHO_CHECK_RETURN( offSect <= pSect->cb 1912 1913 || ( paSyms[iSymbol].n_sect == 1 /* special hack for __mh_execute_header */ 1913 1914 && offSect == 0U - pSect->RVA … … 1934 1935 /** @todo implement indirect and prebound symbols. */ 1935 1936 default: 1936 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);1937 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 1937 1938 } 1938 1939 … … 1947 1948 RTUINTPTR BaseAddress, PFNRTLDRENUMSYMS pfnCallback, void *pvUser) 1948 1949 { 1949 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);1950 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 1950 1951 RT_NOREF(pvBits); 1951 1952 … … 1981 1982 } 1982 1983 else 1983 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);1984 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 1984 1985 1985 1986 return rc; … … 2001 2002 * @param pvUser See kLdrModEnumSymbols. 2002 2003 */ 2003 static int kldrModMachODoEnumSymbols32Bit(P KLDRMODMACHO pThis, const macho_nlist_32_t *paSyms, uint32_t cSyms,2004 static int kldrModMachODoEnumSymbols32Bit(PRTLDRMODMACHO pThis, const macho_nlist_32_t *paSyms, uint32_t cSyms, 2004 2005 const char *pchStrings, uint32_t cchStrings, RTLDRADDR BaseAddress, 2005 2006 uint32_t fFlags, PFNRTLDRENUMSYMS pfnCallback, void *pvUser) … … 2043 2044 2044 2045 /* name */ 2045 KLDRMODMACHO_CHECK_RETURN((uint32_t)paSyms[iSym].n_un.n_strx < cchStrings, VERR_LDRMACHO_BAD_SYMBOL);2046 RTLDRMODMACHO_CHECK_RETURN((uint32_t)paSyms[iSym].n_un.n_strx < cchStrings, VERR_LDRMACHO_BAD_SYMBOL); 2046 2047 psz = &pchStrings[paSyms[iSym].n_un.n_strx]; 2047 2048 cch = strlen(psz); … … 2057 2058 case MACHO_N_SECT: 2058 2059 { 2059 P KLDRMODMACHOSECT pSect;2060 KLDRMODMACHO_CHECK_RETURN((uint32_t)(paSyms[iSym].n_sect - 1) < pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL);2060 PRTLDRMODMACHOSECT pSect; 2061 RTLDRMODMACHO_CHECK_RETURN((uint32_t)(paSyms[iSym].n_sect - 1) < pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL); 2061 2062 pSect = &pThis->paSections[paSyms[iSym].n_sect - 1]; 2062 2063 2063 2064 uValue = paSyms[iSym].n_value - pSect->LinkAddress; 2064 KLDRMODMACHO_CHECK_RETURN( uValue <= pSect->cb2065 RTLDRMODMACHO_CHECK_RETURN( uValue <= pSect->cb 2065 2066 || ( paSyms[iSym].n_sect == 1 /* special hack for __mh_execute_header */ 2066 2067 && uValue == 0U - pSect->RVA … … 2085 2086 /** @todo implement indirect and prebound symbols. */ 2086 2087 default: 2087 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);2088 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 2088 2089 } 2089 2090 … … 2113 2114 * @param pvUser See kLdrModEnumSymbols. 2114 2115 */ 2115 static int kldrModMachODoEnumSymbols64Bit(P KLDRMODMACHO pThis, const macho_nlist_64_t *paSyms, uint32_t cSyms,2116 static int kldrModMachODoEnumSymbols64Bit(PRTLDRMODMACHO pThis, const macho_nlist_64_t *paSyms, uint32_t cSyms, 2116 2117 const char *pchStrings, uint32_t cchStrings, RTLDRADDR BaseAddress, 2117 2118 uint32_t fFlags, PFNRTLDRENUMSYMS pfnCallback, void *pvUser) … … 2155 2156 2156 2157 /* name */ 2157 KLDRMODMACHO_CHECK_RETURN((uint32_t)paSyms[iSym].n_un.n_strx < cchStrings, VERR_LDRMACHO_BAD_SYMBOL);2158 RTLDRMODMACHO_CHECK_RETURN((uint32_t)paSyms[iSym].n_un.n_strx < cchStrings, VERR_LDRMACHO_BAD_SYMBOL); 2158 2159 psz = &pchStrings[paSyms[iSym].n_un.n_strx]; 2159 2160 cch = strlen(psz); … … 2169 2170 case MACHO_N_SECT: 2170 2171 { 2171 P KLDRMODMACHOSECT pSect;2172 KLDRMODMACHO_CHECK_RETURN((uint32_t)(paSyms[iSym].n_sect - 1) < pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL);2172 PRTLDRMODMACHOSECT pSect; 2173 RTLDRMODMACHO_CHECK_RETURN((uint32_t)(paSyms[iSym].n_sect - 1) < pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL); 2173 2174 pSect = &pThis->paSections[paSyms[iSym].n_sect - 1]; 2174 2175 2175 2176 uValue = paSyms[iSym].n_value - pSect->LinkAddress; 2176 KLDRMODMACHO_CHECK_RETURN( uValue <= pSect->cb2177 RTLDRMODMACHO_CHECK_RETURN( uValue <= pSect->cb 2177 2178 || ( paSyms[iSym].n_sect == 1 /* special hack for __mh_execute_header */ 2178 2179 && uValue == 0U - pSect->RVA … … 2197 2198 /** @todo implement indirect and prebound symbols. */ 2198 2199 default: 2199 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);2200 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 2200 2201 } 2201 2202 … … 2215 2216 static int kldrModMachOGetImport(PRTLDRMODINTERNAL pMod, const void *pvBits, uint32_t iImport, char *pszName, size_t cchName) 2216 2217 { 2217 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);2218 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 2218 2219 RT_NOREF(pvBits); 2219 2220 RT_NOREF(iImport); … … 2233 2234 static int32_t kldrModMachONumberOfImports(PRTLDRMODINTERNAL pMod, const void *pvBits) 2234 2235 { 2235 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);2236 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 2236 2237 RT_NOREF(pvBits); 2237 2238 … … 2247 2248 static int kldrModMachOGetStackInfo(PRTLDRMODINTERNAL pMod, const void *pvBits, RTLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo) 2248 2249 { 2249 /*P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);*/2250 /*PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core);*/ 2250 2251 RT_NOREF(pMod); 2251 2252 RT_NOREF(pvBits); … … 2265 2266 { 2266 2267 #if 0 2267 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);2268 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 2268 2269 int rc; 2269 2270 … … 2298 2299 static DECLCALLBACK(int) rtldrMachO_EnumDbgInfo(PRTLDRMODINTERNAL pMod, const void *pvBits, PFNRTLDRENUMDBG pfnCallback, void *pvUser) 2299 2300 { 2300 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);2301 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 2301 2302 int rc = VINF_SUCCESS; 2302 2303 uint32_t iSect; … … 2335 2336 static int kldrModMachOHasDbgInfo(PRTLDRMODINTERNAL pMod, const void *pvBits) 2336 2337 { 2337 /*P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);*/2338 /*PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core);*/ 2338 2339 2339 2340 #if 0 … … 2357 2358 static int kldrModMachOMap(PRTLDRMODINTERNAL pMod) 2358 2359 { 2359 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);2360 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 2360 2361 unsigned fFixed; 2361 2362 uint32_t i; … … 2409 2410 static int kldrModMachOUnmap(PRTLDRMODINTERNAL pMod) 2410 2411 { 2411 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);2412 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 2412 2413 uint32_t i; 2413 2414 int rc; … … 2440 2441 static int kldrModMachOAllocTLS(PRTLDRMODINTERNAL pMod, void *pvMapping) 2441 2442 { 2442 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);2443 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 2443 2444 2444 2445 /* … … 2464 2465 static int kldrModMachOReload(PRTLDRMODINTERNAL pMod) 2465 2466 { 2466 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);2467 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 2467 2468 2468 2469 /* … … 2480 2481 static int kldrModMachOFixupMapping(PRTLDRMODINTERNAL pMod, PFNRTLDRIMPORT pfnGetImport, void *pvUser) 2481 2482 { 2482 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);2483 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 2483 2484 int rc, rc2; 2484 2485 … … 2522 2523 * @param pvUser User argument to the callback. 2523 2524 */ 2524 static int kldrModMachOObjDoImports(P KLDRMODMACHO pThis, RTLDRADDR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser)2525 static int kldrModMachOObjDoImports(PRTLDRMODMACHO pThis, RTLDRADDR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser) 2525 2526 { 2526 2527 const uint32_t cSyms = pThis->cSymbols; … … 2556 2557 2557 2558 /** @todo Implement N_REF_TO_WEAK. */ 2558 KLDRMODMACHO_CHECK_RETURN(!(paSyms[iSym].n_desc & N_REF_TO_WEAK), VERR_LDRMACHO_TODO);2559 RTLDRMODMACHO_CHECK_RETURN(!(paSyms[iSym].n_desc & N_REF_TO_WEAK), VERR_LDRMACHO_TODO); 2559 2560 2560 2561 /* Get the symbol name. */ 2561 KLDRMODMACHO_CHECK_RETURN((uint32_t)paSyms[iSym].n_un.n_strx < pThis->cchStrings, VERR_LDRMACHO_BAD_SYMBOL);2562 RTLDRMODMACHO_CHECK_RETURN((uint32_t)paSyms[iSym].n_un.n_strx < pThis->cchStrings, VERR_LDRMACHO_BAD_SYMBOL); 2562 2563 pszSymbol = &pThis->pchStrings[paSyms[iSym].n_un.n_strx]; 2563 2564 cchSymbol = strlen(pszSymbol); … … 2615 2616 2616 2617 /** @todo Implement N_REF_TO_WEAK. */ 2617 KLDRMODMACHO_CHECK_RETURN(!(paSyms[iSym].n_desc & N_REF_TO_WEAK), VERR_LDRMACHO_TODO);2618 RTLDRMODMACHO_CHECK_RETURN(!(paSyms[iSym].n_desc & N_REF_TO_WEAK), VERR_LDRMACHO_TODO); 2618 2619 2619 2620 /* Get the symbol name. */ 2620 KLDRMODMACHO_CHECK_RETURN(paSyms[iSym].n_un.n_strx < pThis->cchStrings, VERR_LDRMACHO_BAD_SYMBOL);2621 RTLDRMODMACHO_CHECK_RETURN(paSyms[iSym].n_un.n_strx < pThis->cchStrings, VERR_LDRMACHO_BAD_SYMBOL); 2621 2622 pszSymbol = &pThis->pchStrings[paSyms[iSym].n_un.n_strx]; 2622 2623 cchSymbol = strlen(pszSymbol); … … 2669 2670 * @param NewBaseAddress The address to fixup the mapping to. 2670 2671 */ 2671 static int kldrModMachOObjDoFixups(P KLDRMODMACHO pThis, void *pvMapping, RTLDRADDR NewBaseAddress)2672 static int kldrModMachOObjDoFixups(PRTLDRMODMACHO pThis, void *pvMapping, RTLDRADDR NewBaseAddress) 2672 2673 { 2673 2674 /* … … 2684 2685 for (uint32_t iSeg = 0; RT_SUCCESS(rc) && iSeg < pThis->cSegments; iSeg++) 2685 2686 { 2686 P KLDRMODMACHOSEG pSeg = &pThis->aSegments[iSeg];2687 PRTLDRMODMACHOSEG pSeg = &pThis->aSegments[iSeg]; 2687 2688 for (uint32_t iSect = 0; iSect < pSeg->cSections; iSect++) 2688 2689 { 2689 P KLDRMODMACHOSECT pSect = &pSeg->paSections[iSect];2690 PRTLDRMODMACHOSECT pSect = &pSeg->paSections[iSect]; 2690 2691 2691 2692 /* skip sections without fixups. */ … … 2715 2716 pThis->cSymbols, NewBaseAddress); 2716 2717 else 2717 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);2718 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 2718 2719 if (RT_FAILURE(rc)) 2719 2720 break; … … 2737 2738 * @param NewBaseAddress The new base image address. 2738 2739 */ 2739 static int kldrModMachOFixupSectionGeneric32Bit(P KLDRMODMACHO pThis, uint8_t *pbSectBits, PKLDRMODMACHOSECT pFixupSect,2740 static int kldrModMachOFixupSectionGeneric32Bit(PRTLDRMODMACHO pThis, uint8_t *pbSectBits, PRTLDRMODMACHOSECT pFixupSect, 2740 2741 macho_nlist_32_t *paSyms, uint32_t cSyms, RTLDRADDR NewBaseAddress) 2741 2742 { … … 2815 2816 case MACHO_N_SECT: 2816 2817 { 2817 P KLDRMODMACHOSECT pSymSect;2818 KLDRMODMACHO_CHECK_RETURN((uint32_t)pSym->n_sect - 1 <= pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL);2818 PRTLDRMODMACHOSECT pSymSect; 2819 RTLDRMODMACHO_CHECK_RETURN((uint32_t)pSym->n_sect - 1 <= pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL); 2819 2820 pSymSect = &pThis->paSections[pSym->n_sect - 1]; 2820 2821 … … 2830 2831 case MACHO_N_INDR: 2831 2832 case MACHO_N_PBUD: 2832 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);2833 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 2833 2834 default: 2834 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_SYMBOL);2835 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_SYMBOL); 2835 2836 } 2836 2837 } 2837 2838 else if (Fixup.r.r_symbolnum != R_ABS) 2838 2839 { 2839 P KLDRMODMACHOSECT pSymSect;2840 PRTLDRMODMACHOSECT pSymSect; 2840 2841 if (Fixup.r.r_symbolnum > pThis->cSections) 2841 2842 return VERR_LDR_BAD_FIXUP; … … 2852 2853 else 2853 2854 { 2854 P KLDRMODMACHOSECT pSymSect;2855 PRTLDRMODMACHOSECT pSymSect; 2855 2856 uint32_t iSymSect; 2856 2857 RTLDRADDR Value; 2857 2858 2858 2859 /* sanity */ 2859 KLDRMODMACHO_ASSERT(Fixup.s.r_scattered);2860 RTLDRMODMACHO_ASSERT(Fixup.s.r_scattered); 2860 2861 if ((uint32_t)Fixup.s.r_address >= cbSectBits) 2861 2862 return VERR_LDR_BAD_FIXUP; … … 2940 2941 * @param NewBaseAddress The new base image address. 2941 2942 */ 2942 static int kldrModMachOFixupSectionAMD64(P KLDRMODMACHO pThis, uint8_t *pbSectBits, PKLDRMODMACHOSECT pFixupSect,2943 static int kldrModMachOFixupSectionAMD64(PRTLDRMODMACHO pThis, uint8_t *pbSectBits, PRTLDRMODMACHOSECT pFixupSect, 2943 2944 macho_nlist_64_t *paSyms, uint32_t cSyms, RTLDRADDR NewBaseAddress) 2944 2945 { … … 2977 2978 2978 2979 /* AMD64 doesn't use scattered fixups. */ 2979 KLDRMODMACHO_CHECK_RETURN(!(Fixup.r.r_address & R_SCATTERED), VERR_LDR_BAD_FIXUP);2980 RTLDRMODMACHO_CHECK_RETURN(!(Fixup.r.r_address & R_SCATTERED), VERR_LDR_BAD_FIXUP); 2980 2981 2981 2982 /* sanity */ 2982 KLDRMODMACHO_CHECK_RETURN((uint32_t)Fixup.r.r_address < cbSectBits, VERR_LDR_BAD_FIXUP);2983 RTLDRMODMACHO_CHECK_RETURN((uint32_t)Fixup.r.r_address < cbSectBits, VERR_LDR_BAD_FIXUP); 2983 2984 2984 2985 /* calc fixup addresses. */ … … 2998 2999 case 3: SymAddr = *uFixVirgin.pi64; break; 2999 3000 default: 3000 KLDRMODMACHO_FAILED_RETURN(VERR_LDR_BAD_FIXUP);3001 RTLDRMODMACHO_FAILED_RETURN(VERR_LDR_BAD_FIXUP); 3001 3002 } 3002 3003 … … 3006 3007 const macho_nlist_64_t *pSym; 3007 3008 3008 KLDRMODMACHO_CHECK_RETURN(Fixup.r.r_symbolnum < cSyms, VERR_LDR_BAD_FIXUP);3009 RTLDRMODMACHO_CHECK_RETURN(Fixup.r.r_symbolnum < cSyms, VERR_LDR_BAD_FIXUP); 3009 3010 pSym = &paSyms[Fixup.r.r_symbolnum]; 3010 KLDRMODMACHO_CHECK_RETURN(!(pSym->n_type & MACHO_N_STAB), VERR_LDR_BAD_FIXUP);3011 RTLDRMODMACHO_CHECK_RETURN(!(pSym->n_type & MACHO_N_STAB), VERR_LDR_BAD_FIXUP); 3011 3012 3012 3013 switch (Fixup.r.r_type) … … 3024 3025 case MACHO_N_INDR: 3025 3026 case MACHO_N_PBUD: 3026 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);3027 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 3027 3028 default: 3028 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_SYMBOL);3029 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_SYMBOL); 3029 3030 } 3030 3031 SymAddr = sizeof(uint64_t) * Fixup.r.r_symbolnum + pThis->GotRVA + NewBaseAddress; 3031 KLDRMODMACHO_CHECK_RETURN(Fixup.r.r_length == 2, VERR_LDR_BAD_FIXUP);3032 RTLDRMODMACHO_CHECK_RETURN(Fixup.r.r_length == 2, VERR_LDR_BAD_FIXUP); 3032 3033 SymAddr -= 4; 3033 3034 break; … … 3039 3040 case X86_64_RELOC_SIGNED_2: 3040 3041 case X86_64_RELOC_SIGNED_4: 3041 KLDRMODMACHO_CHECK_RETURN(Fixup.r.r_pcrel, VERR_LDR_BAD_FIXUP);3042 RTLDRMODMACHO_CHECK_RETURN(Fixup.r.r_pcrel, VERR_LDR_BAD_FIXUP); 3042 3043 /* Falls through. */ 3043 3044 default: … … 3047 3048 { 3048 3049 case X86_64_RELOC_UNSIGNED: 3049 KLDRMODMACHO_CHECK_RETURN(!Fixup.r.r_pcrel, VERR_LDR_BAD_FIXUP);3050 RTLDRMODMACHO_CHECK_RETURN(!Fixup.r.r_pcrel, VERR_LDR_BAD_FIXUP); 3050 3051 break; 3051 3052 case X86_64_RELOC_BRANCH: 3052 KLDRMODMACHO_CHECK_RETURN(Fixup.r.r_length == 2, VERR_LDR_BAD_FIXUP);3053 RTLDRMODMACHO_CHECK_RETURN(Fixup.r.r_length == 2, VERR_LDR_BAD_FIXUP); 3053 3054 SymAddr -= 4; 3054 3055 break; … … 3060 3061 break; 3061 3062 default: 3062 KLDRMODMACHO_FAILED_RETURN(VERR_LDR_BAD_FIXUP);3063 RTLDRMODMACHO_FAILED_RETURN(VERR_LDR_BAD_FIXUP); 3063 3064 } 3064 3065 … … 3067 3068 case MACHO_N_SECT: 3068 3069 { 3069 P KLDRMODMACHOSECT pSymSect;3070 KLDRMODMACHO_CHECK_RETURN((uint32_t)pSym->n_sect - 1 <= pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL);3070 PRTLDRMODMACHOSECT pSymSect; 3071 RTLDRMODMACHO_CHECK_RETURN((uint32_t)pSym->n_sect - 1 <= pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL); 3071 3072 pSymSect = &pThis->paSections[pSym->n_sect - 1]; 3072 3073 SymAddr += pSym->n_value - pSymSect->LinkAddress + pSymSect->RVA + NewBaseAddress; … … 3092 3093 case MACHO_N_INDR: 3093 3094 case MACHO_N_PBUD: 3094 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);3095 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 3095 3096 default: 3096 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_SYMBOL);3097 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_SYMBOL); 3097 3098 } 3098 3099 break; … … 3111 3112 case MACHO_N_SECT: 3112 3113 { 3113 P KLDRMODMACHOSECT pSymSect;3114 KLDRMODMACHO_CHECK_RETURN((uint32_t)pSym->n_sect - 1 <= pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL);3114 PRTLDRMODMACHOSECT pSymSect; 3115 RTLDRMODMACHO_CHECK_RETURN((uint32_t)pSym->n_sect - 1 <= pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL); 3115 3116 pSymSect = &pThis->paSections[pSym->n_sect - 1]; 3116 3117 SymAddr -= pSym->n_value - pSymSect->LinkAddress + pSymSect->RVA + NewBaseAddress; … … 3125 3126 case MACHO_N_INDR: 3126 3127 case MACHO_N_PBUD: 3127 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);3128 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 3128 3129 default: 3129 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_SYMBOL);3130 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_SYMBOL); 3130 3131 } 3131 3132 3132 3133 /* Load the 2nd fixup, check sanity. */ 3133 3134 iFixup++; 3134 KLDRMODMACHO_CHECK_RETURN(!Fixup.r.r_pcrel && iFixup < cFixups, VERR_LDR_BAD_FIXUP);3135 RTLDRMODMACHO_CHECK_RETURN(!Fixup.r.r_pcrel && iFixup < cFixups, VERR_LDR_BAD_FIXUP); 3135 3136 Fixup2 = paFixups[iFixup]; 3136 KLDRMODMACHO_CHECK_RETURN( Fixup2.r_address == Fixup.r.r_address3137 RTLDRMODMACHO_CHECK_RETURN( Fixup2.r_address == Fixup.r.r_address 3137 3138 && Fixup2.r_length == Fixup.r.r_length 3138 3139 && Fixup2.r_type == X86_64_RELOC_UNSIGNED … … 3143 3144 if (Fixup2.r_extern) 3144 3145 { 3145 KLDRMODMACHO_CHECK_RETURN(Fixup2.r_symbolnum < cSyms, VERR_LDR_BAD_FIXUP);3146 RTLDRMODMACHO_CHECK_RETURN(Fixup2.r_symbolnum < cSyms, VERR_LDR_BAD_FIXUP); 3146 3147 pSym = &paSyms[Fixup2.r_symbolnum]; 3147 KLDRMODMACHO_CHECK_RETURN(!(pSym->n_type & MACHO_N_STAB), VERR_LDR_BAD_FIXUP);3148 RTLDRMODMACHO_CHECK_RETURN(!(pSym->n_type & MACHO_N_STAB), VERR_LDR_BAD_FIXUP); 3148 3149 3149 3150 /* Add it's value to SymAddr. */ … … 3152 3153 case MACHO_N_SECT: 3153 3154 { 3154 P KLDRMODMACHOSECT pSymSect;3155 KLDRMODMACHO_CHECK_RETURN((uint32_t)pSym->n_sect - 1 <= pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL);3155 PRTLDRMODMACHOSECT pSymSect; 3156 RTLDRMODMACHO_CHECK_RETURN((uint32_t)pSym->n_sect - 1 <= pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL); 3156 3157 pSymSect = &pThis->paSections[pSym->n_sect - 1]; 3157 3158 SymAddr += pSym->n_value - pSymSect->LinkAddress + pSymSect->RVA + NewBaseAddress; … … 3166 3167 case MACHO_N_INDR: 3167 3168 case MACHO_N_PBUD: 3168 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);3169 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 3169 3170 default: 3170 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_SYMBOL);3171 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_BAD_SYMBOL); 3171 3172 } 3172 3173 } 3173 3174 else if (Fixup2.r_symbolnum != R_ABS) 3174 3175 { 3175 P KLDRMODMACHOSECT pSymSect;3176 KLDRMODMACHO_CHECK_RETURN(Fixup2.r_symbolnum <= pThis->cSections, VERR_LDR_BAD_FIXUP);3176 PRTLDRMODMACHOSECT pSymSect; 3177 RTLDRMODMACHO_CHECK_RETURN(Fixup2.r_symbolnum <= pThis->cSections, VERR_LDR_BAD_FIXUP); 3177 3178 pSymSect = &pThis->paSections[Fixup2.r_symbolnum - 1]; 3178 3179 SymAddr += pSymSect->RVA + NewBaseAddress; 3179 3180 } 3180 3181 else 3181 KLDRMODMACHO_FAILED_RETURN(VERR_LDR_BAD_FIXUP);3182 RTLDRMODMACHO_FAILED_RETURN(VERR_LDR_BAD_FIXUP); 3182 3183 } 3183 3184 break; … … 3190 3191 { 3191 3192 case X86_64_RELOC_UNSIGNED: 3192 KLDRMODMACHO_CHECK_RETURN(!Fixup.r.r_pcrel, VERR_LDR_BAD_FIXUP);3193 RTLDRMODMACHO_CHECK_RETURN(!Fixup.r.r_pcrel, VERR_LDR_BAD_FIXUP); 3193 3194 break; 3194 3195 case X86_64_RELOC_BRANCH: 3195 KLDRMODMACHO_CHECK_RETURN(Fixup.r.r_pcrel, VERR_LDR_BAD_FIXUP);3196 RTLDRMODMACHO_CHECK_RETURN(Fixup.r.r_pcrel, VERR_LDR_BAD_FIXUP); 3196 3197 SymAddr += 4; /* dunno what the assmbler/linker really is doing here... */ 3197 3198 break; … … 3200 3201 case X86_64_RELOC_SIGNED_2: 3201 3202 case X86_64_RELOC_SIGNED_4: 3202 KLDRMODMACHO_CHECK_RETURN(Fixup.r.r_pcrel, VERR_LDR_BAD_FIXUP);3203 RTLDRMODMACHO_CHECK_RETURN(Fixup.r.r_pcrel, VERR_LDR_BAD_FIXUP); 3203 3204 break; 3204 3205 /*case X86_64_RELOC_GOT_LOAD:*/ … … 3206 3207 /*case X86_64_RELOC_SUBTRACTOR: - must be r_extern=1 says as. */ 3207 3208 default: 3208 KLDRMODMACHO_FAILED_RETURN(VERR_LDR_BAD_FIXUP);3209 RTLDRMODMACHO_FAILED_RETURN(VERR_LDR_BAD_FIXUP); 3209 3210 } 3210 3211 if (Fixup.r.r_symbolnum != R_ABS) 3211 3212 { 3212 P KLDRMODMACHOSECT pSymSect;3213 KLDRMODMACHO_CHECK_RETURN(Fixup.r.r_symbolnum <= pThis->cSections, VERR_LDR_BAD_FIXUP);3213 PRTLDRMODMACHOSECT pSymSect; 3214 RTLDRMODMACHO_CHECK_RETURN(Fixup.r.r_symbolnum <= pThis->cSections, VERR_LDR_BAD_FIXUP); 3214 3215 pSymSect = &pThis->paSections[Fixup.r.r_symbolnum - 1]; 3215 3216 … … 3234 3235 break; 3235 3236 case 2: 3236 KLDRMODMACHO_CHECK_RETURN(Fixup.r.r_pcrel || Fixup.r.r_type == X86_64_RELOC_SUBTRACTOR, VERR_LDR_BAD_FIXUP);3237 KLDRMODMACHO_CHECK_RETURN((int32_t)SymAddr == (int64_t)SymAddr, VERR_LDR_ADDRESS_OVERFLOW);3237 RTLDRMODMACHO_CHECK_RETURN(Fixup.r.r_pcrel || Fixup.r.r_type == X86_64_RELOC_SUBTRACTOR, VERR_LDR_BAD_FIXUP); 3238 RTLDRMODMACHO_CHECK_RETURN((int32_t)SymAddr == (int64_t)SymAddr, VERR_LDR_ADDRESS_OVERFLOW); 3238 3239 *uFix.pu32 = (uint32_t)SymAddr; 3239 3240 break; 3240 3241 default: 3241 KLDRMODMACHO_FAILED_RETURN(VERR_LDR_BAD_FIXUP);3242 RTLDRMODMACHO_FAILED_RETURN(VERR_LDR_BAD_FIXUP); 3242 3243 } 3243 3244 } … … 3250 3251 * Loads the symbol table for a MH_OBJECT file. 3251 3252 * 3252 * The symbol table is pointed to by KLDRMODMACHO::pvaSymbols.3253 * The symbol table is pointed to by RTLDRMODMACHO::pvaSymbols. 3253 3254 * 3254 3255 * @returns IPRT status code. 3255 3256 * @param pThis The Mach-O module interpreter instance. 3256 3257 */ 3257 static int kldrModMachOLoadObjSymTab(P KLDRMODMACHO pThis)3258 static int kldrModMachOLoadObjSymTab(PRTLDRMODMACHO pThis) 3258 3259 { 3259 3260 int rc = VINF_SUCCESS; … … 3268 3269 3269 3270 /* sanity */ 3270 KLDRMODMACHO_CHECK_RETURN( pThis->offSymbols3271 RTLDRMODMACHO_CHECK_RETURN( pThis->offSymbols 3271 3272 && (!pThis->cchStrings || pThis->offStrings), 3272 3273 VERR_LDRMACHO_BAD_OBJECT_FILE); … … 3278 3279 : sizeof(macho_nlist_64_t); 3279 3280 cbSyms = pThis->cSymbols * cbSym; 3280 KLDRMODMACHO_CHECK_RETURN(cbSyms / cbSym == pThis->cSymbols, VERR_LDRMACHO_BAD_SYMTAB_SIZE);3281 RTLDRMODMACHO_CHECK_RETURN(cbSyms / cbSym == pThis->cSymbols, VERR_LDRMACHO_BAD_SYMTAB_SIZE); 3281 3282 rc = VERR_NO_MEMORY; 3282 3283 pvSyms = RTMemAlloc(cbSyms); … … 3333 3334 } 3334 3335 else 3335 KLDRMODMACHO_ASSERT(pThis->pchStrings || pThis->Hdr.filetype == MH_DSYM);3336 RTLDRMODMACHO_ASSERT(pThis->pchStrings || pThis->Hdr.filetype == MH_DSYM); 3336 3337 3337 3338 return rc; … … 3349 3350 * @param ppaFixups Where to put the pointer to the allocated fixup array. 3350 3351 */ 3351 static int kldrModMachOLoadFixups(P KLDRMODMACHO pThis, RTFOFF offFixups, uint32_t cFixups, macho_relocation_info_t **ppaFixups)3352 static int kldrModMachOLoadFixups(PRTLDRMODMACHO pThis, RTFOFF offFixups, uint32_t cFixups, macho_relocation_info_t **ppaFixups) 3352 3353 { 3353 3354 macho_relocation_info_t *paFixups; … … 3356 3357 /* allocate the memory. */ 3357 3358 cbFixups = cFixups * sizeof(*paFixups); 3358 KLDRMODMACHO_CHECK_RETURN(cbFixups / sizeof(*paFixups) == cFixups, VERR_LDRMACHO_BAD_SYMTAB_SIZE);3359 RTLDRMODMACHO_CHECK_RETURN(cbFixups / sizeof(*paFixups) == cFixups, VERR_LDRMACHO_BAD_SYMTAB_SIZE); 3359 3360 paFixups = (macho_relocation_info_t *)RTMemAlloc(cbFixups); 3360 3361 if (!paFixups) … … 3392 3393 * @param pThis The Mach-O module interpreter instance. 3393 3394 */ 3394 static int kldrModMachOMapVirginBits(P KLDRMODMACHO pThis)3395 static int kldrModMachOMapVirginBits(PRTLDRMODMACHO pThis) 3395 3396 { 3396 3397 int rc = VINF_SUCCESS; … … 3443 3444 static DECLCALLBACK(size_t) rtldrMachO_GetImageSize(PRTLDRMODINTERNAL pMod) 3444 3445 { 3445 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);3446 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 3446 3447 return pThis->cbImage; 3447 3448 } … … 3454 3455 PFNRTLDRIMPORT pfnGetImport, void *pvUser) 3455 3456 { 3456 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);3457 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 3457 3458 3458 3459 if (!pThis->fCanLoad) … … 3496 3497 RTUINTPTR OldBaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser) 3497 3498 { 3498 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);3499 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 3499 3500 int rc; 3500 3501 RT_NOREF(OldBaseAddress); … … 3535 3536 * the bits has been cleared up front. 3536 3537 */ 3537 static int kldrModMachOMakeGOT(P KLDRMODMACHO pThis, void *pvBits, RTLDRADDR NewBaseAddress)3538 static int kldrModMachOMakeGOT(PRTLDRMODMACHO pThis, void *pvBits, RTLDRADDR NewBaseAddress) 3538 3539 { 3539 3540 uint32_t iSym = pThis->cSymbols; … … 3548 3549 case MACHO_N_SECT: 3549 3550 { 3550 P KLDRMODMACHOSECT pSymSect;3551 KLDRMODMACHO_CHECK_RETURN((uint32_t)paSyms[iSym].n_sect - 1 <= pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL);3551 PRTLDRMODMACHOSECT pSymSect; 3552 RTLDRMODMACHO_CHECK_RETURN((uint32_t)paSyms[iSym].n_sect - 1 <= pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL); 3552 3553 pSymSect = &pThis->paSections[paSyms[iSym].n_sect - 1]; 3553 3554 paGOT[iSym] = (uint32_t)(paSyms[iSym].n_value - pSymSect->LinkAddress + pSymSect->RVA + NewBaseAddress); … … 3571 3572 case MACHO_N_SECT: 3572 3573 { 3573 P KLDRMODMACHOSECT pSymSect;3574 KLDRMODMACHO_CHECK_RETURN((uint32_t)paSyms[iSym].n_sect - 1 <= pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL);3574 PRTLDRMODMACHOSECT pSymSect; 3575 RTLDRMODMACHO_CHECK_RETURN((uint32_t)paSyms[iSym].n_sect - 1 <= pThis->cSections, VERR_LDRMACHO_BAD_SYMBOL); 3575 3576 pSymSect = &pThis->paSections[paSyms[iSym].n_sect - 1]; 3576 3577 paGOT[iSym] = paSyms[iSym].n_value - pSymSect->LinkAddress + pSymSect->RVA + NewBaseAddress; … … 3625 3626 3626 3627 default: 3627 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO);3628 RTLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_TODO); 3628 3629 } 3629 3630 } … … 3638 3639 static DECLCALLBACK(int) rtldrMachO_EnumSegments(PRTLDRMODINTERNAL pMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser) 3639 3640 { 3640 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);3641 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 3641 3642 uint32_t const cSegments = pThis->cSegments; 3642 3643 for (uint32_t iSeg = 0; iSeg < cSegments; iSeg++) … … 3657 3658 uint32_t *piSeg, PRTLDRADDR poffSeg) 3658 3659 { 3659 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);3660 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 3660 3661 uint32_t const cSegments = pThis->cSegments; 3661 3662 for (uint32_t iSeg = 0; iSeg < cSegments; iSeg++) … … 3680 3681 static DECLCALLBACK(int) rtldrMachO_LinkAddressToRva(PRTLDRMODINTERNAL pMod, RTLDRADDR LinkAddress, PRTLDRADDR pRva) 3681 3682 { 3682 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);3683 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 3683 3684 uint32_t const cSegments = pThis->cSegments; 3684 3685 for (uint32_t iSeg = 0; iSeg < cSegments; iSeg++) … … 3702 3703 static DECLCALLBACK(int) rtldrMachO_SegOffsetToRva(PRTLDRMODINTERNAL pMod, uint32_t iSeg, RTLDRADDR offSeg, PRTLDRADDR pRva) 3703 3704 { 3704 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);3705 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 3705 3706 3706 3707 if (iSeg >= pThis->cSegments) 3707 3708 return VERR_LDR_INVALID_SEG_OFFSET; 3708 KLDRMODMACHOSEG const *pSegment = &pThis->aSegments[iSeg];3709 RTLDRMODMACHOSEG const *pSegment = &pThis->aSegments[iSeg]; 3709 3710 3710 3711 if ( offSeg > pSegment->SegInfo.cbMapped … … 3724 3725 static DECLCALLBACK(int) rtldrMachO_RvaToSegOffset(PRTLDRMODINTERNAL pMod, RTLDRADDR Rva, uint32_t *piSeg, PRTLDRADDR poffSeg) 3725 3726 { 3726 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);3727 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 3727 3728 uint32_t const cSegments = pThis->cSegments; 3728 3729 for (uint32_t iSeg = 0; iSeg < cSegments; iSeg++) … … 3747 3748 static DECLCALLBACK(int) rtldrMachO_ReadDbgInfo(PRTLDRMODINTERNAL pMod, uint32_t iDbgInfo, RTFOFF off, size_t cb, void *pvBuf) 3748 3749 { 3749 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);3750 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 3750 3751 3751 3752 /** @todo May have to apply fixups here. */ … … 3760 3761 void *pvBuf, size_t cbBuf, size_t *pcbRet) 3761 3762 { 3762 P KLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core);3763 PRTLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, RTLDRMODMACHO, Core); 3763 3764 int rc; 3764 3765 switch (enmProp) … … 3830 3831 * Create the instance data and do a minimal header validation. 3831 3832 */ 3832 P KLDRMODMACHO pThis = NULL;3833 PRTLDRMODMACHO pThis = NULL; 3833 3834 int rc = kldrModMachODoCreate(pReader, offImage, fFlags, &pThis, pErrInfo); 3834 3835 if (RT_SUCCESS(rc)) -
trunk/src/VBox/Runtime/testcase/tstLdr-3.cpp
r74646 r74647 231 231 if (hLdrMod != g_hLdrMod || pvUser != NULL) 232 232 return VERR_INTERNAL_ERROR_3; 233 RTPrintf("Seg#%02u: %RTptr LB %RTptr %s\n", g_iSegNo++, pSeg->RVA, pSeg->cbMapped, pSeg->pszName); 233 RTPrintf("Seg#%02u: %RTptr LB %RTptr %s\n" 234 " link=%RTptr LB %RTptr align=%RTptr fProt=%#x offFile=%RTfoff\n" 235 , g_iSegNo++, pSeg->RVA, pSeg->cbMapped, pSeg->pszName, 236 pSeg->LinkAddress, pSeg->cb, pSeg->Alignment, pSeg->fProt, pSeg->offFile); 234 237 235 238 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.