1/*
2 * Copyright (c) 2005-2021 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _SYS_PROC_INFO_PRIVATE_H
30#define _SYS_PROC_INFO_PRIVATE_H
31
32#include <mach/coalition.h>
33#include <mach/machine.h>
34#include <stdint.h>
35#include <sys/cdefs.h>
36#include <sys/event_private.h>
37#include <sys/proc_info.h>
38#include <sys/types.h>
39#include <uuid/uuid.h>
40
41__BEGIN_DECLS
42
43
44struct proc_uniqidentifierinfo {
45 uint8_t p_uuid[16]; /* UUID of the main executable */
46 uint64_t p_uniqueid; /* 64 bit unique identifier for process */
47 uint64_t p_puniqueid; /* unique identifier for process's parent */
48 int32_t p_idversion; /* pid version */
49 uint32_t p_reserve2; /* reserved for future use */
50 uint64_t p_reserve3; /* reserved for future use */
51 uint64_t p_reserve4; /* reserved for future use */
52};
53
54
55struct proc_bsdinfowithuniqid {
56 struct proc_bsdinfo pbsd;
57 struct proc_uniqidentifierinfo p_uniqidentifier;
58};
59
60struct proc_archinfo {
61 cpu_type_t p_cputype;
62 cpu_subtype_t p_cpusubtype;
63};
64
65struct proc_pidcoalitioninfo {
66 uint64_t coalition_id[COALITION_NUM_TYPES];
67 uint64_t reserved1;
68 uint64_t reserved2;
69 uint64_t reserved3;
70};
71
72struct proc_originatorinfo {
73 uuid_t originator_uuid; /* UUID of the originator process */
74 pid_t originator_pid; /* pid of the originator process */
75 uint64_t p_reserve2;
76 uint64_t p_reserve3;
77 uint64_t p_reserve4;
78};
79
80struct proc_ipctableinfo {
81 uint32_t table_size;
82 uint32_t table_free;
83};
84
85struct proc_threadschedinfo {
86 uint64_t int_time_ns; /* time spent in interrupt context */
87};
88
89// See PROC_PIDTHREADCOUNTS for a description of how to use these structures.
90
91struct proc_threadcounts_data {
92 uint64_t ptcd_instructions;
93 uint64_t ptcd_cycles;
94 uint64_t ptcd_user_time_mach;
95 uint64_t ptcd_system_time_mach;
96 uint64_t ptcd_energy_nj;
97};
98
99struct proc_threadcounts {
100 uint16_t ptc_len;
101 uint16_t ptc_reserved0;
102 uint32_t ptc_reserved1;
103 struct proc_threadcounts_data ptc_counts[];
104};
105
106
107#define PROC_FLAG_DARWINBG 0x8000 /* process in darwin background */
108#define PROC_FLAG_EXT_DARWINBG 0x10000 /* process in darwin background - external enforcement */
109#define PROC_FLAG_IOS_APPLEDAEMON 0x20000 /* Process is apple daemon */
110#define PROC_FLAG_DELAYIDLESLEEP 0x40000 /* Process is marked to delay idle sleep on disk IO */
111#define PROC_FLAG_IOS_IMPPROMOTION 0x80000 /* Process is daemon which receives importane donation */
112#define PROC_FLAG_ADAPTIVE 0x100000 /* Process is adaptive */
113#define PROC_FLAG_ADAPTIVE_IMPORTANT 0x200000 /* Process is adaptive, and is currently important */
114#define PROC_FLAG_IMPORTANCE_DONOR 0x400000 /* Process is marked as an importance donor */
115#define PROC_FLAG_SUPPRESSED 0x800000 /* Process is suppressed */
116#define PROC_FLAG_APPLICATION 0x1000000 /* Process is an application */
117#define PROC_FLAG_IOS_APPLICATION PROC_FLAG_APPLICATION /* Process is an application */
118#define PROC_FLAG_ROSETTA 0x2000000 /* Process is running translated under Rosetta */
119
120
121/* keep in sync with KQ_* in sys/eventvar.h */
122#define PROC_KQUEUE_WORKQ 0x0040
123#define PROC_KQUEUE_WORKLOOP 0x0080
124
125struct kevent_extinfo {
126 struct kevent_qos_s kqext_kev;
127 uint64_t kqext_sdata;
128 int kqext_status;
129 int kqext_sfflags;
130 uint64_t kqext_reserved[2];
131};
132
133/* Flavors for proc_pidinfo() */
134#define PROC_PIDUNIQIDENTIFIERINFO 17
135#define PROC_PIDUNIQIDENTIFIERINFO_SIZE \
136 (sizeof(struct proc_uniqidentifierinfo))
137
138#define PROC_PIDT_BSDINFOWITHUNIQID 18
139#define PROC_PIDT_BSDINFOWITHUNIQID_SIZE \
140 (sizeof(struct proc_bsdinfowithuniqid))
141
142#define PROC_PIDARCHINFO 19
143#define PROC_PIDARCHINFO_SIZE \
144 (sizeof(struct proc_archinfo))
145
146#define PROC_PIDCOALITIONINFO 20
147#define PROC_PIDCOALITIONINFO_SIZE (sizeof(struct proc_pidcoalitioninfo))
148
149#define PROC_PIDNOTEEXIT 21
150#define PROC_PIDNOTEEXIT_SIZE (sizeof(uint32_t))
151
152#define PROC_PIDREGIONPATHINFO2 22
153#define PROC_PIDREGIONPATHINFO2_SIZE (sizeof(struct proc_regionwithpathinfo))
154
155#define PROC_PIDREGIONPATHINFO3 23
156#define PROC_PIDREGIONPATHINFO3_SIZE (sizeof(struct proc_regionwithpathinfo))
157
158#define PROC_PIDEXITREASONINFO 24
159#define PROC_PIDEXITREASONINFO_SIZE (sizeof(struct proc_exitreasoninfo))
160
161#define PROC_PIDEXITREASONBASICINFO 25
162#define PROC_PIDEXITREASONBASICINFOSIZE (sizeof(struct proc_exitreasonbasicinfo))
163
164#define PROC_PIDLISTUPTRS 26
165#define PROC_PIDLISTUPTRS_SIZE (sizeof(uint64_t))
166
167#define PROC_PIDLISTDYNKQUEUES 27
168#define PROC_PIDLISTDYNKQUEUES_SIZE (sizeof(kqueue_id_t))
169
170#define PROC_PIDLISTTHREADIDS 28
171#define PROC_PIDLISTTHREADIDS_SIZE (2* sizeof(uint32_t))
172
173#define PROC_PIDVMRTFAULTINFO 29
174#define PROC_PIDVMRTFAULTINFO_SIZE (7 * sizeof(uint64_t))
175
176#define PROC_PIDPLATFORMINFO 30
177#define PROC_PIDPLATFORMINFO_SIZE (sizeof(uint32_t))
178
179#define PROC_PIDREGIONPATH 31
180#define PROC_PIDREGIONPATH_SIZE (sizeof(struct proc_regionpath))
181
182#define PROC_PIDIPCTABLEINFO 32
183#define PROC_PIDIPCTABLEINFO_SIZE (sizeof(struct proc_ipctableinfo))
184
185#define PROC_PIDTHREADSCHEDINFO 33
186#define PROC_PIDTHREADSCHEDINFO_SIZE (sizeof(struct proc_threadschedinfo))
187
188// PROC_PIDTHREADCOUNTS returns a list of counters for the given thread,
189// separated out by the "perf-level" it was running on (typically either
190// "performance" or "efficiency").
191//
192// This interface works a bit differently from the other proc_info(3) flavors.
193// It copies out a structure with a variable-length array at the end of it.
194// The start of the `proc_threadcounts` structure contains a header indicating
195// the length of the subsequent array of `proc_threadcounts_data` elements.
196//
197// To use this interface, first read the `hw.nperflevels` sysctl to find out how
198// large to make the allocation that receives the counter data:
199//
200// sizeof(proc_threadcounts) + nperflevels * sizeof(proc_threadcounts_data)
201//
202// Use the `hw.perflevel[0-9].name` sysctl to find out which perf-level maps to
203// each entry in the array.
204//
205// The complete usage would be (omitting error reporting):
206//
207// uint32_t len = 0;
208// int ret = sysctlbyname("hw.nperflevels", &len, &len_sz, NULL, 0);
209// size_t size = sizeof(struct proc_threadcounts) +
210// len * sizeof(struct proc_threadcounts_data);
211// struct proc_threadcounts *counts = malloc(size);
212// // Fill this in with a thread ID, like from `PROC_PIDLISTTHREADS`.
213// uint64_t tid = 0;
214// int size_copied = proc_info(getpid(), PROC_PIDTHREADCOUNTS, tid, counts,
215// size);
216
217#define PROC_PIDTHREADCOUNTS 34
218#define PROC_PIDTHREADCOUNTS_SIZE (sizeof(struct proc_threadcounts))
219
220/* Flavors for proc_pidfdinfo */
221
222#define PROC_PIDFDKQUEUE_EXTINFO 9
223#define PROC_PIDFDKQUEUE_EXTINFO_SIZE (sizeof(struct kevent_extinfo))
224#define PROC_PIDFDKQUEUE_KNOTES_MAX (1024 * 128)
225#define PROC_PIDDYNKQUEUES_MAX (1024 * 128)
226
227
228/* Flavors for proc_pidoriginatorinfo */
229#define PROC_PIDORIGINATOR_UUID 0x1
230#define PROC_PIDORIGINATOR_UUID_SIZE (sizeof(uuid_t))
231
232#define PROC_PIDORIGINATOR_BGSTATE 0x2
233#define PROC_PIDORIGINATOR_BGSTATE_SIZE (sizeof(uint32_t))
234
235#define PROC_PIDORIGINATOR_PID_UUID 0x3
236#define PROC_PIDORIGINATOR_PID_UUID_SIZE (sizeof(struct proc_originatorinfo))
237
238/* Flavors for proc_listcoalitions */
239#define LISTCOALITIONS_ALL_COALS 1
240#define LISTCOALITIONS_ALL_COALS_SIZE (sizeof(struct procinfo_coalinfo))
241
242#define LISTCOALITIONS_SINGLE_TYPE 2
243#define LISTCOALITIONS_SINGLE_TYPE_SIZE (sizeof(struct procinfo_coalinfo))
244
245/* reasons for proc_can_use_foreground_hw */
246#define PROC_FGHW_OK 0 /* pid may use foreground HW */
247#define PROC_FGHW_DAEMON_OK 1
248#define PROC_FGHW_DAEMON_LEADER 10 /* pid is in a daemon coalition */
249#define PROC_FGHW_LEADER_NONUI 11 /* coalition leader is in a non-focal state */
250#define PROC_FGHW_LEADER_BACKGROUND 12 /* coalition leader is in a background state */
251#define PROC_FGHW_DAEMON_NO_VOUCHER 13 /* pid is a daemon with no adopted voucher */
252#define PROC_FGHW_NO_VOUCHER_ATTR 14 /* pid has adopted a voucher with no bank/originator attribute */
253#define PROC_FGHW_NO_ORIGINATOR 15 /* pid has adopted a voucher for a process that's gone away */
254#define PROC_FGHW_ORIGINATOR_BACKGROUND 16 /* pid has adopted a voucher for an app that's in the background */
255#define PROC_FGHW_VOUCHER_ERROR 98 /* error in voucher / originator callout */
256#define PROC_FGHW_ERROR 99 /* syscall parameter/permissions error */
257
258/* flavors for proc_piddynkqueueinfo */
259#define PROC_PIDDYNKQUEUE_INFO 0
260#define PROC_PIDDYNKQUEUE_INFO_SIZE (sizeof(struct kqueue_dyninfo))
261#define PROC_PIDDYNKQUEUE_EXTINFO 1
262#define PROC_PIDDYNKQUEUE_EXTINFO_SIZE (sizeof(struct kevent_extinfo))
263
264/* __proc_info() call numbers */
265#define PROC_INFO_CALL_LISTPIDS 0x1
266#define PROC_INFO_CALL_PIDINFO 0x2
267#define PROC_INFO_CALL_PIDFDINFO 0x3
268#define PROC_INFO_CALL_KERNMSGBUF 0x4
269#define PROC_INFO_CALL_SETCONTROL 0x5
270#define PROC_INFO_CALL_PIDFILEPORTINFO 0x6
271#define PROC_INFO_CALL_TERMINATE 0x7
272#define PROC_INFO_CALL_DIRTYCONTROL 0x8
273#define PROC_INFO_CALL_PIDRUSAGE 0x9
274#define PROC_INFO_CALL_PIDORIGINATORINFO 0xa
275#define PROC_INFO_CALL_LISTCOALITIONS 0xb
276#define PROC_INFO_CALL_CANUSEFGHW 0xc
277#define PROC_INFO_CALL_PIDDYNKQUEUEINFO 0xd
278#define PROC_INFO_CALL_UDATA_INFO 0xe
279#define PROC_INFO_CALL_SET_DYLD_IMAGES 0xf
280#define PROC_INFO_CALL_TERMINATE_RSR 0x10
281#define PROC_INFO_CALL_SIGNAL_AUDITTOKEN 0x11
282#define PROC_INFO_CALL_TERMINATE_AUDITTOKEN 0x12
283
284/* __proc_info_extended_id() flags */
285#define PIF_COMPARE_IDVERSION 0x01
286#define PIF_COMPARE_UNIQUEID 0x02
287
288#ifdef KERNEL_PRIVATE
289extern int proc_fdlist(proc_t p, struct proc_fdinfo *buf, size_t *count);
290extern int proc_pidoriginatorpid_uuid(uuid_t uuid, uint32_t buffersize, pid_t *pid);
291#endif
292
293#ifdef XNU_KERNEL_PRIVATE
294#ifndef pshmnode
295struct pshmnode;
296#endif
297
298#ifndef psemnode
299struct psemnode;
300#endif
301
302#ifndef pipe
303struct pipe;
304#endif
305
306extern int fill_socketinfo(socket_t so, struct socket_info *si);
307extern int fill_pshminfo(struct pshmnode * pshm, struct pshm_info * pinfo);
308extern int fill_pseminfo(struct psemnode * psem, struct psem_info * pinfo);
309extern int fill_pipeinfo(struct pipe * cpipe, struct pipe_info * pinfo);
310extern int fill_kqueueinfo(struct kqueue * kq, struct kqueue_info * kinfo);
311extern int pid_kqueue_extinfo(proc_t, struct kqueue * kq, user_addr_t buffer,
312 uint32_t buffersize, int32_t * retval);
313extern int pid_kqueue_udatainfo(proc_t p, struct kqueue *kq, uint64_t *buf,
314 uint32_t bufsize);
315extern int pid_kqueue_listdynamickqueues(proc_t p, user_addr_t ubuf,
316 uint32_t bufsize, int32_t *retval);
317extern int pid_dynamickqueue_extinfo(proc_t p, kqueue_id_t kq_id,
318 user_addr_t ubuf, uint32_t bufsize, int32_t *retval);
319struct kern_channel;
320extern int fill_channelinfo(struct kern_channel * chan,
321 struct proc_channel_info *chan_info);
322extern int fill_procworkqueue(proc_t, struct proc_workqueueinfo *);
323extern boolean_t workqueue_get_pwq_exceeded(void *v, boolean_t *exceeded_total,
324 boolean_t *exceeded_constrained);
325extern uint32_t workqueue_get_pwq_state_kdp(void *proc);
326
327#endif /* XNU_KERNEL_PRIVATE */
328
329__END_DECLS
330
331#endif /*_SYS_PROC_INFO_PRIVATE_H */
332