-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmach_private.h
More file actions
335 lines (284 loc) · 11.5 KB
/
mach_private.h
File metadata and controls
335 lines (284 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <mach/mach_traps.h>
__BEGIN_DECLS
#define PTHREAD_FEATURE_DISPATCHFUNC 0x01 /* same as WQOPS_QUEUE_NEWSPISUPP, checks for dispatch function support */
#define PTHREAD_FEATURE_FINEPRIO 0x02 /* are fine grained prioirities available */
#define PTHREAD_FEATURE_BSDTHREADCTL 0x04 /* is the bsdthread_ctl syscall available */
#define PTHREAD_FEATURE_SETSELF 0x08 /* is the BSDTHREAD_CTL_SET_SELF command of bsdthread_ctl available */
#define PTHREAD_FEATURE_QOS_MAINTENANCE 0x10 /* is QOS_CLASS_MAINTENANCE available */
#define PTHREAD_FEATURE_RESERVED 0x20 /* burnt, shipped in OSX 10.11 & iOS 9 with partial kevent delivery support */
#define PTHREAD_FEATURE_KEVENT 0x40 /* supports direct kevent delivery */
#define PTHREAD_FEATURE_WORKLOOP 0x80 /* supports workloops */
#define PTHREAD_FEATURE_QOS_DEFAULT 0x40000000 /* the kernel supports QOS_CLASS_DEFAULT */
// Others
#define PROC_PIDT_SHORTBSDINFO 13
#define PROC_PIDT_SHORTBSDINFO_SIZE (sizeof(struct proc_bsdshortinfo))
struct proc_bsdshortinfo {
uint32_t pbsi_pid; /* process id */
uint32_t pbsi_ppid; /* process parent id */
uint32_t pbsi_pgid; /* process perp id */
uint32_t pbsi_status; /* p_stat value, SZOMB, SRUN, etc */
char pbsi_comm[MAXCOMLEN]; /* upto 16 characters of process name */
uint32_t pbsi_flags; /* 64bit; emulated etc */
uid_t pbsi_uid; /* current uid on process */
gid_t pbsi_gid; /* current gid on process */
uid_t pbsi_ruid; /* current ruid on process */
gid_t pbsi_rgid; /* current tgid on process */
uid_t pbsi_svuid; /* current svuid on process */
gid_t pbsi_svgid; /* current svgid on process */
uint32_t pbsi_rfu; /* reserved for future use*/
};
struct iovec_32 {
uint32_t guest_iov_base; /* Base address. */
size_t iov_len; /* Length. */
};
struct crashreporter_annotations_t {
uint64_t version; // unsigned long
uint64_t message; // char *
uint64_t signature_string; // char *
uint64_t backtrace; // char *
uint64_t message2; // char *
uint64_t thread; // uint64_t
uint64_t dialog_mode; // unsigned int
};
// Mach private
#ifdef __MigPackStructs
#pragma pack(push, 4)
#endif
typedef struct {
mach_msg_header_t Head;
char payload[];
} __Request___xpc_send_serializer_t __attribute__((unused));
typedef struct {
mach_msg_header_t Head;
NDR_record_t NDR;
kern_return_t RetCode;
} __Reply___xpc_send_serializer_t __attribute__((unused));
typedef struct {
mach_msg_header_t Head;
mach_msg_body_t msgh_body;
mach_msg_ool_descriptor_t name;
NDR_record_t NDR;
mach_msg_type_number_t nameCnt;
} __Request___notify_server_register_check_t __attribute__((unused));
typedef struct {
mach_msg_header_t Head;
NDR_record_t NDR;
kern_return_t RetCode;
int size;
int slot;
int token;
int status;
} __Reply___notify_server_register_check_t __attribute__((unused));
#ifdef __MigPackStructs
#pragma pack(pop)
#endif
typedef struct {
/* a mach_msg_header_t* or mach_msg_aux_header_t* */
mach_vm_address_t msgv_data;
/* if msgv_rcv_addr is non-zero, use it as rcv address instead */
mach_vm_address_t msgv_rcv_addr;
mach_msg_size_t msgv_send_size;
mach_msg_size_t msgv_rcv_size;
} mach_msg_vector_t;
__options_decl(mach_msg_option64_t, uint64_t, {
MACH64_MSG_OPTION_NONE = 0x0ull,
/* share lower 32 bits with mach_msg_option_t */
MACH64_SEND_MSG = MACH_SEND_MSG,
MACH64_RCV_MSG = MACH_RCV_MSG,
MACH64_RCV_LARGE = MACH_RCV_LARGE,
MACH64_RCV_LARGE_IDENTITY = MACH_RCV_LARGE_IDENTITY,
MACH64_SEND_TIMEOUT = MACH_SEND_TIMEOUT,
MACH64_SEND_OVERRIDE = MACH_SEND_OVERRIDE,
MACH64_SEND_INTERRUPT = MACH_SEND_INTERRUPT,
MACH64_SEND_NOTIFY = MACH_SEND_NOTIFY,
#if KERNEL
MACH64_SEND_ALWAYS = MACH_SEND_ALWAYS,
MACH64_SEND_IMPORTANCE = MACH_SEND_IMPORTANCE,
MACH64_SEND_KERNEL = MACH_SEND_KERNEL,
#endif
MACH64_SEND_FILTER_NONFATAL = MACH_SEND_FILTER_NONFATAL,
MACH64_SEND_TRAILER = MACH_SEND_TRAILER,
MACH64_SEND_NOIMPORTANCE = MACH_SEND_NOIMPORTANCE,
MACH64_SEND_NODENAP = MACH_SEND_NODENAP,
MACH64_SEND_SYNC_OVERRIDE = MACH_SEND_SYNC_OVERRIDE,
MACH64_SEND_PROPAGATE_QOS = MACH_SEND_PROPAGATE_QOS,
MACH64_SEND_SYNC_BOOTSTRAP_CHECKIN = MACH_SEND_SYNC_BOOTSTRAP_CHECKIN,
MACH64_RCV_TIMEOUT = MACH_RCV_TIMEOUT,
MACH64_RCV_INTERRUPT = MACH_RCV_INTERRUPT,
MACH64_RCV_VOUCHER = MACH_RCV_VOUCHER,
MACH64_RCV_GUARDED_DESC = MACH_RCV_GUARDED_DESC,
MACH64_RCV_SYNC_WAIT = MACH_RCV_SYNC_WAIT,
MACH64_RCV_SYNC_PEEK = MACH_RCV_SYNC_PEEK,
MACH64_MSG_STRICT_REPLY = MACH_MSG_STRICT_REPLY,
/* following options are 64 only */
/* Send and receive message as vectors */
MACH64_MSG_VECTOR = 0x0000000100000000ull,
/* The message is a kobject call */
MACH64_SEND_KOBJECT_CALL = 0x0000000200000000ull,
/* The message is sent to a message queue */
MACH64_SEND_MQ_CALL = 0x0000000400000000ull,
/* This message destination is unknown. Used by old simulators only. */
MACH64_SEND_ANY = 0x0000000800000000ull,
/* This message is a DriverKit call */
MACH64_SEND_DK_CALL = 0x0000001000000000ull,
#ifdef XNU_KERNEL_PRIVATE
/*
* Policy for the mach_msg2_trap() call
*/
MACH64_POLICY_KERNEL_EXTENSION = 0x0002000000000000ull,
MACH64_POLICY_FILTER_NON_FATAL = 0x0004000000000000ull,
MACH64_POLICY_FILTER_MSG = 0x0008000000000000ull,
MACH64_POLICY_DEFAULT = 0x0010000000000000ull,
#if XNU_TARGET_OS_OSX
MACH64_POLICY_SIMULATED = 0x0020000000000000ull,
#else
MACH64_POLICY_SIMULATED = 0x0000000000000000ull,
#endif
#if CONFIG_ROSETTA
MACH64_POLICY_TRANSLATED = 0x0040000000000000ull,
#else
MACH64_POLICY_TRANSLATED = 0x0000000000000000ull,
#endif
MACH64_POLICY_HARDENED = 0x0080000000000000ull,
MACH64_POLICY_RIGID = 0x0100000000000000ull,
MACH64_POLICY_PLATFORM = 0x0200000000000000ull,
MACH64_POLICY_KERNEL = MACH64_SEND_KERNEL,
/* one of these bits must be set to have a valid policy */
MACH64_POLICY_NEEDED_MASK = (
MACH64_POLICY_SIMULATED |
MACH64_POLICY_TRANSLATED |
MACH64_POLICY_DEFAULT |
MACH64_POLICY_HARDENED |
MACH64_POLICY_RIGID |
MACH64_POLICY_PLATFORM |
MACH64_POLICY_KERNEL),
/* extra policy modifiers */
MACH64_POLICY_MASK = (
MACH64_POLICY_KERNEL_EXTENSION |
MACH64_POLICY_FILTER_NON_FATAL |
MACH64_POLICY_FILTER_MSG |
MACH64_POLICY_NEEDED_MASK),
/*
* If kmsg has auxiliary data, append it immediate after the message
* and trailer.
*
* Must be used in conjunction with MACH64_MSG_VECTOR,
* only used by kevent() from the kernel.
*/
MACH64_RCV_LINEAR_VECTOR = 0x1000000000000000ull,
/* Receive into highest addr of buffer */
MACH64_RCV_STACK = 0x2000000000000000ull,
#if MACH_FLIPC
/*
* This internal-only flag is intended for use by a single thread per-port/set!
* If more than one thread attempts to MACH64_PEEK_MSG on a port or set, one of
* the threads may miss messages (in fact, it may never wake up).
*/
MACH64_PEEK_MSG = 0x4000000000000000ull,
#endif /* MACH_FLIPC */
/*
* This is a mach_msg2() send/receive operation.
*/
MACH64_MACH_MSG2 = 0x8000000000000000ull
#endif
});
// https://github.com/apple-oss-distributions/xnu/blob/main/osfmk/mach/message.h#L1481-L1528
extern mach_msg_return_t mach_msg2_internal(
void *data,
mach_msg_option64_t option64,
uint64_t msgh_bits_and_send_size,
uint64_t msgh_remote_and_local_port,
uint64_t msgh_voucher_and_id,
uint64_t desc_count_and_rcv_name,
uint64_t rcv_size_and_priority,
uint64_t timeout);
static inline mach_msg_return_t
mach_msg2(
void *data,
mach_msg_option64_t option64,
mach_msg_header_t header,
mach_msg_size_t send_size,
mach_msg_size_t rcv_size,
mach_port_t rcv_name,
uint64_t timeout,
uint32_t priority)
{
mach_msg_base_t *base;
mach_msg_size_t descriptors;
if (option64 & MACH64_MSG_VECTOR) {
base = (mach_msg_base_t *)((mach_msg_vector_t *)data)->msgv_data;
} else {
base = (mach_msg_base_t *)data;
}
if ((option64 & MACH64_SEND_MSG) &&
(base->header.msgh_bits & MACH_MSGH_BITS_COMPLEX)) {
descriptors = base->body.msgh_descriptor_count;
} else {
descriptors = 0;
}
#define MACH_MSG2_SHIFT_ARGS(lo, hi) ((uint64_t)hi << 32 | (uint32_t)lo)
return mach_msg2_internal(data, option64,
MACH_MSG2_SHIFT_ARGS(header.msgh_bits, send_size),
MACH_MSG2_SHIFT_ARGS(header.msgh_remote_port, header.msgh_local_port),
MACH_MSG2_SHIFT_ARGS(header.msgh_voucher_port, header.msgh_id),
MACH_MSG2_SHIFT_ARGS(descriptors, rcv_name),
MACH_MSG2_SHIFT_ARGS(rcv_size, priority), timeout);
#undef MACH_MSG2_SHIFT_ARGS
}
int __proc_info(int callnum, int pid, int flavor, uint64_t arg, void * buffer, int buffersize);
// Mach private
extern mach_port_name_t mach_reply_port(void);
extern mach_port_name_t thread_self_trap(void);
extern mach_port_name_t host_self_trap(void);
extern mach_msg_return_t mach_msg_trap(
mach_msg_header_t *msg,
mach_msg_option_t option,
mach_msg_size_t send_size,
mach_msg_size_t rcv_size,
mach_port_name_t rcv_name,
mach_msg_timeout_t timeout,
mach_port_name_t notify);
extern mach_msg_return_t mach_msg_overwrite_trap(
mach_msg_header_t *msg,
mach_msg_option_t option,
mach_msg_size_t send_size,
mach_msg_size_t rcv_size,
mach_port_name_t rcv_name,
mach_msg_timeout_t timeout,
mach_msg_priority_t priority,
mach_msg_header_t *rcv_msg,
mach_msg_size_t rcv_limit);
extern kern_return_t semaphore_signal_trap(
mach_port_name_t signal_name);
extern kern_return_t semaphore_signal_all_trap(
mach_port_name_t signal_name);
extern kern_return_t semaphore_signal_thread_trap(
mach_port_name_t signal_name,
mach_port_name_t thread_name);
extern kern_return_t semaphore_wait_trap(
mach_port_name_t wait_name);
extern kern_return_t semaphore_wait_signal_trap(
mach_port_name_t wait_name,
mach_port_name_t signal_name);
extern kern_return_t semaphore_timedwait_trap(
mach_port_name_t wait_name,
unsigned int sec,
clock_res_t nsec);
extern kern_return_t semaphore_timedwait_signal_trap(
mach_port_name_t wait_name,
mach_port_name_t signal_name,
unsigned int sec,
clock_res_t nsec);
// XPC private
extern kern_return_t _xpc_send_serializer(mach_port_t port, const char *payload);
// FIXME: uint64_t
extern uint32_t __thread_selfid(void);
extern void _pthread_set_self(pthread_t);
extern int __semwait_signal_nocancel(int, int, int, int, int64_t, int32_t);
extern int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
extern int __sysctlbyname(const char *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
size_t __getdirentries64(int fd, void *buf, size_t bufsize, __darwin_off_t *basep);
int getentropy(void *buffer, size_t length);
__END_DECLS