xref: /xnu-10002.1.13/bsd/sys/resource.h (revision 1031c584a5e37aff177559b9f69dbd3c8c3fd30a) !
1 /*
2  * Copyright (c) 2000-2018 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 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29 /*
30  * Copyright (c) 1982, 1986, 1993
31  *	The Regents of the University of California.  All rights reserved.
32  *
33  * Redistribution and use in source and binary forms, with or without
34  * modification, are permitted provided that the following conditions
35  * are met:
36  * 1. Redistributions of source code must retain the above copyright
37  *    notice, this list of conditions and the following disclaimer.
38  * 2. Redistributions in binary form must reproduce the above copyright
39  *    notice, this list of conditions and the following disclaimer in the
40  *    documentation and/or other materials provided with the distribution.
41  * 3. All advertising materials mentioning features or use of this software
42  *    must display the following acknowledgement:
43  *	This product includes software developed by the University of
44  *	California, Berkeley and its contributors.
45  * 4. Neither the name of the University nor the names of its contributors
46  *    may be used to endorse or promote products derived from this software
47  *    without specific prior written permission.
48  *
49  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59  * SUCH DAMAGE.
60  *
61  *	@(#)resource.h	8.2 (Berkeley) 1/4/94
62  */
63 
64 #ifndef _SYS_RESOURCE_H_
65 #define _SYS_RESOURCE_H_
66 
67 #include <sys/appleapiopts.h>
68 #include <sys/cdefs.h>
69 #include <sys/_types.h>
70 
71 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
72 #include <stdint.h>
73 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
74 
75 #ifndef KERNEL
76 #include <Availability.h>
77 #endif
78 
79 /* [XSI] The timeval structure shall be defined as described in
80  * <sys/time.h>
81  */
82 #include <sys/_types/_timeval.h>
83 #ifdef KERNEL
84 #include <sys/_types/_user32_timeval.h>
85 #include <sys/_types/_user64_timeval.h>
86 #endif
87 
88 /* The id_t type shall be defined as described in <sys/types.h> */
89 #include <sys/_types/_id_t.h>
90 
91 
92 /*
93  * Resource limit type (low 63 bits, excluding the sign bit)
94  */
95 typedef __uint64_t      rlim_t;
96 
97 
98 /*****
99  * PRIORITY
100  */
101 
102 /*
103  * Possible values of the first parameter to getpriority()/setpriority(),
104  * used to indicate the type of the second parameter.
105  */
106 #define PRIO_PROCESS    0               /* Second argument is a PID */
107 #define PRIO_PGRP       1               /* Second argument is a GID */
108 #define PRIO_USER       2               /* Second argument is a UID */
109 
110 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
111 #define PRIO_DARWIN_THREAD      3               /* Second argument is always 0 (current thread) */
112 #define PRIO_DARWIN_PROCESS     4               /* Second argument is a PID */
113 
114 #ifdef PRIVATE
115 
116 #define PRIO_DARWIN_GPU         5               /* Second argument is a PID */
117 
118 #define PRIO_DARWIN_GPU_ALLOW   0x1
119 #define PRIO_DARWIN_GPU_DENY    0x2
120 
121 #define PRIO_DARWIN_ROLE        6               /* Second argument is a PID */
122 
123 #define PRIO_DARWIN_ROLE_DEFAULT        0x0     /* Reset to default state */
124 #define PRIO_DARWIN_ROLE_UI_FOCAL       0x1     /* On  screen,     focal UI */
125 #define PRIO_DARWIN_ROLE_UI             0x2     /* On  screen UI,  focal unknown */
126 #define PRIO_DARWIN_ROLE_NON_UI         0x3     /* Off screen, non-focal UI */
127 #define PRIO_DARWIN_ROLE_UI_NON_FOCAL   0x4     /* On  screen, non-focal UI */
128 #define PRIO_DARWIN_ROLE_TAL_LAUNCH     0x5     /* Throttled-launch (for OS X TAL resume) */
129 #define PRIO_DARWIN_ROLE_DARWIN_BG      0x6     /* Throttled for running in the background */
130 
131 /* Additional private parameters to getpriority()/setpriority() are in resource_private.h */
132 
133 #endif /* PRIVATE */
134 
135 /*
136  * Range limitations for the value of the third parameter to setpriority().
137  */
138 #define PRIO_MIN        -20
139 #define PRIO_MAX        20
140 
141 /*
142  * use PRIO_DARWIN_BG to set the current thread into "background" state
143  * which lowers CPU, disk IO, and networking priorites until thread terminates
144  * or "background" state is revoked
145  */
146 #define PRIO_DARWIN_BG 0x1000
147 
148 /*
149  * use PRIO_DARWIN_NONUI to restrict a process's ability to make calls to
150  * the GPU. (deprecated)
151  */
152 #define PRIO_DARWIN_NONUI 0x1001
153 
154 #endif  /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
155 
156 
157 
158 /*****
159  * RESOURCE USAGE
160  */
161 
162 /*
163  * Possible values of the first parameter to getrusage(), used to indicate
164  * the scope of the information to be returned.
165  */
166 #define RUSAGE_SELF     0               /* Current process information */
167 #define RUSAGE_CHILDREN -1              /* Current process' children */
168 
169 /*
170  * A structure representing an accounting of resource utilization.  The
171  * address of an instance of this structure is the second parameter to
172  * getrusage().
173  *
174  * Note: All values other than ru_utime and ru_stime are implementaiton
175  *       defined and subject to change in a future release.  Their use
176  *       is discouraged for standards compliant programs.
177  */
178 struct  rusage {
179 	struct timeval ru_utime;        /* user time used (PL) */
180 	struct timeval ru_stime;        /* system time used (PL) */
181 #if __DARWIN_C_LEVEL < __DARWIN_C_FULL
182 	long    ru_opaque[14];          /* implementation defined */
183 #else
184 	/*
185 	 * Informational aliases for source compatibility with programs
186 	 * that need more information than that provided by standards,
187 	 * and which do not mind being OS-dependent.
188 	 */
189 	long    ru_maxrss;              /* max resident set size (PL) */
190 #define ru_first        ru_ixrss        /* internal: ruadd() range start */
191 	long    ru_ixrss;               /* integral shared memory size (NU) */
192 	long    ru_idrss;               /* integral unshared data (NU)  */
193 	long    ru_isrss;               /* integral unshared stack (NU) */
194 	long    ru_minflt;              /* page reclaims (NU) */
195 	long    ru_majflt;              /* page faults (NU) */
196 	long    ru_nswap;               /* swaps (NU) */
197 	long    ru_inblock;             /* block input operations (atomic) */
198 	long    ru_oublock;             /* block output operations (atomic) */
199 	long    ru_msgsnd;              /* messages sent (atomic) */
200 	long    ru_msgrcv;              /* messages received (atomic) */
201 	long    ru_nsignals;            /* signals received (atomic) */
202 	long    ru_nvcsw;               /* voluntary context switches (atomic) */
203 	long    ru_nivcsw;              /* involuntary " */
204 #define ru_last         ru_nivcsw       /* internal: ruadd() range end */
205 #endif  /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
206 };
207 
208 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
209 /*
210  * Flavors for proc_pid_rusage().
211  */
212 #define RUSAGE_INFO_V0  0
213 #define RUSAGE_INFO_V1  1
214 #define RUSAGE_INFO_V2  2
215 #define RUSAGE_INFO_V3  3
216 #define RUSAGE_INFO_V4  4
217 #define RUSAGE_INFO_V5  5
218 #define RUSAGE_INFO_V6  6
219 #define RUSAGE_INFO_CURRENT RUSAGE_INFO_V6
220 
221 /*
222  * Flags for RUSAGE_INFO_V5
223  */
224 #define RU_PROC_RUNS_RESLIDE    0x00000001      /* proc has reslid shared cache */
225 
226 typedef void *rusage_info_t;
227 
228 struct rusage_info_v0 {
229 	uint8_t  ri_uuid[16];
230 	uint64_t ri_user_time;
231 	uint64_t ri_system_time;
232 	uint64_t ri_pkg_idle_wkups;
233 	uint64_t ri_interrupt_wkups;
234 	uint64_t ri_pageins;
235 	uint64_t ri_wired_size;
236 	uint64_t ri_resident_size;
237 	uint64_t ri_phys_footprint;
238 	uint64_t ri_proc_start_abstime;
239 	uint64_t ri_proc_exit_abstime;
240 };
241 
242 struct rusage_info_v1 {
243 	uint8_t  ri_uuid[16];
244 	uint64_t ri_user_time;
245 	uint64_t ri_system_time;
246 	uint64_t ri_pkg_idle_wkups;
247 	uint64_t ri_interrupt_wkups;
248 	uint64_t ri_pageins;
249 	uint64_t ri_wired_size;
250 	uint64_t ri_resident_size;
251 	uint64_t ri_phys_footprint;
252 	uint64_t ri_proc_start_abstime;
253 	uint64_t ri_proc_exit_abstime;
254 	uint64_t ri_child_user_time;
255 	uint64_t ri_child_system_time;
256 	uint64_t ri_child_pkg_idle_wkups;
257 	uint64_t ri_child_interrupt_wkups;
258 	uint64_t ri_child_pageins;
259 	uint64_t ri_child_elapsed_abstime;
260 };
261 
262 struct rusage_info_v2 {
263 	uint8_t  ri_uuid[16];
264 	uint64_t ri_user_time;
265 	uint64_t ri_system_time;
266 	uint64_t ri_pkg_idle_wkups;
267 	uint64_t ri_interrupt_wkups;
268 	uint64_t ri_pageins;
269 	uint64_t ri_wired_size;
270 	uint64_t ri_resident_size;
271 	uint64_t ri_phys_footprint;
272 	uint64_t ri_proc_start_abstime;
273 	uint64_t ri_proc_exit_abstime;
274 	uint64_t ri_child_user_time;
275 	uint64_t ri_child_system_time;
276 	uint64_t ri_child_pkg_idle_wkups;
277 	uint64_t ri_child_interrupt_wkups;
278 	uint64_t ri_child_pageins;
279 	uint64_t ri_child_elapsed_abstime;
280 	uint64_t ri_diskio_bytesread;
281 	uint64_t ri_diskio_byteswritten;
282 };
283 
284 struct rusage_info_v3 {
285 	uint8_t  ri_uuid[16];
286 	uint64_t ri_user_time;
287 	uint64_t ri_system_time;
288 	uint64_t ri_pkg_idle_wkups;
289 	uint64_t ri_interrupt_wkups;
290 	uint64_t ri_pageins;
291 	uint64_t ri_wired_size;
292 	uint64_t ri_resident_size;
293 	uint64_t ri_phys_footprint;
294 	uint64_t ri_proc_start_abstime;
295 	uint64_t ri_proc_exit_abstime;
296 	uint64_t ri_child_user_time;
297 	uint64_t ri_child_system_time;
298 	uint64_t ri_child_pkg_idle_wkups;
299 	uint64_t ri_child_interrupt_wkups;
300 	uint64_t ri_child_pageins;
301 	uint64_t ri_child_elapsed_abstime;
302 	uint64_t ri_diskio_bytesread;
303 	uint64_t ri_diskio_byteswritten;
304 	uint64_t ri_cpu_time_qos_default;
305 	uint64_t ri_cpu_time_qos_maintenance;
306 	uint64_t ri_cpu_time_qos_background;
307 	uint64_t ri_cpu_time_qos_utility;
308 	uint64_t ri_cpu_time_qos_legacy;
309 	uint64_t ri_cpu_time_qos_user_initiated;
310 	uint64_t ri_cpu_time_qos_user_interactive;
311 	uint64_t ri_billed_system_time;
312 	uint64_t ri_serviced_system_time;
313 };
314 
315 struct rusage_info_v4 {
316 	uint8_t  ri_uuid[16];
317 	uint64_t ri_user_time;
318 	uint64_t ri_system_time;
319 	uint64_t ri_pkg_idle_wkups;
320 	uint64_t ri_interrupt_wkups;
321 	uint64_t ri_pageins;
322 	uint64_t ri_wired_size;
323 	uint64_t ri_resident_size;
324 	uint64_t ri_phys_footprint;
325 	uint64_t ri_proc_start_abstime;
326 	uint64_t ri_proc_exit_abstime;
327 	uint64_t ri_child_user_time;
328 	uint64_t ri_child_system_time;
329 	uint64_t ri_child_pkg_idle_wkups;
330 	uint64_t ri_child_interrupt_wkups;
331 	uint64_t ri_child_pageins;
332 	uint64_t ri_child_elapsed_abstime;
333 	uint64_t ri_diskio_bytesread;
334 	uint64_t ri_diskio_byteswritten;
335 	uint64_t ri_cpu_time_qos_default;
336 	uint64_t ri_cpu_time_qos_maintenance;
337 	uint64_t ri_cpu_time_qos_background;
338 	uint64_t ri_cpu_time_qos_utility;
339 	uint64_t ri_cpu_time_qos_legacy;
340 	uint64_t ri_cpu_time_qos_user_initiated;
341 	uint64_t ri_cpu_time_qos_user_interactive;
342 	uint64_t ri_billed_system_time;
343 	uint64_t ri_serviced_system_time;
344 	uint64_t ri_logical_writes;
345 	uint64_t ri_lifetime_max_phys_footprint;
346 	uint64_t ri_instructions;
347 	uint64_t ri_cycles;
348 	uint64_t ri_billed_energy;
349 	uint64_t ri_serviced_energy;
350 	uint64_t ri_interval_max_phys_footprint;
351 	uint64_t ri_runnable_time;
352 };
353 
354 struct rusage_info_v5 {
355 	uint8_t  ri_uuid[16];
356 	uint64_t ri_user_time;
357 	uint64_t ri_system_time;
358 	uint64_t ri_pkg_idle_wkups;
359 	uint64_t ri_interrupt_wkups;
360 	uint64_t ri_pageins;
361 	uint64_t ri_wired_size;
362 	uint64_t ri_resident_size;
363 	uint64_t ri_phys_footprint;
364 	uint64_t ri_proc_start_abstime;
365 	uint64_t ri_proc_exit_abstime;
366 	uint64_t ri_child_user_time;
367 	uint64_t ri_child_system_time;
368 	uint64_t ri_child_pkg_idle_wkups;
369 	uint64_t ri_child_interrupt_wkups;
370 	uint64_t ri_child_pageins;
371 	uint64_t ri_child_elapsed_abstime;
372 	uint64_t ri_diskio_bytesread;
373 	uint64_t ri_diskio_byteswritten;
374 	uint64_t ri_cpu_time_qos_default;
375 	uint64_t ri_cpu_time_qos_maintenance;
376 	uint64_t ri_cpu_time_qos_background;
377 	uint64_t ri_cpu_time_qos_utility;
378 	uint64_t ri_cpu_time_qos_legacy;
379 	uint64_t ri_cpu_time_qos_user_initiated;
380 	uint64_t ri_cpu_time_qos_user_interactive;
381 	uint64_t ri_billed_system_time;
382 	uint64_t ri_serviced_system_time;
383 	uint64_t ri_logical_writes;
384 	uint64_t ri_lifetime_max_phys_footprint;
385 	uint64_t ri_instructions;
386 	uint64_t ri_cycles;
387 	uint64_t ri_billed_energy;
388 	uint64_t ri_serviced_energy;
389 	uint64_t ri_interval_max_phys_footprint;
390 	uint64_t ri_runnable_time;
391 	uint64_t ri_flags;
392 };
393 
394 struct rusage_info_v6 {
395 	uint8_t  ri_uuid[16];
396 	uint64_t ri_user_time;
397 	uint64_t ri_system_time;
398 	uint64_t ri_pkg_idle_wkups;
399 	uint64_t ri_interrupt_wkups;
400 	uint64_t ri_pageins;
401 	uint64_t ri_wired_size;
402 	uint64_t ri_resident_size;
403 	uint64_t ri_phys_footprint;
404 	uint64_t ri_proc_start_abstime;
405 	uint64_t ri_proc_exit_abstime;
406 	uint64_t ri_child_user_time;
407 	uint64_t ri_child_system_time;
408 	uint64_t ri_child_pkg_idle_wkups;
409 	uint64_t ri_child_interrupt_wkups;
410 	uint64_t ri_child_pageins;
411 	uint64_t ri_child_elapsed_abstime;
412 	uint64_t ri_diskio_bytesread;
413 	uint64_t ri_diskio_byteswritten;
414 	uint64_t ri_cpu_time_qos_default;
415 	uint64_t ri_cpu_time_qos_maintenance;
416 	uint64_t ri_cpu_time_qos_background;
417 	uint64_t ri_cpu_time_qos_utility;
418 	uint64_t ri_cpu_time_qos_legacy;
419 	uint64_t ri_cpu_time_qos_user_initiated;
420 	uint64_t ri_cpu_time_qos_user_interactive;
421 	uint64_t ri_billed_system_time;
422 	uint64_t ri_serviced_system_time;
423 	uint64_t ri_logical_writes;
424 	uint64_t ri_lifetime_max_phys_footprint;
425 	uint64_t ri_instructions;
426 	uint64_t ri_cycles;
427 	uint64_t ri_billed_energy;
428 	uint64_t ri_serviced_energy;
429 	uint64_t ri_interval_max_phys_footprint;
430 	uint64_t ri_runnable_time;
431 	uint64_t ri_flags;
432 	uint64_t ri_user_ptime;
433 	uint64_t ri_system_ptime;
434 	uint64_t ri_pinstructions;
435 	uint64_t ri_pcycles;
436 	uint64_t ri_energy_nj;
437 	uint64_t ri_penergy_nj;
438 	uint64_t ri_reserved[14];
439 };
440 
441 typedef struct rusage_info_v6 rusage_info_current;
442 
443 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
444 
445 #ifdef KERNEL
446 
447 struct rusage_superset {
448 	struct rusage           ru;
449 	rusage_info_current     ri;
450 };
451 
452 struct rusage_info_child {
453 	uint64_t ri_child_user_time;
454 	uint64_t ri_child_system_time;
455 	uint64_t ri_child_pkg_idle_wkups;
456 	uint64_t ri_child_interrupt_wkups;
457 	uint64_t ri_child_pageins;
458 	uint64_t ri_child_elapsed_abstime;
459 };
460 
461 struct  user64_rusage {
462 	struct user64_timeval ru_utime; /* user time used */
463 	struct user64_timeval ru_stime; /* system time used */
464 	user64_long_t   ru_maxrss;              /* max resident set size */
465 	user64_long_t   ru_ixrss;               /* integral shared memory size */
466 	user64_long_t   ru_idrss;               /* integral unshared data " */
467 	user64_long_t   ru_isrss;               /* integral unshared stack " */
468 	user64_long_t   ru_minflt;              /* page reclaims */
469 	user64_long_t   ru_majflt;              /* page faults */
470 	user64_long_t   ru_nswap;               /* swaps */
471 	user64_long_t   ru_inblock;             /* block input operations */
472 	user64_long_t   ru_oublock;             /* block output operations */
473 	user64_long_t   ru_msgsnd;              /* messages sent */
474 	user64_long_t   ru_msgrcv;              /* messages received */
475 	user64_long_t   ru_nsignals;    /* signals received */
476 	user64_long_t   ru_nvcsw;               /* voluntary context switches */
477 	user64_long_t   ru_nivcsw;              /* involuntary " */
478 };
479 
480 struct  user32_rusage {
481 	struct user32_timeval ru_utime; /* user time used */
482 	struct user32_timeval ru_stime; /* system time used */
483 	user32_long_t   ru_maxrss;              /* max resident set size */
484 	user32_long_t   ru_ixrss;               /* integral shared memory size */
485 	user32_long_t   ru_idrss;               /* integral unshared data " */
486 	user32_long_t   ru_isrss;               /* integral unshared stack " */
487 	user32_long_t   ru_minflt;              /* page reclaims */
488 	user32_long_t   ru_majflt;              /* page faults */
489 	user32_long_t   ru_nswap;               /* swaps */
490 	user32_long_t   ru_inblock;             /* block input operations */
491 	user32_long_t   ru_oublock;             /* block output operations */
492 	user32_long_t   ru_msgsnd;              /* messages sent */
493 	user32_long_t   ru_msgrcv;              /* messages received */
494 	user32_long_t   ru_nsignals;    /* signals received */
495 	user32_long_t   ru_nvcsw;               /* voluntary context switches */
496 	user32_long_t   ru_nivcsw;              /* involuntary " */
497 };
498 
499 #endif /* KERNEL */
500 
501 
502 /*****
503  * RESOURCE LIMITS
504  */
505 
506 /*
507  * Symbolic constants for resource limits; since all limits are representable
508  * as a type rlim_t, we are permitted to define RLIM_SAVED_* in terms of
509  * RLIM_INFINITY.
510  */
511 #define RLIM_INFINITY   (((__uint64_t)1 << 63) - 1)     /* no limit */
512 #define RLIM_SAVED_MAX  RLIM_INFINITY   /* Unrepresentable hard limit */
513 #define RLIM_SAVED_CUR  RLIM_INFINITY   /* Unrepresentable soft limit */
514 
515 /*
516  * Possible values of the first parameter to getrlimit()/setrlimit(), to
517  * indicate for which resource the operation is being performed.
518  */
519 #define RLIMIT_CPU      0               /* cpu time per process */
520 #define RLIMIT_FSIZE    1               /* file size */
521 #define RLIMIT_DATA     2               /* data segment size */
522 #define RLIMIT_STACK    3               /* stack size */
523 #define RLIMIT_CORE     4               /* core file size */
524 #define RLIMIT_AS       5               /* address space (resident set size) */
525 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
526 #define RLIMIT_RSS      RLIMIT_AS       /* source compatibility alias */
527 #define RLIMIT_MEMLOCK  6               /* locked-in-memory address space */
528 #define RLIMIT_NPROC    7               /* number of processes */
529 #endif  /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
530 #define RLIMIT_NOFILE   8               /* number of open files */
531 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
532 #define RLIM_NLIMITS    9               /* total number of resource limits */
533 #endif  /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
534 #define _RLIMIT_POSIX_FLAG      0x1000  /* Set bit for strict POSIX */
535 
536 /*
537  * A structure representing a resource limit.  The address of an instance
538  * of this structure is the second parameter to getrlimit()/setrlimit().
539  */
540 struct rlimit {
541 	rlim_t  rlim_cur;               /* current (soft) limit */
542 	rlim_t  rlim_max;               /* maximum value for rlim_cur */
543 };
544 
545 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
546 /*
547  * proc_rlimit_control()
548  *
549  * Resource limit flavors
550  */
551 #define RLIMIT_WAKEUPS_MONITOR          0x1 /* Configure the wakeups monitor. */
552 #define RLIMIT_CPU_USAGE_MONITOR        0x2 /* Configure the CPU usage monitor. */
553 #define RLIMIT_THREAD_CPULIMITS         0x3 /* Configure a blocking, per-thread, CPU limits. */
554 #define RLIMIT_FOOTPRINT_INTERVAL       0x4 /* Configure memory footprint interval tracking */
555 
556 /*
557  * Flags for wakeups monitor control.
558  */
559 #define WAKEMON_ENABLE                  0x01
560 #define WAKEMON_DISABLE                 0x02
561 #define WAKEMON_GET_PARAMS              0x04
562 #define WAKEMON_SET_DEFAULTS            0x08
563 #define WAKEMON_MAKE_FATAL              0x10 /* Configure the task so that violations are fatal. */
564 
565 /*
566  * Flags for CPU usage monitor control.
567  */
568 #define CPUMON_MAKE_FATAL               0x1000
569 
570 /*
571  * Flags for memory footprint interval tracking.
572  */
573 #define FOOTPRINT_INTERVAL_RESET        0x1 /* Reset the footprint interval counter to zero */
574 
575 struct proc_rlimit_control_wakeupmon {
576 	uint32_t wm_flags;
577 	int32_t wm_rate;
578 };
579 
580 #if PRIVATE
581 /*
582  * Flags for I/O monitor control.
583  */
584 #define IOMON_ENABLE                    0x01
585 #define IOMON_DISABLE                   0x02
586 
587 #endif /* PRIVATE */
588 
589 
590 /* I/O type */
591 #define IOPOL_TYPE_DISK 0
592 #if PRIVATE
593 #define IOPOL_TYPE_VFS_HFS_CASE_SENSITIVITY 1
594 #endif
595 #define IOPOL_TYPE_VFS_ATIME_UPDATES 2
596 #define IOPOL_TYPE_VFS_MATERIALIZE_DATALESS_FILES 3
597 #define IOPOL_TYPE_VFS_STATFS_NO_DATA_VOLUME 4
598 #define IOPOL_TYPE_VFS_TRIGGER_RESOLVE 5
599 #define IOPOL_TYPE_VFS_IGNORE_CONTENT_PROTECTION 6
600 #define IOPOL_TYPE_VFS_IGNORE_PERMISSIONS 7
601 #define IOPOL_TYPE_VFS_SKIP_MTIME_UPDATE 8
602 #define IOPOL_TYPE_VFS_ALLOW_LOW_SPACE_WRITES 9
603 #define IOPOL_TYPE_VFS_DISALLOW_RW_FOR_O_EVTONLY 10
604 #if PRIVATE
605 #define IOPOL_TYPE_VFS_ALTLINK 11
606 #define IOPOL_TYPE_VFS_NOCACHE_WRITE_FS_BLKSIZE  12
607 #endif
608 
609 /* scope */
610 #define IOPOL_SCOPE_PROCESS   0
611 #define IOPOL_SCOPE_THREAD    1
612 #define IOPOL_SCOPE_DARWIN_BG 2
613 
614 /* I/O Priority */
615 #define IOPOL_DEFAULT           0
616 #define IOPOL_IMPORTANT         1
617 #define IOPOL_PASSIVE           2
618 #define IOPOL_THROTTLE          3
619 #define IOPOL_UTILITY           4
620 #define IOPOL_STANDARD          5
621 
622 /* compatibility with older names */
623 #define IOPOL_APPLICATION       IOPOL_STANDARD
624 #define IOPOL_NORMAL            IOPOL_IMPORTANT
625 
626 #if PRIVATE
627 #define IOPOL_VFS_HFS_CASE_SENSITIVITY_DEFAULT  0
628 #define IOPOL_VFS_HFS_CASE_SENSITIVITY_FORCE_CASE_SENSITIVE     1
629 
630 #define IOPOL_VFS_ALTLINK_DISABLED 0
631 #define IOPOL_VFS_ALTLINK_ENABLED  1
632 #endif
633 
634 #define IOPOL_ATIME_UPDATES_DEFAULT     0
635 #define IOPOL_ATIME_UPDATES_OFF         1
636 
637 #define IOPOL_MATERIALIZE_DATALESS_FILES_DEFAULT 0
638 #define IOPOL_MATERIALIZE_DATALESS_FILES_OFF     1
639 #define IOPOL_MATERIALIZE_DATALESS_FILES_ON      2
640 
641 #define IOPOL_VFS_STATFS_NO_DATA_VOLUME_DEFAULT 0
642 #define IOPOL_VFS_STATFS_FORCE_NO_DATA_VOLUME   1
643 
644 #define IOPOL_VFS_TRIGGER_RESOLVE_DEFAULT 0
645 #define IOPOL_VFS_TRIGGER_RESOLVE_OFF     1
646 
647 #define IOPOL_VFS_CONTENT_PROTECTION_DEFAULT 0
648 #define IOPOL_VFS_CONTENT_PROTECTION_IGNORE  1
649 
650 #define IOPOL_VFS_IGNORE_PERMISSIONS_OFF 0
651 #define IOPOL_VFS_IGNORE_PERMISSIONS_ON  1
652 
653 #define IOPOL_VFS_SKIP_MTIME_UPDATE_OFF 0
654 #define IOPOL_VFS_SKIP_MTIME_UPDATE_ON 1
655 
656 #define IOPOL_VFS_ALLOW_LOW_SPACE_WRITES_OFF 0
657 #define IOPOL_VFS_ALLOW_LOW_SPACE_WRITES_ON 1
658 
659 #define IOPOL_VFS_DISALLOW_RW_FOR_O_EVTONLY_DEFAULT 0
660 #define IOPOL_VFS_DISALLOW_RW_FOR_O_EVTONLY_ON 1
661 
662 #define IOPOL_VFS_NOCACHE_WRITE_FS_BLKSIZE_DEFAULT 0
663 #define IOPOL_VFS_NOCACHE_WRITE_FS_BLKSIZE_ON 1
664 
665 #ifdef PRIVATE
666 /*
667  * Structures for use in communicating via iopolicysys() between Libc and the
668  * kernel.  Not to be used by user programs directly.
669  */
670 
671 /*
672  * the command to iopolicysys()
673  */
674 #define IOPOL_CMD_GET           0x00000001      /* Get I/O policy */
675 #define IOPOL_CMD_SET           0x00000002      /* Set I/O policy */
676 
677 /*
678  * Second parameter to iopolicysys()
679  */
680 struct _iopol_param_t {
681 	int iop_scope;  /* current process or a thread */
682 	int iop_iotype;
683 	int iop_policy;
684 };
685 
686 #endif  /* PRIVATE */
687 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
688 
689 #ifndef KERNEL
690 
691 __BEGIN_DECLS
692 int     getpriority(int, id_t);
693 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
694 int     getiopolicy_np(int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
695 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
696 int     getrlimit(int, struct rlimit *) __DARWIN_ALIAS(getrlimit);
697 int     getrusage(int, struct rusage *);
698 int     setpriority(int, id_t, int);
699 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
700 int     setiopolicy_np(int, int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
701 #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
702 int     setrlimit(int, const struct rlimit *) __DARWIN_ALIAS(setrlimit);
703 __END_DECLS
704 
705 #endif  /* !KERNEL */
706 #endif  /* !_SYS_RESOURCE_H_ */
707