]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/sys/resource.h
xnu-1504.3.12.tar.gz
[apple/xnu.git] / bsd / sys / resource.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000-2008 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
72/* [XSI] The timeval structure shall be defined as described in
73 * <sys/time.h>
74 */
75#define __need_struct_timeval
76#ifdef KERNEL
77#define __need_struct_user32_timeval
78#define __need_struct_user64_timeval
79#endif
80#include <sys/_structs.h>
81
82/* The id_t type shall be defined as described in <sys/types.h> */
83#ifndef _ID_T
84#define _ID_T
85typedef __darwin_id_t id_t; /* can hold pid_t, gid_t, or uid_t */
86#endif
87
88
89/*
90 * Resource limit type (low 63 bits, excluding the sign bit)
91 */
92typedef __uint64_t rlim_t;
93
94
95/*****
96 * PRIORITY
97 */
98
99/*
100 * Possible values of the first parameter to getpriority()/setpriority(),
101 * used to indicate the type of the second parameter.
102 */
103#define PRIO_PROCESS 0 /* Second argument is a PID */
104#define PRIO_PGRP 1 /* Second argument is a GID */
105#define PRIO_USER 2 /* Second argument is a UID */
106
107#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
108#define PRIO_DARWIN_THREAD 3 /* Second argument is always 0 (current thread) */
109#define PRIO_DARWIN_PROCESS 4 /* Second argument is a PID */
110
111/*
112 * Range limitations for the value of the third parameter to setpriority().
113 */
114#define PRIO_MIN -20
115#define PRIO_MAX 20
116
117/*
118 * use PRIO_DARWIN_BG to set the current thread into "background" state
119 * which lowers CPU, disk IO, and networking priorites until thread terminates
120 * or "background" state is revoked
121 */
122#define PRIO_DARWIN_BG 0x1000
123
124#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
125
126
127
128/*****
129 * RESOURCE USAGE
130 */
131
132/*
133 * Possible values of the first parameter to getrusage(), used to indicate
134 * the scope of the information to be returned.
135 */
136#define RUSAGE_SELF 0 /* Current process information */
137#define RUSAGE_CHILDREN -1 /* Current process' children */
138
139/*
140 * A structure representing an accounting of resource utilization. The
141 * address of an instance of this structure is the second parameter to
142 * getrusage().
143 *
144 * Note: All values other than ru_utime and ru_stime are implementaiton
145 * defined and subject to change in a future release. Their use
146 * is discouraged for standards compliant programs.
147 */
148struct rusage {
149 struct timeval ru_utime; /* user time used (PL) */
150 struct timeval ru_stime; /* system time used (PL) */
151#if defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE)
152 long ru_opaque[14]; /* implementation defined */
153#else /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
154 /*
155 * Informational aliases for source compatibility with programs
156 * that need more information than that provided by standards,
157 * and which do not mind being OS-dependent.
158 */
159 long ru_maxrss; /* max resident set size (PL) */
160#define ru_first ru_ixrss /* internal: ruadd() range start */
161 long ru_ixrss; /* integral shared memory size (NU) */
162 long ru_idrss; /* integral unshared data (NU) */
163 long ru_isrss; /* integral unshared stack (NU) */
164 long ru_minflt; /* page reclaims (NU) */
165 long ru_majflt; /* page faults (NU) */
166 long ru_nswap; /* swaps (NU) */
167 long ru_inblock; /* block input operations (atomic) */
168 long ru_oublock; /* block output operations (atomic) */
169 long ru_msgsnd; /* messages sent (atomic) */
170 long ru_msgrcv; /* messages received (atomic) */
171 long ru_nsignals; /* signals received (atomic) */
172 long ru_nvcsw; /* voluntary context switches (atomic) */
173 long ru_nivcsw; /* involuntary " */
174#define ru_last ru_nivcsw /* internal: ruadd() range end */
175#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
176};
177
178
179#ifdef KERNEL
180
181struct user64_rusage {
182 struct user64_timeval ru_utime; /* user time used */
183 struct user64_timeval ru_stime; /* system time used */
184 user64_long_t ru_maxrss; /* max resident set size */
185 user64_long_t ru_ixrss; /* integral shared memory size */
186 user64_long_t ru_idrss; /* integral unshared data " */
187 user64_long_t ru_isrss; /* integral unshared stack " */
188 user64_long_t ru_minflt; /* page reclaims */
189 user64_long_t ru_majflt; /* page faults */
190 user64_long_t ru_nswap; /* swaps */
191 user64_long_t ru_inblock; /* block input operations */
192 user64_long_t ru_oublock; /* block output operations */
193 user64_long_t ru_msgsnd; /* messages sent */
194 user64_long_t ru_msgrcv; /* messages received */
195 user64_long_t ru_nsignals; /* signals received */
196 user64_long_t ru_nvcsw; /* voluntary context switches */
197 user64_long_t ru_nivcsw; /* involuntary " */
198};
199
200struct user32_rusage {
201 struct user32_timeval ru_utime; /* user time used */
202 struct user32_timeval ru_stime; /* system time used */
203 user32_long_t ru_maxrss; /* max resident set size */
204 user32_long_t ru_ixrss; /* integral shared memory size */
205 user32_long_t ru_idrss; /* integral unshared data " */
206 user32_long_t ru_isrss; /* integral unshared stack " */
207 user32_long_t ru_minflt; /* page reclaims */
208 user32_long_t ru_majflt; /* page faults */
209 user32_long_t ru_nswap; /* swaps */
210 user32_long_t ru_inblock; /* block input operations */
211 user32_long_t ru_oublock; /* block output operations */
212 user32_long_t ru_msgsnd; /* messages sent */
213 user32_long_t ru_msgrcv; /* messages received */
214 user32_long_t ru_nsignals; /* signals received */
215 user32_long_t ru_nvcsw; /* voluntary context switches */
216 user32_long_t ru_nivcsw; /* involuntary " */
217};
218
219#endif /* KERNEL */
220
221
222/*****
223 * RESOURCE LIMITS
224 */
225
226/*
227 * Symbolic constants for resource limits; since all limits are representable
228 * as a type rlim_t, we are permitted to define RLIM_SAVED_* in terms of
229 * RLIM_INFINITY.
230 */
231#define RLIM_INFINITY (((__uint64_t)1 << 63) - 1) /* no limit */
232#define RLIM_SAVED_MAX RLIM_INFINITY /* Unrepresentable hard limit */
233#define RLIM_SAVED_CUR RLIM_INFINITY /* Unrepresentable soft limit */
234
235/*
236 * Possible values of the first parameter to getrlimit()/setrlimit(), to
237 * indicate for which resource the operation is being performed.
238 */
239#define RLIMIT_CPU 0 /* cpu time per process */
240#define RLIMIT_FSIZE 1 /* file size */
241#define RLIMIT_DATA 2 /* data segment size */
242#define RLIMIT_STACK 3 /* stack size */
243#define RLIMIT_CORE 4 /* core file size */
244#define RLIMIT_AS 5 /* address space (resident set size) */
245#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
246#define RLIMIT_RSS RLIMIT_AS /* source compatibility alias */
247#define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */
248#define RLIMIT_NPROC 7 /* number of processes */
249#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
250#define RLIMIT_NOFILE 8 /* number of open files */
251#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
252#define RLIM_NLIMITS 9 /* total number of resource limits */
253#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
254#define _RLIMIT_POSIX_FLAG 0x1000 /* Set bit for strict POSIX */
255
256/*
257 * A structure representing a resource limit. The address of an instance
258 * of this structure is the second parameter to getrlimit()/setrlimit().
259 */
260struct rlimit {
261 rlim_t rlim_cur; /* current (soft) limit */
262 rlim_t rlim_max; /* maximum value for rlim_cur */
263};
264
265#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
266/* I/O type */
267#define IOPOL_TYPE_DISK 0
268
269/* scope */
270#define IOPOL_SCOPE_PROCESS 0
271#define IOPOL_SCOPE_THREAD 1
272
273/* I/O Priority */
274#define IOPOL_DEFAULT 0
275#define IOPOL_NORMAL 1
276#define IOPOL_PASSIVE 2
277#define IOPOL_THROTTLE 3
278
279#ifdef PRIVATE
280/*
281 * Structures for use in communicating via iopolicysys() between Lic and the
282 * kernel. Not to be used by uesr programs directly.
283 */
284
285/*
286 * the command to iopolicysys()
287 */
288#define IOPOL_CMD_GET 0x00000001 /* Get I/O policy */
289#define IOPOL_CMD_SET 0x00000002 /* Set I/O policy */
290
291/*
292 * Second parameter to iopolicysys()
293 */
294struct _iopol_param_t {
295 int iop_scope; /* current process or a thread */
296 int iop_iotype;
297 int iop_policy;
298};
299
300#endif /* PRIVATE */
301#endif /* !_POSIX_C_SOURCE || _DARWIN_C_SOURCE */
302
303#ifndef KERNEL
304
305__BEGIN_DECLS
306int getpriority(int, id_t);
307#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
308int getiopolicy_np(int, int);
309#endif /* !_POSIX_C_SOURCE || _DARWIN_C_SOURCE */
310int getrlimit(int, struct rlimit *) __DARWIN_ALIAS(getrlimit);
311int getrusage(int, struct rusage *);
312int setpriority(int, id_t, int);
313#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
314int setiopolicy_np(int, int, int);
315#endif /* !_POSIX_C_SOURCE || _DARWIN_C_SOURCE */
316int setrlimit(int, const struct rlimit *) __DARWIN_ALIAS(setrlimit);
317__END_DECLS
318
319#endif /* !KERNEL */
320#endif /* !_SYS_RESOURCE_H_ */