]> git.saurik.com Git - apple/dyld.git/blob - src/ImageLoaderMachOClassic.h
dyld-360.19.tar.gz
[apple/dyld.git] / src / ImageLoaderMachOClassic.h
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2008 Apple Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25
26 #ifndef __IMAGELOADER_MACHO_CLASSIC__
27 #define __IMAGELOADER_MACHO_CLASSIC__
28
29 #include <stdint.h>
30
31 #include "ImageLoaderMachO.h"
32
33
34 //
35 // ImageLoaderMachOClassic is the concrete subclass of ImageLoader which loads mach-o files
36 // that use the traditional LINKEDIT format.
37 //
38 class ImageLoaderMachOClassic : public ImageLoaderMachO {
39 public:
40 static ImageLoaderMachOClassic* instantiateMainExecutable(const macho_header* mh, uintptr_t slide, const char* path,
41 unsigned int segCount, unsigned int libCount, const LinkContext& context);
42 static ImageLoaderMachOClassic* instantiateFromFile(const char* path, int fd, const uint8_t* fileData, size_t lenFileData,
43 uint64_t offsetInFat, uint64_t lenInFat, const struct stat& info,
44 unsigned int segCount, unsigned int libCount,
45 const struct linkedit_data_command* codeSigCmd, const LinkContext& context);
46 static ImageLoaderMachOClassic* instantiateFromCache(const macho_header* mh, const char* path, long slide, const struct stat& info,
47 unsigned int segCount, unsigned int libCount, const LinkContext& context);
48 static ImageLoaderMachOClassic* instantiateFromMemory(const char* moduleName, const macho_header* mh, uint64_t len,
49 unsigned int segCount, unsigned int libCount, const LinkContext& context);
50
51 virtual ~ImageLoaderMachOClassic();
52
53 virtual ImageLoader* libImage(unsigned int) const;
54 virtual bool libReExported(unsigned int) const;
55 virtual bool libIsUpward(unsigned int) const;
56 virtual void setLibImage(unsigned int, ImageLoader*, bool, bool);
57 virtual void doBind(const LinkContext& context, bool forceLazysBound);
58 virtual void doBindJustLazies(const LinkContext& context);
59 virtual uintptr_t doBindLazySymbol(uintptr_t* lazyPointer, const LinkContext& context);
60 virtual uintptr_t doBindFastLazySymbol(uint32_t lazyBindingInfoOffset, const LinkContext& context, void (*lock)(), void (*unlock)());
61 virtual const char* findClosestSymbol(const void* addr, const void** closestAddr) const;
62 virtual void initializeCoalIterator(CoalIterator&, unsigned int loadOrder);
63 virtual bool incrementCoalIterator(CoalIterator&);
64 virtual uintptr_t getAddressCoalIterator(CoalIterator&, const LinkContext& contex);
65 virtual void updateUsesCoalIterator(CoalIterator&, uintptr_t newAddr, ImageLoader* target, const LinkContext& context);
66
67 protected:
68 virtual void doInterpose(const LinkContext& context);
69 virtual void dynamicInterpose(const LinkContext& context);
70 virtual void setDyldInfo(const dyld_info_command*) {}
71 virtual void setSymbolTableInfo(const macho_nlist*, const char*, const dysymtab_command*);
72 virtual bool isSubframeworkOf(const LinkContext& context, const ImageLoader* image) const;
73 virtual bool hasSubLibrary(const LinkContext& context, const ImageLoader* child) const;
74 virtual uint32_t* segmentCommandOffsets() const;
75 virtual void rebase(const LinkContext& context);
76 virtual const ImageLoader::Symbol* findExportedSymbol(const char* name, const ImageLoader** foundIn) const;
77 virtual bool containsSymbol(const void* addr) const;
78 virtual uintptr_t exportedSymbolAddress(const LinkContext& context, const Symbol* symbol, const ImageLoader* requestor, bool runResolver) const;
79 virtual bool exportedSymbolIsWeakDefintion(const Symbol* symbol) const;
80 virtual const char* exportedSymbolName(const Symbol* symbol) const;
81 virtual unsigned int exportedSymbolCount() const;
82 virtual const ImageLoader::Symbol* exportedSymbolIndexed(unsigned int) const;
83 virtual unsigned int importedSymbolCount() const;
84 virtual const ImageLoader::Symbol* importedSymbolIndexed(unsigned int) const;
85 virtual const char* importedSymbolName(const Symbol* symbol) const;
86 #if PREBOUND_IMAGE_SUPPORT
87 virtual void resetPreboundLazyPointers(const LinkContext& context);
88 #endif
89
90
91 private:
92 ImageLoaderMachOClassic(const macho_header* mh, const char* path, unsigned int segCount,
93 uint32_t segOffsets[], unsigned int libCount);
94 static ImageLoaderMachOClassic* instantiateStart(const macho_header* mh, const char* path, unsigned int segCount, unsigned int libCount);
95 void instantiateFinish(const LinkContext& context);
96 uintptr_t getRelocBase();
97 void mapSegmentsClassic(int fd, uint64_t offsetInFat, uint64_t lenInFat, uint64_t fileLen, const LinkContext& context);
98 uintptr_t getFirstWritableSegmentAddress();
99 const struct macho_nlist* binarySearch(const char* key, const char stringPool[], const struct macho_nlist symbols[], uint32_t symbolCount) const;
100 const struct macho_nlist* binarySearchWithToc(const char* key, const char stringPool[], const struct macho_nlist symbols[],
101 const struct dylib_table_of_contents toc[], uint32_t symbolCount, uint32_t hintIndex) const;
102 static bool symbolIsWeakReference(const struct macho_nlist* symbol);
103 static bool symbolIsWeakDefinition(const struct macho_nlist* symbol);
104 uintptr_t resolveUndefined(const LinkContext& context, const struct macho_nlist* symbol, bool twoLevel,
105 bool dontCoalesce, const ImageLoader **foundIn);
106 uintptr_t getSymbolAddress(const macho_nlist*, const LinkContext& context, bool runResolver) const;
107 bool isAddrInSection(uintptr_t addr, uint8_t sectionIndex);
108 void doBindExternalRelocations(const LinkContext& context);
109 uintptr_t bindIndirectSymbol(uintptr_t* ptrToBind, const struct macho_section* sect,
110 const char* symbolName, uintptr_t targetAddr,
111 const ImageLoader* targetImage, const LinkContext& context);
112 void bindIndirectSymbolPointers(const LinkContext& context, bool bindNonLazys, bool bindLazys);
113 void initializeLazyStubs(const LinkContext& context);
114 void prefetchLINKEDIT(const LinkContext& context);
115 #if SPLIT_SEG_DYLIB_SUPPORT
116 unsigned int getExtraZeroFillEntriesCount();
117 void initMappingTable(uint64_t offsetInFat, shared_file_mapping_np *mappingTable);
118 #endif
119 int mapSplitSegDylibOutsideSharedRegion(int fd, uint64_t offsetInFat, uint64_t lenInFat, uint64_t fileLen, const LinkContext& context);
120 #if SPLIT_SEG_SHARED_REGION_SUPPORT
121 int mapSplitSegDylibInfoSharedRegion(int fd, uint64_t offsetInFat, uint64_t lenInFat, uint64_t fileLen, const LinkContext& context);
122 #endif
123
124
125 const char* fStrings;
126 const struct macho_nlist* fSymbolTable;
127 const struct dysymtab_command* fDynamicInfo;
128
129 };
130
131
132
133
134 #endif // __IMAGELOADER_MACHO_CLASSIC__
135
136
137
138