]>
Commit | Line | Data |
---|---|---|
39236c6e A |
1 | /* |
2 | * Copyright (c) 2006, 2007, 2010 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
0a7de745 | 5 | * |
39236c6e A |
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. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
0a7de745 | 12 | * |
39236c6e A |
13 | * The Original Code and all software distributed under the License are |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
0a7de745 | 20 | * |
39236c6e A |
21 | * @APPLE_LICENSE_HEADER_END@ |
22 | */ | |
23 | #ifndef _LIBPROC_H_ | |
24 | #define _LIBPROC_H_ | |
25 | ||
26 | #include <sys/cdefs.h> | |
27 | #include <sys/param.h> | |
28 | #include <sys/types.h> | |
29 | #include <sys/stat.h> | |
30 | #include <sys/mount.h> | |
31 | #include <sys/resource.h> | |
32 | #include <stdint.h> | |
33 | #include <stdbool.h> | |
f427ee49 | 34 | #include <mach/message.h> /* for audit_token_t */ |
39236c6e A |
35 | |
36 | #include <sys/proc_info.h> | |
37 | ||
38 | #include <Availability.h> | |
f427ee49 | 39 | #include <os/availability.h> |
39236c6e A |
40 | |
41 | /* | |
0a7de745 | 42 | * This header file contains private interfaces to obtain process information. |
39236c6e A |
43 | * These interfaces are subject to change in future releases. |
44 | */ | |
45 | ||
46 | /*! | |
0a7de745 A |
47 | * @define PROC_LISTPIDSPATH_PATH_IS_VOLUME |
48 | * @discussion This flag indicates that all processes that hold open | |
49 | * file references on the volume associated with the specified | |
50 | * path should be returned. | |
39236c6e | 51 | */ |
0a7de745 | 52 | #define PROC_LISTPIDSPATH_PATH_IS_VOLUME 1 |
39236c6e A |
53 | |
54 | ||
55 | /*! | |
0a7de745 A |
56 | * @define PROC_LISTPIDSPATH_EXCLUDE_EVTONLY |
57 | * @discussion This flag indicates that file references that were opened | |
58 | * with the O_EVTONLY flag should be excluded from the matching | |
59 | * criteria. | |
39236c6e | 60 | */ |
0a7de745 | 61 | #define PROC_LISTPIDSPATH_EXCLUDE_EVTONLY 2 |
39236c6e A |
62 | |
63 | __BEGIN_DECLS | |
64 | ||
65 | ||
66 | /*! | |
0a7de745 A |
67 | * @function proc_listpidspath |
68 | * @discussion A function which will search through the current | |
69 | * processes looking for open file references which match | |
70 | * a specified path or volume. | |
71 | * @param type types of processes to be searched (see proc_listpids) | |
72 | * @param typeinfo adjunct information for type | |
73 | * @param path file or volume path | |
74 | * @param pathflags flags to control which files should be considered | |
75 | * during the process search. | |
76 | * @param buffer a C array of int-sized values to be filled with | |
77 | * process identifiers that hold an open file reference | |
78 | * matching the specified path or volume. Pass NULL to | |
79 | * obtain the minimum buffer size needed to hold the | |
80 | * currently active processes. | |
81 | * @param buffersize the size (in bytes) of the provided buffer. | |
82 | * @result the number of bytes of data returned in the provided buffer; | |
83 | * -1 if an error was encountered; | |
39236c6e | 84 | */ |
0a7de745 A |
85 | int proc_listpidspath(uint32_t type, |
86 | uint32_t typeinfo, | |
87 | const char *path, | |
88 | uint32_t pathflags, | |
89 | void *buffer, | |
90 | int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); | |
39236c6e A |
91 | |
92 | int proc_listpids(uint32_t type, uint32_t typeinfo, void *buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); | |
93 | int proc_listallpids(void * buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_1); | |
94 | int proc_listpgrppids(pid_t pgrpid, void * buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_1); | |
95 | int proc_listchildpids(pid_t ppid, void * buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_1); | |
0a7de745 | 96 | int proc_pidinfo(int pid, int flavor, uint64_t arg, void *buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); |
39236c6e A |
97 | int proc_pidfdinfo(int pid, int fd, int flavor, void * buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); |
98 | int proc_pidfileportinfo(int pid, uint32_t fileport, int flavor, void *buffer, int buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3); | |
99 | int proc_name(int pid, void * buffer, uint32_t buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); | |
100 | int proc_regionfilename(int pid, uint64_t address, void * buffer, uint32_t buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); | |
101 | int proc_kmsgbuf(void * buffer, uint32_t buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); | |
102 | int proc_pidpath(int pid, void * buffer, uint32_t buffersize) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); | |
f427ee49 | 103 | int proc_pidpath_audittoken(audit_token_t *audittoken, void * buffer, uint32_t buffersize) API_AVAILABLE(macos(10.16), ios(14.0), watchos(7.0), tvos(14.0)); |
39236c6e A |
104 | int proc_libversion(int *major, int * minor) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); |
105 | ||
106 | /* | |
107 | * Return resource usage information for the given pid, which can be a live process or a zombie. | |
108 | * | |
109 | * Returns 0 on success; or -1 on failure, with errno set to indicate the specific error. | |
110 | */ | |
111 | int proc_pid_rusage(int pid, int flavor, rusage_info_t *buffer) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0); | |
112 | ||
0a7de745 A |
113 | /* |
114 | * A process can use the following api to set its own process control | |
39236c6e A |
115 | * state on resoure starvation. The argument can have one of the PROC_SETPC_XX values |
116 | */ | |
0a7de745 A |
117 | #define PROC_SETPC_NONE 0 |
118 | #define PROC_SETPC_THROTTLEMEM 1 | |
119 | #define PROC_SETPC_SUSPEND 2 | |
120 | #define PROC_SETPC_TERMINATE 3 | |
39236c6e A |
121 | |
122 | int proc_setpcontrol(const int control) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2); | |
123 | int proc_setpcontrol(const int control); | |
124 | ||
125 | int proc_track_dirty(pid_t pid, uint32_t flags); | |
126 | int proc_set_dirty(pid_t pid, bool dirty); | |
127 | int proc_get_dirty(pid_t pid, uint32_t *flags); | |
fe8ab488 | 128 | int proc_clear_dirty(pid_t pid, uint32_t flags); |
39236c6e A |
129 | |
130 | int proc_terminate(pid_t pid, int *sig); | |
131 | ||
f427ee49 A |
132 | /* |
133 | * NO_SMT means that on an SMT CPU, this thread must be scheduled alone, | |
134 | * with the paired CPU idle. | |
135 | * | |
136 | * Set NO_SMT on the current proc (all existing and future threads) | |
137 | * This attribute is inherited on fork and exec | |
138 | */ | |
139 | int proc_set_no_smt(void) __API_AVAILABLE(macos(10.16)); | |
140 | ||
141 | /* Set NO_SMT on the current thread */ | |
142 | int proc_setthread_no_smt(void) __API_AVAILABLE(macos(10.16)); | |
143 | ||
144 | /* | |
145 | * CPU Security Mitigation APIs | |
146 | * | |
147 | * Set CPU security mitigation on the current proc (all existing and future threads) | |
148 | * This attribute is inherited on fork and exec | |
149 | */ | |
150 | int proc_set_csm(uint32_t flags) __API_AVAILABLE(macos(10.16)); | |
151 | ||
152 | /* Set CPU security mitigation on the current thread */ | |
153 | int proc_setthread_csm(uint32_t flags) __API_AVAILABLE(macos(10.16)); | |
154 | ||
155 | /* | |
156 | * flags for CPU Security Mitigation APIs | |
157 | * PROC_CSM_ALL should be used in most cases, | |
158 | * the individual flags are provided only for performance evaluation etc | |
159 | */ | |
160 | #define PROC_CSM_ALL 0x0001 /* Set all available mitigations */ | |
161 | #define PROC_CSM_NOSMT 0x0002 /* Set NO_SMT - see above */ | |
162 | #define PROC_CSM_TECS 0x0004 /* Execute VERW on every return to user mode */ | |
163 | ||
3e170ce0 | 164 | #ifdef PRIVATE |
5c9f4661 | 165 | #include <sys/event.h> |
3e170ce0 A |
166 | /* |
167 | * Enumerate potential userspace pointers embedded in kernel data structures. | |
168 | * Currently inspects kqueues only. | |
169 | * | |
170 | * NOTE: returned "pointers" are opaque user-supplied values and thus not | |
171 | * guaranteed to address valid objects or be pointers at all. | |
172 | * | |
173 | * Returns the number of pointers found (which may exceed buffersize), or -1 on | |
174 | * failure and errno set appropriately. | |
175 | */ | |
176 | int proc_list_uptrs(pid_t pid, uint64_t *buffer, uint32_t buffersize); | |
5ba3f43e A |
177 | |
178 | int proc_list_dynkqueueids(int pid, kqueue_id_t *buf, uint32_t bufsz); | |
179 | int proc_piddynkqueueinfo(int pid, int flavor, kqueue_id_t kq_id, void *buffer, | |
0a7de745 | 180 | int buffersize); |
3e170ce0 A |
181 | #endif /* PRIVATE */ |
182 | ||
a39ff7e2 A |
183 | int proc_udata_info(int pid, int flavor, void *buffer, int buffersize); |
184 | ||
39236c6e A |
185 | __END_DECLS |
186 | ||
187 | #endif /*_LIBPROC_H_ */ |