Changeset 43
- Timestamp:
- Aug 31, 2011, 4:37:38 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdrModMachO.c
r42 r43 131 131 /** The size of the mapped image. */ 132 132 KLDRADDR cbImage; 133 /** Whether we're capable of loading the image. */ 134 KBOOL fCanLoad; 133 135 /** Whether we're creating a global offset table segment. 134 136 * This dependes on the cputype and image type. */ … … 186 188 static int kldrModMachODoCreate(PKRDR pRdr, KLDRFOFF offImage, PKLDRMODMACHO *ppMod); 187 189 static int kldrModMachOPreParseLoadCommands(KU8 *pbLoadCommands, const mach_header_32_t *pHdr, PKRDR pRdr, KLDRFOFF offImage, 188 KU32 *pcSegments, KU32 *pcSections, KU32 *pcbStringPool );190 KU32 *pcSegments, KU32 *pcSections, KU32 *pcbStringPool, PKBOOL pfCanLoad); 189 191 static int kldrModMachOParseLoadCommands(PKLDRMODMACHO pModMachO, char *pbStringPool, KU32 cbStringPool); 190 192 static int kldrModMachOAdjustBaseAddress(PKLDRMODMACHO pModMachO, PKLDRADDR pBaseAddress); … … 289 291 KSIZE cb; 290 292 KBOOL fMakeGot; 293 KBOOL fCanLoad = K_TRUE; 291 294 KU8 cbJmpStub; 292 295 int rc; … … 348 351 : sizeof(mach_header_64_t) + offImage); 349 352 if (!rc) 350 rc = kldrModMachOPreParseLoadCommands(pbLoadCommands, &s.Hdr32, pRdr, offImage, &cSegments, &cSections, &cbStringPool); 353 rc = kldrModMachOPreParseLoadCommands(pbLoadCommands, &s.Hdr32, pRdr, offImage, 354 &cSegments, &cSections, &cbStringPool, &fCanLoad); 351 355 if (rc) 352 356 { … … 454 458 pModMachO->LinkAddress = 0; 455 459 pModMachO->cbImage = 0; 460 pModMachO->fCanLoad = fCanLoad; 456 461 pModMachO->fMakeGot = fMakeGot; 457 462 pModMachO->cbJmpStub = cbJmpStub; … … 498 503 * @param pcSegments Where to store the section count. 499 504 * @param pcbStringPool Where to store the string pool size. 505 * @param pfCanLoad Where to store the can-load-image indicator. 500 506 */ 501 507 static int kldrModMachOPreParseLoadCommands(KU8 *pbLoadCommands, const mach_header_32_t *pHdr, PKRDR pRdr, KLDRFOFF offImage, 502 KU32 *pcSegments, KU32 *pcSections, KU32 *pcbStringPool )508 KU32 *pcSegments, KU32 *pcSections, KU32 *pcbStringPool, PKBOOL pfCanLoad) 503 509 { 504 510 union … … 527 533 *pcSections = 0; 528 534 *pcbStringPool = 0; 535 *pfCanLoad = K_TRUE; 529 536 530 537 while (cLeft-- > 0) … … 636 643 break; 637 644 645 case S_SYMBOL_STUBS: 646 if ( pSect->reserved1 647 || pSect->reserved2 < 1 648 || pSect->reserved2 > 64 ) 649 return KLDR_ERR_MACHO_BAD_SECTION; 650 fFileBits = 0; 651 break; 652 653 case S_NON_LAZY_SYMBOL_POINTERS: 654 case S_LAZY_SYMBOL_POINTERS: 655 if (pSect->reserved2) /* (reserved 1 is indirect symbol table index)*/ 656 return KLDR_ERR_MACHO_BAD_SECTION; 657 *pfCanLoad = K_FALSE; 658 fFileBits = 0; 659 break; 660 638 661 case S_LITERAL_POINTERS: 639 662 case S_INTERPOSING: 640 663 case S_GB_ZEROFILL: 641 case S_NON_LAZY_SYMBOL_POINTERS:642 case S_LAZY_SYMBOL_POINTERS:643 case S_SYMBOL_STUBS:644 return KLDR_ERR_MACHO_UNSUPPORTED_SECTION;645 664 case S_MOD_INIT_FUNC_POINTERS: 646 665 return KLDR_ERR_MACHO_UNSUPPORTED_INIT_SECTION; … … 687 706 cSections++; 688 707 689 /* Don't load debug symbols. (test this) */ 690 if (pSect->flags & S_ATTR_DEBUG) 708 /* Don't load debug symbols. */ 709 if ( (pSect->flags & S_ATTR_DEBUG) 710 || !kHlpStrComp(pSect->segname, "__DWARF")) 691 711 break; 692 712 … … 807 827 break; 808 828 829 case S_SYMBOL_STUBS: 830 if ( pSect->reserved1 831 || pSect->reserved2 < 1 /* stub size.*/ 832 || pSect->reserved2 > 64 ) 833 return KLDR_ERR_MACHO_BAD_SECTION; 834 fFileBits = 1; 835 break; 836 837 case S_NON_LAZY_SYMBOL_POINTERS: 838 case S_LAZY_SYMBOL_POINTERS: 839 if (pSect->reserved2) /* (reserved 1 is indirect symbol table index)*/ 840 return KLDR_ERR_MACHO_BAD_SECTION; 841 *pfCanLoad = K_FALSE; 842 fFileBits = 0; 843 break; 844 809 845 case S_LITERAL_POINTERS: 810 846 case S_INTERPOSING: 811 847 case S_GB_ZEROFILL: 812 case S_NON_LAZY_SYMBOL_POINTERS:813 case S_LAZY_SYMBOL_POINTERS:814 case S_SYMBOL_STUBS:815 848 return KLDR_ERR_MACHO_UNSUPPORTED_SECTION; 816 849 #if 1 /** @todo this requires a query API or flag... */ … … 866 899 867 900 /* Don't load debug symbols. (test this) */ 868 if (pSect->flags & S_ATTR_DEBUG) 901 if ( (pSect->flags & S_ATTR_DEBUG) 902 || !kHlpStrComp(pSect->segname, "__DWARF")) 869 903 break; 870 904 … … 1109 1143 1110 1144 /* Don't load debug symbols. (test this!) */ 1111 if (pSect->flags & S_ATTR_DEBUG) 1145 if ( (pSect->flags & S_ATTR_DEBUG) 1146 || !kHlpStrComp(pSect->segname, "__DWARF")) 1112 1147 { 1113 1148 pSectExtra++; … … 1243 1278 1244 1279 /* Don't load debug symbols. (test this!) */ 1245 if (pSect->flags & S_ATTR_DEBUG) 1280 if ( (pSect->flags & S_ATTR_DEBUG) 1281 || !kHlpStrComp(pSect->segname, "__DWARF")) 1246 1282 { 1247 1283 pSectExtra++; … … 2197 2233 void *pvBase; 2198 2234 int rc; 2235 2236 if (!pModMachO->fCanLoad) 2237 return KLDR_ERR_TODO; 2199 2238 2200 2239 /* … … 3248 3287 int rc; 3249 3288 3289 if (!pModMachO->fCanLoad) 3290 return KLDR_ERR_TODO; 3291 3250 3292 /* 3251 3293 * Zero the entire buffer first to simplify things.
Note:
See TracChangeset
for help on using the changeset viewer.