]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/resource.h
xnu-2422.90.20.tar.gz
[apple/xnu.git] / bsd / sys / resource.h
CommitLineData
1c79356b 1/*
b0d623f7 2 * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
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. 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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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
9bccf70c 67#include <sys/appleapiopts.h>
91447636
A
68#include <sys/cdefs.h>
69#include <sys/_types.h>
70
39236c6e
A
71#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
72#include <stdint.h>
73#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
74
75#ifndef KERNEL
6d2010ae
A
76#include <Availability.h>
77#endif
91447636
A
78
79/* [XSI] The timeval structure shall be defined as described in
80 * <sys/time.h>
91447636 81 */
39236c6e 82#include <sys/_types/_timeval.h>
b0d623f7 83#ifdef KERNEL
39236c6e
A
84#include <sys/_types/_user32_timeval.h>
85#include <sys/_types/_user64_timeval.h>
b0d623f7 86#endif
91447636
A
87
88/* The id_t type shall be defined as described in <sys/types.h> */
39236c6e 89#include <sys/_types/_id_t.h>
91447636 90
9bccf70c 91
1c79356b 92/*
91447636
A
93 * Resource limit type (low 63 bits, excluding the sign bit)
94 */
2d21ac55 95typedef __uint64_t rlim_t;
91447636
A
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
39236c6e 110#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
2d21ac55 111#define PRIO_DARWIN_THREAD 3 /* Second argument is always 0 (current thread) */
b7266188 112#define PRIO_DARWIN_PROCESS 4 /* Second argument is a PID */
2d21ac55 113
91447636
A
114/*
115 * Range limitations for the value of the third parameter to setpriority().
1c79356b
A
116 */
117#define PRIO_MIN -20
118#define PRIO_MAX 20
2d21ac55 119
b7266188
A
120/*
121 * use PRIO_DARWIN_BG to set the current thread into "background" state
2d21ac55
A
122 * which lowers CPU, disk IO, and networking priorites until thread terminates
123 * or "background" state is revoked
124 */
125#define PRIO_DARWIN_BG 0x1000
126
6d2010ae
A
127/*
128 * use PRIO_DARWIN_NONUI to restrict a process's ability to make calls to
129 * the GPU.
130 */
131#define PRIO_DARWIN_NONUI 0x1001
132
39236c6e 133#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
1c79356b 134
1c79356b 135
91447636
A
136
137/*****
138 * RESOURCE USAGE
1c79356b
A
139 */
140
91447636
A
141/*
142 * Possible values of the first parameter to getrusage(), used to indicate
143 * the scope of the information to be returned.
144 */
145#define RUSAGE_SELF 0 /* Current process information */
146#define RUSAGE_CHILDREN -1 /* Current process' children */
1c79356b 147
91447636
A
148/*
149 * A structure representing an accounting of resource utilization. The
150 * address of an instance of this structure is the second parameter to
151 * getrusage().
152 *
153 * Note: All values other than ru_utime and ru_stime are implementaiton
154 * defined and subject to change in a future release. Their use
155 * is discouraged for standards compliant programs.
156 */
1c79356b 157struct rusage {
2d21ac55
A
158 struct timeval ru_utime; /* user time used (PL) */
159 struct timeval ru_stime; /* system time used (PL) */
39236c6e 160#if __DARWIN_C_LEVEL < __DARWIN_C_FULL
91447636 161 long ru_opaque[14]; /* implementation defined */
39236c6e 162#else
91447636
A
163 /*
164 * Informational aliases for source compatibility with programs
165 * that need more information than that provided by standards,
166 * and which do not mind being OS-dependent.
167 */
2d21ac55 168 long ru_maxrss; /* max resident set size (PL) */
91447636 169#define ru_first ru_ixrss /* internal: ruadd() range start */
2d21ac55
A
170 long ru_ixrss; /* integral shared memory size (NU) */
171 long ru_idrss; /* integral unshared data (NU) */
172 long ru_isrss; /* integral unshared stack (NU) */
173 long ru_minflt; /* page reclaims (NU) */
174 long ru_majflt; /* page faults (NU) */
175 long ru_nswap; /* swaps (NU) */
176 long ru_inblock; /* block input operations (atomic) */
177 long ru_oublock; /* block output operations (atomic) */
178 long ru_msgsnd; /* messages sent (atomic) */
179 long ru_msgrcv; /* messages received (atomic) */
180 long ru_nsignals; /* signals received (atomic) */
181 long ru_nvcsw; /* voluntary context switches (atomic) */
1c79356b 182 long ru_nivcsw; /* involuntary " */
91447636 183#define ru_last ru_nivcsw /* internal: ruadd() range end */
39236c6e
A
184#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
185};
186
187#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
188/*
189 * Flavors for proc_pid_rusage().
190 */
191#define RUSAGE_INFO_V0 0
192#define RUSAGE_INFO_V1 1
193#define RUSAGE_INFO_V2 2
194#define RUSAGE_INFO_CURRENT RUSAGE_INFO_V2
195
196typedef void *rusage_info_t;
197
198struct rusage_info_v0 {
199 uint8_t ri_uuid[16];
200 uint64_t ri_user_time;
201 uint64_t ri_system_time;
202 uint64_t ri_pkg_idle_wkups;
203 uint64_t ri_interrupt_wkups;
204 uint64_t ri_pageins;
205 uint64_t ri_wired_size;
206 uint64_t ri_resident_size;
207 uint64_t ri_phys_footprint;
208 uint64_t ri_proc_start_abstime;
209 uint64_t ri_proc_exit_abstime;
91447636
A
210};
211
39236c6e
A
212struct rusage_info_v1 {
213 uint8_t ri_uuid[16];
214 uint64_t ri_user_time;
215 uint64_t ri_system_time;
216 uint64_t ri_pkg_idle_wkups;
217 uint64_t ri_interrupt_wkups;
218 uint64_t ri_pageins;
219 uint64_t ri_wired_size;
220 uint64_t ri_resident_size;
221 uint64_t ri_phys_footprint;
222 uint64_t ri_proc_start_abstime;
223 uint64_t ri_proc_exit_abstime;
224 uint64_t ri_child_user_time;
225 uint64_t ri_child_system_time;
226 uint64_t ri_child_pkg_idle_wkups;
227 uint64_t ri_child_interrupt_wkups;
228 uint64_t ri_child_pageins;
229 uint64_t ri_child_elapsed_abstime;
230};
231
232struct rusage_info_v2 {
233 uint8_t ri_uuid[16];
234 uint64_t ri_user_time;
235 uint64_t ri_system_time;
236 uint64_t ri_pkg_idle_wkups;
237 uint64_t ri_interrupt_wkups;
238 uint64_t ri_pageins;
239 uint64_t ri_wired_size;
240 uint64_t ri_resident_size;
241 uint64_t ri_phys_footprint;
242 uint64_t ri_proc_start_abstime;
243 uint64_t ri_proc_exit_abstime;
244 uint64_t ri_child_user_time;
245 uint64_t ri_child_system_time;
246 uint64_t ri_child_pkg_idle_wkups;
247 uint64_t ri_child_interrupt_wkups;
248 uint64_t ri_child_pageins;
249 uint64_t ri_child_elapsed_abstime;
250 uint64_t ri_diskio_bytesread;
251 uint64_t ri_diskio_byteswritten;
252};
253
254#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
91447636 255
91447636 256#ifdef KERNEL
91447636 257
39236c6e
A
258struct rusage_superset {
259 struct rusage ru;
260 struct rusage_info_v2 ri;
261};
262
263struct rusage_info_child {
264 uint64_t ri_child_user_time;
265 uint64_t ri_child_system_time;
266 uint64_t ri_child_pkg_idle_wkups;
267 uint64_t ri_child_interrupt_wkups;
268 uint64_t ri_child_pageins;
269 uint64_t ri_child_elapsed_abstime;
270};
271
272struct rusage_info_diskiobytes {
273 volatile uint64_t ri_bytesread __attribute__((aligned(8)));
274 volatile uint64_t ri_byteswritten __attribute__((aligned(8)));
275};
276
b0d623f7
A
277struct user64_rusage {
278 struct user64_timeval ru_utime; /* user time used */
279 struct user64_timeval ru_stime; /* system time used */
280 user64_long_t ru_maxrss; /* max resident set size */
281 user64_long_t ru_ixrss; /* integral shared memory size */
282 user64_long_t ru_idrss; /* integral unshared data " */
283 user64_long_t ru_isrss; /* integral unshared stack " */
284 user64_long_t ru_minflt; /* page reclaims */
285 user64_long_t ru_majflt; /* page faults */
286 user64_long_t ru_nswap; /* swaps */
287 user64_long_t ru_inblock; /* block input operations */
288 user64_long_t ru_oublock; /* block output operations */
289 user64_long_t ru_msgsnd; /* messages sent */
290 user64_long_t ru_msgrcv; /* messages received */
291 user64_long_t ru_nsignals; /* signals received */
292 user64_long_t ru_nvcsw; /* voluntary context switches */
293 user64_long_t ru_nivcsw; /* involuntary " */
294};
91447636 295
b0d623f7
A
296struct user32_rusage {
297 struct user32_timeval ru_utime; /* user time used */
298 struct user32_timeval ru_stime; /* system time used */
299 user32_long_t ru_maxrss; /* max resident set size */
300 user32_long_t ru_ixrss; /* integral shared memory size */
301 user32_long_t ru_idrss; /* integral unshared data " */
302 user32_long_t ru_isrss; /* integral unshared stack " */
303 user32_long_t ru_minflt; /* page reclaims */
304 user32_long_t ru_majflt; /* page faults */
305 user32_long_t ru_nswap; /* swaps */
306 user32_long_t ru_inblock; /* block input operations */
307 user32_long_t ru_oublock; /* block output operations */
308 user32_long_t ru_msgsnd; /* messages sent */
309 user32_long_t ru_msgrcv; /* messages received */
310 user32_long_t ru_nsignals; /* signals received */
311 user32_long_t ru_nvcsw; /* voluntary context switches */
312 user32_long_t ru_nivcsw; /* involuntary " */
1c79356b
A
313};
314
b0d623f7 315#endif /* KERNEL */
91447636
A
316
317
318/*****
319 * RESOURCE LIMITS
320 */
321
1c79356b 322/*
91447636
A
323 * Symbolic constants for resource limits; since all limits are representable
324 * as a type rlim_t, we are permitted to define RLIM_SAVED_* in terms of
325 * RLIM_INFINITY.
1c79356b 326 */
91447636
A
327#define RLIM_INFINITY (((__uint64_t)1 << 63) - 1) /* no limit */
328#define RLIM_SAVED_MAX RLIM_INFINITY /* Unrepresentable hard limit */
329#define RLIM_SAVED_CUR RLIM_INFINITY /* Unrepresentable soft limit */
330
331/*
332 * Possible values of the first parameter to getrlimit()/setrlimit(), to
333 * indicate for which resource the operation is being performed.
334 */
2d21ac55 335#define RLIMIT_CPU 0 /* cpu time per process */
91447636
A
336#define RLIMIT_FSIZE 1 /* file size */
337#define RLIMIT_DATA 2 /* data segment size */
1c79356b
A
338#define RLIMIT_STACK 3 /* stack size */
339#define RLIMIT_CORE 4 /* core file size */
91447636 340#define RLIMIT_AS 5 /* address space (resident set size) */
39236c6e 341#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
91447636 342#define RLIMIT_RSS RLIMIT_AS /* source compatibility alias */
1c79356b
A
343#define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */
344#define RLIMIT_NPROC 7 /* number of processes */
39236c6e 345#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
1c79356b 346#define RLIMIT_NOFILE 8 /* number of open files */
39236c6e 347#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
91447636 348#define RLIM_NLIMITS 9 /* total number of resource limits */
39236c6e 349#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
2d21ac55 350#define _RLIMIT_POSIX_FLAG 0x1000 /* Set bit for strict POSIX */
1c79356b 351
91447636
A
352/*
353 * A structure representing a resource limit. The address of an instance
354 * of this structure is the second parameter to getrlimit()/setrlimit().
355 */
1c79356b
A
356struct rlimit {
357 rlim_t rlim_cur; /* current (soft) limit */
358 rlim_t rlim_max; /* maximum value for rlim_cur */
359};
360
39236c6e
A
361#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
362/*
363 * proc_rlimit_control()
364 *
365 * Resource limit flavors
366 */
367#define RLIMIT_WAKEUPS_MONITOR 0x1 /* Configure the wakeups monitor. */
368#define RLIMIT_CPU_USAGE_MONITOR 0x2 /* Configure the CPU usage monitor. */
369
370/*
371 * Flags for wakeups monitor control.
372 */
373#define WAKEMON_ENABLE 0x01
374#define WAKEMON_DISABLE 0x02
375#define WAKEMON_GET_PARAMS 0x04
376#define WAKEMON_SET_DEFAULTS 0x08
377#define WAKEMON_MAKE_FATAL 0x10 /* Configure the task so that violations are fatal. */
378/*
379 * Flags for CPU usage monitor control.
380 */
381#define CPUMON_MAKE_FATAL 0x1000
382
383struct proc_rlimit_control_wakeupmon {
384 uint32_t wm_flags;
385 int32_t wm_rate;
386};
387
2d21ac55
A
388/* I/O type */
389#define IOPOL_TYPE_DISK 0
39236c6e
A
390#if PRIVATE
391#define IOPOL_TYPE_VFS_HFS_CASE_SENSITIVITY 1
392#endif
2d21ac55
A
393
394/* scope */
395#define IOPOL_SCOPE_PROCESS 0
396#define IOPOL_SCOPE_THREAD 1
39236c6e 397#define IOPOL_SCOPE_DARWIN_BG 2
2d21ac55
A
398
399/* I/O Priority */
39236c6e
A
400#define IOPOL_DEFAULT 0
401#define IOPOL_IMPORTANT 1
402#define IOPOL_PASSIVE 2
403#define IOPOL_THROTTLE 3
404#define IOPOL_UTILITY 4
405#define IOPOL_STANDARD 5
406
407/* compatibility with older names */
408#define IOPOL_APPLICATION IOPOL_STANDARD
409#define IOPOL_NORMAL IOPOL_IMPORTANT
410
411#if PRIVATE
412#define IOPOL_VFS_HFS_CASE_SENSITIVITY_DEFAULT 0
413#define IOPOL_VFS_HFS_CASE_SENSITIVITY_FORCE_CASE_SENSITIVE 1
414#endif
2d21ac55
A
415
416#ifdef PRIVATE
417/*
39236c6e
A
418 * Structures for use in communicating via iopolicysys() between Libc and the
419 * kernel. Not to be used by user programs directly.
2d21ac55
A
420 */
421
422/*
423 * the command to iopolicysys()
424 */
425#define IOPOL_CMD_GET 0x00000001 /* Get I/O policy */
426#define IOPOL_CMD_SET 0x00000002 /* Set I/O policy */
427
428/*
429 * Second parameter to iopolicysys()
430 */
431struct _iopol_param_t {
432 int iop_scope; /* current process or a thread */
433 int iop_iotype;
434 int iop_policy;
435};
436
437#endif /* PRIVATE */
39236c6e 438#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
1c79356b 439
91447636 440#ifndef KERNEL
1c79356b
A
441
442__BEGIN_DECLS
91447636 443int getpriority(int, id_t);
39236c6e 444#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
6d2010ae 445int getiopolicy_np(int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
39236c6e 446#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
2d21ac55 447int getrlimit(int, struct rlimit *) __DARWIN_ALIAS(getrlimit);
91447636
A
448int getrusage(int, struct rusage *);
449int setpriority(int, id_t, int);
39236c6e 450#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
6d2010ae 451int setiopolicy_np(int, int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
39236c6e 452#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
2d21ac55 453int setrlimit(int, const struct rlimit *) __DARWIN_ALIAS(setrlimit);
1c79356b
A
454__END_DECLS
455
91447636 456#endif /* !KERNEL */
1c79356b 457#endif /* !_SYS_RESOURCE_H_ */