1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2008 Apple Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
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
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.
22 * @APPLE_LICENSE_HEADER_END@
26 #ifndef __IMAGELOADER_MACHO_COMPRESSED__
27 #define __IMAGELOADER_MACHO_COMPRESSED__
31 #include "ImageLoaderMachO.h"
35 // ImageLoaderMachOCompressed is the concrete subclass of ImageLoader which loads mach-o files
36 // that use the compressed LINKEDIT format.
38 class ImageLoaderMachOCompressed
: public ImageLoaderMachO
{
40 static ImageLoaderMachOCompressed
* instantiateMainExecutable(const macho_header
* mh
, uintptr_t slide
, const char* path
,
41 unsigned int segCount
, unsigned int libCount
, const LinkContext
& context
);
42 static ImageLoaderMachOCompressed
* instantiateFromFile(const char* path
, int fd
, const uint8_t* fileData
,
43 uint64_t offsetInFat
, uint64_t lenInFat
, const struct stat
& info
,
44 unsigned int segCount
, unsigned int libCount
, const LinkContext
& context
);
45 static ImageLoaderMachOCompressed
* instantiateFromCache(const macho_header
* mh
, const char* path
, const struct stat
& info
,
46 unsigned int segCount
, unsigned int libCount
, const LinkContext
& context
);
47 static ImageLoaderMachOCompressed
* instantiateFromMemory(const char* moduleName
, const macho_header
* mh
, uint64_t len
,
48 unsigned int segCount
, unsigned int libCount
, const LinkContext
& context
);
51 virtual ~ImageLoaderMachOCompressed();
53 virtual ImageLoader
* libImage(unsigned int) const;
54 virtual bool libReExported(unsigned int) const;
55 virtual void setLibImage(unsigned int, ImageLoader
*, bool);
56 virtual void doBind(const LinkContext
& context
, bool forceLazysBound
);
57 virtual void doBindJustLazies(const LinkContext
& context
);
58 virtual uintptr_t doBindLazySymbol(uintptr_t* lazyPointer
, const LinkContext
& context
);
59 virtual uintptr_t doBindFastLazySymbol(uint32_t lazyBindingInfoOffset
, const LinkContext
& context
);
60 virtual const char* findClosestSymbol(const void* addr
, const void** closestAddr
) const;
61 virtual void initializeCoalIterator(CoalIterator
&, unsigned int loadOrder
);
62 virtual bool incrementCoalIterator(CoalIterator
&);
63 virtual uintptr_t getAddressCoalIterator(CoalIterator
&, const LinkContext
& contex
);
64 virtual void updateUsesCoalIterator(CoalIterator
&, uintptr_t newAddr
, ImageLoader
* target
, const LinkContext
& context
);
68 virtual void setDyldInfo(const dyld_info_command
* dyldInfo
) { fDyldInfo
= dyldInfo
; }
69 virtual void setSymbolTableInfo(const macho_nlist
*, const char*, const dysymtab_command
*) {}
70 virtual bool isSubframeworkOf(const LinkContext
& context
, const ImageLoader
* image
) const { return false; }
71 virtual bool hasSubLibrary(const LinkContext
& context
, const ImageLoader
* child
) const { return false; }
72 virtual uint32_t* segmentCommandOffsets() const;
73 virtual void rebase(const LinkContext
& context
);
74 virtual const ImageLoader::Symbol
* findExportedSymbol(const char* name
, const ImageLoader
** foundIn
) const;
75 virtual bool containsSymbol(const void* addr
) const;
76 virtual uintptr_t exportedSymbolAddress(const Symbol
* symbol
) const;
77 virtual bool exportedSymbolIsWeakDefintion(const Symbol
* symbol
) const;
78 virtual const char* exportedSymbolName(const Symbol
* symbol
) const;
79 virtual unsigned int exportedSymbolCount() const;
80 virtual const ImageLoader::Symbol
* exportedSymbolIndexed(unsigned int) const;
81 virtual unsigned int importedSymbolCount() const;
82 virtual const ImageLoader::Symbol
* importedSymbolIndexed(unsigned int) const;
83 virtual const char* importedSymbolName(const Symbol
* symbol
) const;
84 #if PREBOUND_IMAGE_SUPPORT
85 virtual void resetPreboundLazyPointers(const LinkContext
& context
);
90 struct LastLookup
{ int ordinal
; uint8_t flags
; const char* name
; uintptr_t result
; const ImageLoader
* foundIn
; };
93 typedef uintptr_t (ImageLoaderMachOCompressed::*bind_handler
)(const LinkContext
& context
, uintptr_t addr
, uint8_t type
,
94 const char* symbolName
, uint8_t symboFlags
, intptr_t addend
, int libraryOrdinal
,
95 const char* msg
, LastLookup
* last
);
97 void eachLazyBind(const LinkContext
& context
, bind_handler
);
98 void eachBind(const LinkContext
& context
, bind_handler
);
101 ImageLoaderMachOCompressed(const macho_header
* mh
, const char* path
, unsigned int segCount
,
102 uint32_t segOffsets
[], unsigned int libCount
);
103 static ImageLoaderMachOCompressed
* instantiateStart(const macho_header
* mh
, const char* path
, unsigned int segCount
, unsigned int libCount
);
104 void instantiateFinish(const LinkContext
& context
);
105 void markSequentialLINKEDIT(const LinkContext
& context
);
106 void markFreeLINKEDIT(const LinkContext
& context
);
107 void markLINKEDIT(const LinkContext
& context
, int advise
);
109 void rebaseAt(const LinkContext
& context
, uintptr_t addr
, uintptr_t slide
, uint8_t type
);
110 void throwBadRebaseAddress(uintptr_t address
, uintptr_t segmentEndAddress
, int segmentIndex
,
111 const uint8_t* startOpcodes
, const uint8_t* endOpcodes
, const uint8_t* pos
);
112 uintptr_t bindAt(const LinkContext
& context
, uintptr_t addr
, uint8_t type
, const char* symbolName
,
113 uint8_t symboFlags
, intptr_t addend
, int libraryOrdinal
, const char* msg
,
115 void bindCompressed(const LinkContext
& context
);
116 void throwBadBindingAddress(uintptr_t address
, uintptr_t segmentEndAddress
, int segmentIndex
,
117 const uint8_t* startOpcodes
, const uint8_t* endOpcodes
, const uint8_t* pos
);
118 uintptr_t resolve(const LinkContext
& context
, const char* symbolName
,
119 uint8_t symboFlags
, int libraryOrdinal
, const ImageLoader
** targetImage
, LastLookup
* last
= NULL
);
120 uintptr_t resolveFlat(const LinkContext
& context
, const char* symbolName
, bool weak_import
,
121 const ImageLoader
** foundIn
);
122 uintptr_t resolveCoalesced(const LinkContext
& context
, const char* symbolName
, const ImageLoader
** foundIn
);
123 uintptr_t resolveTwolevel(const LinkContext
& context
, const ImageLoader
* targetImage
, bool weak_import
,
124 const char* symbolName
, const ImageLoader
** foundIn
);
126 const struct dyld_info_command
* fDyldInfo
;
131 #endif // __IMAGELOADER_MACHO_COMPRESSED__