dyld-655.1.1.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 };
70
71 struct dyld_all_image_infos_64 {
72 uint32_t version;
73 uint32_t infoArrayCount;
74 std::atomic<uint64_t> infoArray;
75 uint64_t notification;
76 bool processDetachedFromSharedRegion;
77 bool libSystemInitialized;
78 uint32_t paddingToMakeTheSizeCorrectOn32bitAndDoesntAffect64b; // NOT PART OF DYLD_ALL_IMAGE_INFOS!
79 uint64_t dyldImageLoadAddress;
80 uint64_t jitInfo;
81 uint64_t dyldVersion;
82 uint64_t errorMessage;
83 uint64_t terminationFlags;
84 uint64_t coreSymbolicationShmPage;
85 uint64_t systemOrderFlag;
86 uint64_t uuidArrayCount;
87 uint64_t uuidArray;
88 uint64_t dyldAllImageInfosAddress;
89 uint64_t initialImageCount;
90 uint64_t errorKind;
91 uint64_t errorClientOfDylibPath;
92 uint64_t errorTargetDylibPath;
93 uint64_t errorSymbol;
94 uint64_t sharedCacheSlide;
95 std::array<uint8_t, 16> sharedCacheUUID;
96 uint64_t sharedCacheBaseAddress;
97 std::atomic<uint64_t> infoArrayChangeTimestamp;
98 uint64_t dyldPath;
99 uint32_t notifyMachPorts[8];
100 uint64_t reserved[9];
101 uint64_t compact_dyld_image_info_addr;
102 uint64_t compact_dyld_image_info_size;
103 };
104
105 struct dyld_image_info_32 {
106 uint32_t imageLoadAddress;
107 uint32_t imageFilePath;
108 uint32_t imageFileModDate;
109 };
110 struct dyld_image_info_64 {
111 uint64_t imageLoadAddress;
112 uint64_t imageFilePath;
113 uint64_t imageFileModDate;
114 };
115
116 #define DYLD_PROCESS_INFO_NOTIFY_MAX_BUFFER_SIZE (32*1024)
117 #define DYLD_PROCESS_INFO_NOTIFY_LOAD_ID 0x1000
118 #define DYLD_PROCESS_INFO_NOTIFY_UNLOAD_ID 0x2000
119 #define DYLD_PROCESS_INFO_NOTIFY_MAIN_ID 0x3000
120
121
122 struct dyld_process_info_image_entry {
123 uuid_t uuid;
124 uint64_t loadAddress;
125 uint32_t pathStringOffset;
126 uint32_t pathLength;
127 };
128
129 struct dyld_process_info_notify_header {
130 mach_msg_header_t header;
131 uint32_t version;
132 uint32_t imageCount;
133 uint32_t imagesOffset;
134 uint32_t stringsOffset;
135 uint64_t timestamp;
136 };
137
138 struct VIS_HIDDEN RemoteBuffer {
139 RemoteBuffer();
140 RemoteBuffer(task_t task, mach_vm_address_t remote_address, size_t remote_size, bool shared, bool allow_truncation);
141 ~RemoteBuffer();
142 RemoteBuffer& operator=(RemoteBuffer&& other) {
143 _localAddress = other._localAddress;
144 _size = other._size;
145 _kr = other._kr;
146 other._localAddress = 0;
147 other._size = 0;
148 other._kr = KERN_SUCCESS;
149 return *this;
150 }
151 RemoteBuffer(const RemoteBuffer &) = delete;
152 RemoteBuffer& operator=(const RemoteBuffer &) = delete;
153 void *getLocalAddress();
154 kern_return_t getKernelReturn();
155 size_t getSize();
156 private:
157 bool map(task_t task, mach_vm_address_t remote_address, bool shared);
158 mach_vm_address_t _localAddress;
159 vm_size_t _size;
160 kern_return_t _kr;
161 };
162
163 // only called during libdyld set up
164 void setNotifyMonitoringDyldMain(void (*func)()) VIS_HIDDEN;
165 void setNotifyMonitoringDyld(void (*func)(bool unloading, unsigned imageCount,
166 const struct mach_header* loadAddresses[],
167 const char* imagePaths[])) VIS_HIDDEN;
168
169 void withRemoteBuffer(task_t task, mach_vm_address_t remote_address, size_t remote_size, bool shared, bool allow_truncation, kern_return_t *kr, void (^block)(void *buffer, size_t size)) __attribute__((visibility("hidden")));
170
171 template<typename T>
172 VIS_HIDDEN void withRemoteObject(task_t task, mach_vm_address_t remote_address, bool shared, kern_return_t *kr, void (^block)(T t))
173 {
174 withRemoteBuffer(task, remote_address, sizeof(T), shared, false, kr, ^(void *buffer, size_t size) {
175 block(*reinterpret_cast<T *>(buffer));
176 });
177 }
178
179
180 #endif // _DYLD_PROCESS_INFO_INTERNAL_H_
181
182