]> git.saurik.com Git - apple/dyld.git/blob - src/dyld_process_info_internal.h
dyld-851.27.tar.gz
[apple/dyld.git] / src / dyld_process_info_internal.h
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2016 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 #ifndef _DYLD_PROCESS_INFO_INTERNAL_H_
26 #define _DYLD_PROCESS_INFO_INTERNAL_H_
27
28 #define VIS_HIDDEN __attribute__((visibility("hidden")))
29
30 #include <stdlib.h>
31 #include <string.h>
32 #include <limits.h>
33 #include <stdio.h>
34 #include <uuid/uuid.h>
35
36 #include <array>
37
38 struct dyld_all_image_infos_32 {
39 uint32_t version;
40 uint32_t infoArrayCount;
41 std::atomic<uint32_t> infoArray;
42 uint32_t notification;
43 bool processDetachedFromSharedRegion;
44 bool libSystemInitialized;
45 uint32_t dyldImageLoadAddress;
46 uint32_t jitInfo;
47 uint32_t dyldVersion;
48 uint32_t errorMessage;
49 uint32_t terminationFlags;
50 uint32_t coreSymbolicationShmPage;
51 uint32_t systemOrderFlag;
52 uint32_t uuidArrayCount;
53 uint32_t uuidArray;
54 uint32_t dyldAllImageInfosAddress;
55 uint32_t initialImageCount;
56 uint32_t errorKind;
57 uint32_t errorClientOfDylibPath;
58 uint32_t errorTargetDylibPath;
59 uint32_t errorSymbol;
60 uint32_t sharedCacheSlide;
61 std::array<uint8_t, 16> sharedCacheUUID;
62 uint32_t sharedCacheBaseAddress;
63 std::atomic<uint64_t> infoArrayChangeTimestamp;
64 uint32_t dyldPath;
65 uint32_t notifyMachPorts[8];
66 uint32_t reserved[5];
67 uint32_t compact_dyld_image_info_addr;
68 uint32_t compact_dyld_image_info_size;
69 uint32_t platform;
70 // the aot fields below will not be set in the 32 bit case
71 uint32_t aotInfoCount;
72 std::atomic<uint64_t> aotInfoArray;
73 uint64_t aotInfoArrayChangeTimestamp;
74 uint64_t aotSharedCacheBaseAddress;
75 std::array<uint8_t, 16> aotSharedCacheUUID[16];
76 };
77
78 struct dyld_all_image_infos_64 {
79 uint32_t version;
80 uint32_t infoArrayCount;
81 std::atomic<uint64_t> infoArray;
82 uint64_t notification;
83 bool processDetachedFromSharedRegion;
84 bool libSystemInitialized;
85 uint32_t paddingToMakeTheSizeCorrectOn32bitAndDoesntAffect64b; // NOT PART OF DYLD_ALL_IMAGE_INFOS!
86 uint64_t dyldImageLoadAddress;
87 uint64_t jitInfo;
88 uint64_t dyldVersion;
89 uint64_t errorMessage;
90 uint64_t terminationFlags;
91 uint64_t coreSymbolicationShmPage;
92 uint64_t systemOrderFlag;
93 uint64_t uuidArrayCount;
94 uint64_t uuidArray;
95 uint64_t dyldAllImageInfosAddress;
96 uint64_t initialImageCount;
97 uint64_t errorKind;
98 uint64_t errorClientOfDylibPath;
99 uint64_t errorTargetDylibPath;
100 uint64_t errorSymbol;
101 uint64_t sharedCacheSlide;
102 std::array<uint8_t, 16> sharedCacheUUID;
103 uint64_t sharedCacheBaseAddress;
104 std::atomic<uint64_t> infoArrayChangeTimestamp;
105 uint64_t dyldPath;
106 uint32_t notifyMachPorts[8];
107 uint64_t reserved[9];
108 uint64_t compact_dyld_image_info_addr;
109 uint64_t compact_dyld_image_info_size;
110 uint32_t platform;
111 uint32_t aotInfoCount;
112 std::atomic<uint64_t> aotInfoArray;
113 uint64_t aotInfoArrayChangeTimestamp;
114 uint64_t aotSharedCacheBaseAddress;
115 std::array<uint8_t, 16> aotSharedCacheUUID[16];
116 };
117
118 struct dyld_image_info_32 {
119 uint32_t imageLoadAddress;
120 uint32_t imageFilePath;
121 uint32_t imageFileModDate;
122 };
123 struct dyld_image_info_64 {
124 uint64_t imageLoadAddress;
125 uint64_t imageFilePath;
126 uint64_t imageFileModDate;
127 };
128
129 #define DYLD_AOT_IMAGE_KEY_SIZE 32
130 struct dyld_aot_image_info_64 {
131 uint64_t x86LoadAddress;
132 uint64_t aotLoadAddress;
133 uint64_t aotImageSize;
134 uint8_t aotImageKey[DYLD_AOT_IMAGE_KEY_SIZE];
135 };
136
137 #define DYLD_PROCESS_INFO_NOTIFY_MAX_BUFFER_SIZE (32*1024)
138 #define DYLD_PROCESS_INFO_NOTIFY_LOAD_ID 0x1000
139 #define DYLD_PROCESS_INFO_NOTIFY_UNLOAD_ID 0x2000
140 #define DYLD_PROCESS_INFO_NOTIFY_MAIN_ID 0x3000
141
142
143 struct dyld_process_info_image_entry {
144 uuid_t uuid;
145 uint64_t loadAddress;
146 uint32_t pathStringOffset;
147 uint32_t pathLength;
148 };
149
150 struct dyld_process_info_notify_header {
151 mach_msg_header_t header;
152 uint32_t version;
153 uint32_t imageCount;
154 uint32_t imagesOffset;
155 uint32_t stringsOffset;
156 uint64_t timestamp;
157 };
158
159 //FIXME: Refactor this out into a seperate file
160 struct VIS_HIDDEN RemoteBuffer {
161 RemoteBuffer();
162 RemoteBuffer(task_t task, mach_vm_address_t remote_address, size_t remote_size, bool allow_truncation);
163 RemoteBuffer& operator=(RemoteBuffer&& other);
164 ~RemoteBuffer();
165 void *getLocalAddress() const;
166 kern_return_t getKernelReturn() const;
167 size_t getSize() const;
168 private:
169 static std::pair<mach_vm_address_t, kern_return_t> map( task_t task, mach_vm_address_t remote_address, vm_size_t _size);
170 static std::tuple<mach_vm_address_t,vm_size_t,kern_return_t>create( task_t task,
171 mach_vm_address_t remote_address,
172 size_t remote_size,
173 bool allow_truncation);
174 RemoteBuffer(std::tuple<mach_vm_address_t,vm_size_t,kern_return_t> T);
175
176 mach_vm_address_t _localAddress;
177 vm_size_t _size;
178 kern_return_t _kr;
179 };
180
181 // only called during libdyld set up
182 void setNotifyMonitoringDyldMain(void (*func)()) VIS_HIDDEN;
183 void setNotifyMonitoringDyld(void (*func)(bool unloading, unsigned imageCount,
184 const struct mach_header* loadAddresses[],
185 const char* imagePaths[])) VIS_HIDDEN;
186
187 void withRemoteBuffer(task_t task, mach_vm_address_t remote_address, size_t remote_size, bool allow_truncation, kern_return_t *kr, void (^block)(void *buffer, size_t size)) __attribute__((visibility("hidden")));
188
189 template<typename T>
190 VIS_HIDDEN void withRemoteObject(task_t task, mach_vm_address_t remote_address, kern_return_t *kr, void (^block)(T t))
191 {
192 withRemoteBuffer(task, remote_address, sizeof(T), false, kr, ^(void *buffer, size_t size) {
193 block(*reinterpret_cast<T *>(buffer));
194 });
195 }
196
197
198 #endif // _DYLD_PROCESS_INFO_INTERNAL_H_
199
200