1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2016 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@
25 #ifndef _DYLD_PROCESS_INFO_INTERNAL_H_
26 #define _DYLD_PROCESS_INFO_INTERNAL_H_
28 #define VIS_HIDDEN __attribute__((visibility("hidden")))
34 #include <uuid/uuid.h>
38 struct dyld_all_image_infos_32
{
40 uint32_t infoArrayCount
;
41 std::atomic
<uint32_t> infoArray
;
42 uint32_t notification
;
43 bool processDetachedFromSharedRegion
;
44 bool libSystemInitialized
;
45 uint32_t dyldImageLoadAddress
;
48 uint32_t errorMessage
;
49 uint32_t terminationFlags
;
50 uint32_t coreSymbolicationShmPage
;
51 uint32_t systemOrderFlag
;
52 uint32_t uuidArrayCount
;
54 uint32_t dyldAllImageInfosAddress
;
55 uint32_t initialImageCount
;
57 uint32_t errorClientOfDylibPath
;
58 uint32_t errorTargetDylibPath
;
60 uint32_t sharedCacheSlide
;
61 std::array
<uint8_t, 16> sharedCacheUUID
;
62 uint32_t sharedCacheBaseAddress
;
63 std::atomic
<uint64_t> infoArrayChangeTimestamp
;
65 uint32_t notifyMachPorts
[8];
67 uint32_t compact_dyld_image_info_addr
;
68 uint32_t compact_dyld_image_info_size
;
72 struct dyld_all_image_infos_64
{
74 uint32_t infoArrayCount
;
75 std::atomic
<uint64_t> infoArray
;
76 uint64_t notification
;
77 bool processDetachedFromSharedRegion
;
78 bool libSystemInitialized
;
79 uint32_t paddingToMakeTheSizeCorrectOn32bitAndDoesntAffect64b
; // NOT PART OF DYLD_ALL_IMAGE_INFOS!
80 uint64_t dyldImageLoadAddress
;
83 uint64_t errorMessage
;
84 uint64_t terminationFlags
;
85 uint64_t coreSymbolicationShmPage
;
86 uint64_t systemOrderFlag
;
87 uint64_t uuidArrayCount
;
89 uint64_t dyldAllImageInfosAddress
;
90 uint64_t initialImageCount
;
92 uint64_t errorClientOfDylibPath
;
93 uint64_t errorTargetDylibPath
;
95 uint64_t sharedCacheSlide
;
96 std::array
<uint8_t, 16> sharedCacheUUID
;
97 uint64_t sharedCacheBaseAddress
;
98 std::atomic
<uint64_t> infoArrayChangeTimestamp
;
100 uint32_t notifyMachPorts
[8];
101 uint64_t reserved
[9];
102 uint64_t compact_dyld_image_info_addr
;
103 uint64_t compact_dyld_image_info_size
;
107 struct dyld_image_info_32
{
108 uint32_t imageLoadAddress
;
109 uint32_t imageFilePath
;
110 uint32_t imageFileModDate
;
112 struct dyld_image_info_64
{
113 uint64_t imageLoadAddress
;
114 uint64_t imageFilePath
;
115 uint64_t imageFileModDate
;
118 #define DYLD_PROCESS_INFO_NOTIFY_MAX_BUFFER_SIZE (32*1024)
119 #define DYLD_PROCESS_INFO_NOTIFY_LOAD_ID 0x1000
120 #define DYLD_PROCESS_INFO_NOTIFY_UNLOAD_ID 0x2000
121 #define DYLD_PROCESS_INFO_NOTIFY_MAIN_ID 0x3000
124 struct dyld_process_info_image_entry
{
126 uint64_t loadAddress
;
127 uint32_t pathStringOffset
;
131 struct dyld_process_info_notify_header
{
132 mach_msg_header_t header
;
135 uint32_t imagesOffset
;
136 uint32_t stringsOffset
;
140 //FIXME: Refactor this out into a seperate file
141 struct VIS_HIDDEN RemoteBuffer
{
143 RemoteBuffer(task_t task
, mach_vm_address_t remote_address
, size_t remote_size
, bool shared
, bool allow_truncation
);
144 RemoteBuffer
& operator=(RemoteBuffer
&& other
);
146 void *getLocalAddress() const;
147 kern_return_t
getKernelReturn() const;
148 size_t getSize() const;
150 static std::pair
<mach_vm_address_t
, kern_return_t
> map( task_t task
, mach_vm_address_t remote_address
,
151 vm_size_t _size
, bool shared
);
152 static std::tuple
<mach_vm_address_t
,vm_size_t
,kern_return_t
,bool>create( task_t task
,
153 mach_vm_address_t remote_address
,
156 bool allow_truncation
);
157 RemoteBuffer(std::tuple
<mach_vm_address_t
,vm_size_t
,kern_return_t
,bool> T
);
159 mach_vm_address_t _localAddress
;
165 // only called during libdyld set up
166 void setNotifyMonitoringDyldMain(void (*func
)()) VIS_HIDDEN
;
167 void setNotifyMonitoringDyld(void (*func
)(bool unloading
, unsigned imageCount
,
168 const struct mach_header
* loadAddresses
[],
169 const char* imagePaths
[])) VIS_HIDDEN
;
171 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")));
174 VIS_HIDDEN
void withRemoteObject(task_t task
, mach_vm_address_t remote_address
, bool shared
, kern_return_t
*kr
, void (^block
)(T t
))
176 withRemoteBuffer(task
, remote_address
, sizeof(T
), shared
, false, kr
, ^(void *buffer
, size_t size
) {
177 block(*reinterpret_cast<T
*>(buffer
));
182 #endif // _DYLD_PROCESS_INFO_INTERNAL_H_