]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/resource.h
xnu-792.21.3.tar.gz
[apple/xnu.git] / bsd / sys / resource.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, 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 * NB: We use __darwin_time_t and __darwin_suseconds_t here to avoid
76 * improperly exposing time_t and suseconds_t into the namespace.
77 */
78 #ifndef _TIMEVAL
79 #define _TIMEVAL
80 struct timeval {
81 __darwin_time_t tv_sec; /* seconds */
82 __darwin_suseconds_t tv_usec; /* and microseconds */
83 };
84 #endif
85
86 /* The id_t type shall be defined as described in <sys/types.h> */
87 #ifndef _ID_T
88 #define _ID_T
89 typedef __darwin_id_t id_t; /* can hold pid_t, gid_t, or uid_t */
90 #endif
91
92
93 /*
94 * Resource limit type (low 63 bits, excluding the sign bit)
95 */
96 typedef __int64_t rlim_t;
97
98
99 /*****
100 * PRIORITY
101 */
102
103 /*
104 * Possible values of the first parameter to getpriority()/setpriority(),
105 * used to indicate the type of the second parameter.
106 */
107 #define PRIO_PROCESS 0 /* Second argument is a PID */
108 #define PRIO_PGRP 1 /* Second argument is a GID */
109 #define PRIO_USER 2 /* Second argument is a UID */
110
111 #ifndef _POSIX_C_SOURCE
112 /*
113 * Range limitations for the value of the third parameter to setpriority().
114 */
115 #define PRIO_MIN -20
116 #define PRIO_MAX 20
117 #endif /* !_POSIX_C_SOURCE */
118
119
120
121 /*****
122 * RESOURCE USAGE
123 */
124
125 /*
126 * Possible values of the first parameter to getrusage(), used to indicate
127 * the scope of the information to be returned.
128 */
129 #define RUSAGE_SELF 0 /* Current process information */
130 #define RUSAGE_CHILDREN -1 /* Current process' children */
131
132 /*
133 * A structure representing an accounting of resource utilization. The
134 * address of an instance of this structure is the second parameter to
135 * getrusage().
136 *
137 * Note: All values other than ru_utime and ru_stime are implementaiton
138 * defined and subject to change in a future release. Their use
139 * is discouraged for standards compliant programs.
140 */
141 struct rusage {
142 struct timeval ru_utime; /* user time used */
143 struct timeval ru_stime; /* system time used */
144 #ifdef _POSIX_C_SOURCE
145 long ru_opaque[14]; /* implementation defined */
146 #else /* !_POSIX_C_SOURCE */
147 /*
148 * Informational aliases for source compatibility with programs
149 * that need more information than that provided by standards,
150 * and which do not mind being OS-dependent.
151 */
152 long ru_maxrss; /* max resident set size */
153 #define ru_first ru_ixrss /* internal: ruadd() range start */
154 long ru_ixrss; /* integral shared memory size */
155 long ru_idrss; /* integral unshared data " */
156 long ru_isrss; /* integral unshared stack " */
157 long ru_minflt; /* page reclaims */
158 long ru_majflt; /* page faults */
159 long ru_nswap; /* swaps */
160 long ru_inblock; /* block input operations */
161 long ru_oublock; /* block output operations */
162 long ru_msgsnd; /* messages sent */
163 long ru_msgrcv; /* messages received */
164 long ru_nsignals; /* signals received */
165 long ru_nvcsw; /* voluntary context switches */
166 long ru_nivcsw; /* involuntary " */
167 #define ru_last ru_nivcsw /* internal: ruadd() range end */
168 #endif /* !_POSIX_C_SOURCE */
169 };
170
171
172
173 // LP64todo - should this move?
174 #ifdef KERNEL
175 #include <machine/types.h> /* user_time_t */
176
177 /* LP64 version of struct timeval. time_t is a long and must grow when
178 * we're dealing with a 64-bit process.
179 * WARNING - keep in sync with struct timeval
180 */
181
182 #if __DARWIN_ALIGN_NATURAL
183 #pragma options align=natural
184 #endif
185
186 struct user_rusage_timeval {
187 user_time_t tv_sec; /* seconds */
188 __darwin_suseconds_t tv_usec; /* and microseconds */
189 };
190 struct user_rusage {
191 struct user_rusage_timeval ru_utime; /* user time used */
192 struct user_rusage_timeval ru_stime; /* system time used */
193 user_long_t ru_maxrss; /* max resident set size */
194 user_long_t ru_ixrss; /* integral shared memory size */
195 user_long_t ru_idrss; /* integral unshared data " */
196 user_long_t ru_isrss; /* integral unshared stack " */
197 user_long_t ru_minflt; /* page reclaims */
198 user_long_t ru_majflt; /* page faults */
199 user_long_t ru_nswap; /* swaps */
200 user_long_t ru_inblock; /* block input operations */
201 user_long_t ru_oublock; /* block output operations */
202 user_long_t ru_msgsnd; /* messages sent */
203 user_long_t ru_msgrcv; /* messages received */
204 user_long_t ru_nsignals; /* signals received */
205 user_long_t ru_nvcsw; /* voluntary context switches */
206 user_long_t ru_nivcsw; /* involuntary " */
207 };
208
209 #if __DARWIN_ALIGN_NATURAL
210 #pragma options align=reset
211 #endif
212
213 #endif // KERNEL
214
215
216 /*****
217 * RESOURCE LIMITS
218 */
219
220 /*
221 * Symbolic constants for resource limits; since all limits are representable
222 * as a type rlim_t, we are permitted to define RLIM_SAVED_* in terms of
223 * RLIM_INFINITY.
224 */
225 #define RLIM_INFINITY (((__uint64_t)1 << 63) - 1) /* no limit */
226 #define RLIM_SAVED_MAX RLIM_INFINITY /* Unrepresentable hard limit */
227 #define RLIM_SAVED_CUR RLIM_INFINITY /* Unrepresentable soft limit */
228
229 /*
230 * Possible values of the first parameter to getrlimit()/setrlimit(), to
231 * indicate for which resource the operation is being performed.
232 */
233 #define RLIMIT_CPU 0 /* cpu time per process, in ms */
234 #define RLIMIT_FSIZE 1 /* file size */
235 #define RLIMIT_DATA 2 /* data segment size */
236 #define RLIMIT_STACK 3 /* stack size */
237 #define RLIMIT_CORE 4 /* core file size */
238 #define RLIMIT_AS 5 /* address space (resident set size) */
239 #ifndef _POSIX_C_SOURCE
240 #define RLIMIT_RSS RLIMIT_AS /* source compatibility alias */
241 #define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */
242 #define RLIMIT_NPROC 7 /* number of processes */
243 #endif /* !_POSIX_C_SOURCE */
244 #define RLIMIT_NOFILE 8 /* number of open files */
245 #ifndef _POSIX_C_SOURCE
246 #define RLIM_NLIMITS 9 /* total number of resource limits */
247 #endif /* !_POSIX_C_SOURCE */
248
249 /*
250 * A structure representing a resource limit. The address of an instance
251 * of this structure is the second parameter to getrlimit()/setrlimit().
252 */
253 struct rlimit {
254 rlim_t rlim_cur; /* current (soft) limit */
255 rlim_t rlim_max; /* maximum value for rlim_cur */
256 };
257
258
259 #ifndef KERNEL
260
261 __BEGIN_DECLS
262 int getpriority(int, id_t);
263 int getrlimit(int, struct rlimit *);
264 int getrusage(int, struct rusage *);
265 int setpriority(int, id_t, int);
266 int setrlimit(int, const struct rlimit *);
267 __END_DECLS
268
269 #endif /* !KERNEL */
270 #endif /* !_SYS_RESOURCE_H_ */