]> git.saurik.com Git - apple/dyld.git/blob - include/mach-o/dyld_images.h
ed710ef342d46892ff42e1a92c03b269a633d166
[apple/dyld.git] / include / mach-o / dyld_images.h
1 /*
2 * Copyright (c) 2006-2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 #ifndef _DYLD_IMAGES_
24 #define _DYLD_IMAGES_
25
26 #include <stdbool.h>
27 #include <unistd.h>
28 #include <mach/mach.h>
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34
35 /*
36 * Beginning in Mac OS X 10.4, this is how gdb discovers which mach-o images are loaded in a process.
37 *
38 * gdb looks for the symbol "_dyld_all_image_infos" in dyld. It contains the fields below.
39 *
40 * For a snashot of what images are currently loaded, the infoArray fields contain a pointer
41 * to an array of all images. If infoArray is NULL, it means it is being modified, come back later.
42 *
43 * To be notified of changes, gdb sets a break point on the address pointed to by the notificationn
44 * field. The function it points to is called by dyld with an array of information about what images
45 * have been added (dyld_image_adding) or are about to be removed (dyld_image_removing).
46 *
47 * The notification is called after infoArray is updated. This means that if gdb attaches to a process
48 * and infoArray is NULL, gdb can set a break point on notification and let the proccess continue to
49 * run until the break point. Then gdb can inspect the full infoArray.
50 *
51 * The dyldVersion field always points to a C string that contains the dyld version. For instance,
52 * in dyld-127.3, dyldVersion would contain a pointer to "127.3".
53 *
54 * The errorMessage and terminationFlags fields are normally zero. If dyld terminates a process
55 * (for instance because a required dylib or symbol is missing), then the errorMessage field will
56 * be set to point to a C string message buffer containing the reason dyld terminate the process.
57 * The low bit of the terminationFlags will be set if dyld terminated the process before any user
58 * code ran, in which case there is no need for the crash log to contain the backtrace.
59 *
60 * When dyld terminates a process because some required dylib or symbol cannot be bound, in
61 * addition to the errorMessage field, it now sets the errorKind field and the corresponding
62 * fields: errorClientOfDylibPath, errorTargetDylibPath, errorSymbol.
63 *
64 */
65
66 enum dyld_image_mode { dyld_image_adding=0, dyld_image_removing=1 };
67
68 struct dyld_image_info {
69 const struct mach_header* imageLoadAddress; /* base address image is mapped into */
70 const char* imageFilePath; /* path dyld used to load the image */
71 uintptr_t imageFileModDate; /* time_t of image file */
72 /* if stat().st_mtime of imageFilePath does not match imageFileModDate, */
73 /* then file has been modified since dyld loaded it */
74 };
75
76 struct dyld_uuid_info {
77 const struct mach_header* imageLoadAddress; /* base address image is mapped into */
78 uuid_t imageUUID; /* UUID of image */
79 };
80
81 typedef void (*dyld_image_notifier)(enum dyld_image_mode mode, uint32_t infoCount, const struct dyld_image_info info[]);
82
83 /* for use in dyld_all_image_infos.errorKind field */
84 enum { dyld_error_kind_none=0,
85 dyld_error_kind_dylib_missing=1,
86 dyld_error_kind_dylib_wrong_arch=2,
87 dyld_error_kind_dylib_version=3,
88 dyld_error_kind_symbol_missing=4
89 };
90
91
92 struct dyld_all_image_infos {
93 uint32_t version; /* 1 in Mac OS X 10.4 and 10.5 */
94 uint32_t infoArrayCount;
95 const struct dyld_image_info* infoArray;
96 dyld_image_notifier notification;
97 bool processDetachedFromSharedRegion;
98 /* the following fields are only in version 2 (Mac OS X 10.6, iPhoneOS 2.0) and later */
99 bool libSystemInitialized;
100 const struct mach_header* dyldImageLoadAddress;
101 /* the following field is only in version 3 (Mac OS X 10.6, iPhoneOS 3.0) and later */
102 void* jitInfo;
103 /* the following fields are only in version 5 (Mac OS X 10.6, iPhoneOS 3.0) and later */
104 const char* dyldVersion;
105 const char* errorMessage;
106 uintptr_t terminationFlags;
107 /* the following field is only in version 6 (Mac OS X 10.6, iPhoneOS 3.1) and later */
108 void* coreSymbolicationShmPage;
109 /* the following field is only in version 7 (Mac OS X 10.6, iPhoneOS 3.1) and later */
110 uintptr_t systemOrderFlag;
111 /* the following field is only in version 8 (Mac OS X 10.7, iPhoneOS 3.1) and later */
112 uintptr_t uuidArrayCount;
113 const struct dyld_uuid_info* uuidArray; /* only images not in dyld shared cache */
114 /* the following field is only in version 9 (Mac OS X 10.7, iOS 4.0) and later */
115 struct dyld_all_image_infos* dyldAllImageInfosAddress;
116 /* the following field is only in version 10 (Mac OS X 10.7, iOS 4.2) and later */
117 uintptr_t initialImageCount;
118 /* the following field is only in version 11 (Mac OS X 10.7, iOS 4.2) and later */
119 uintptr_t errorKind;
120 const char* errorClientOfDylibPath;
121 const char* errorTargetDylibPath;
122 const char* errorSymbol;
123 /* the following field is only in version 12 (Mac OS X 10.7, iOS 4.3) and later */
124 uintptr_t sharedCacheSlide;
125 };
126 extern struct dyld_all_image_infos dyld_all_image_infos;
127
128 /*
129 * Beginning in Mac OS X 10.6, rather than looking up the symbol "_dyld_all_image_infos"
130 * in dyld's symbol table, you can add DYLD_ALL_IMAGE_INFOS_OFFSET_OFFSET to the mach_header
131 * for dyld and read the 32-bit unsigned int at that location. Adding that value to dyld's
132 * mach_header address gets you the address of dyld_all_image_infos in dyld.
133 */
134 #define DYLD_ALL_IMAGE_INFOS_OFFSET_OFFSET 0x1010
135
136
137
138 /*
139 * Beginning in Mac OS X 10.5, this is how gdb discovers where the shared cache is in a process.
140 * Images that are in the shared cache have their segments rearranged, so when using imageFilePath
141 * to load the file from disk, you have to know to adjust addresses based on how their segment
142 * was rearranged.
143 *
144 * gdb looks for the symbol "_dyld_shared_region_ranges" in dyld.
145 *
146 * It contains information the count of shared regions used by the process. The count is
147 * the number of start/length pairs.
148 */
149 struct dyld_shared_cache_ranges {
150 uintptr_t sharedRegionsCount; /* how many ranges follow */
151 struct {
152 uintptr_t start;
153 uintptr_t length;
154 } ranges[4]; /* max regions */
155 };
156 extern struct dyld_shared_cache_ranges dyld_shared_cache_ranges;
157
158
159
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif /* _DYLD_IMAGES_ */