]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/resource.h
xnu-792.6.56.tar.gz
[apple/xnu.git] / bsd / sys / resource.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 /*
25 * Copyright (c) 1982, 1986, 1993
26 * The Regents of the University of California. All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * SUCH DAMAGE.
55 *
56 * @(#)resource.h 8.2 (Berkeley) 1/4/94
57 */
58
59 #ifndef _SYS_RESOURCE_H_
60 #define _SYS_RESOURCE_H_
61
62 #include <sys/appleapiopts.h>
63 #include <sys/cdefs.h>
64 #include <sys/_types.h>
65
66
67 /* [XSI] The timeval structure shall be defined as described in
68 * <sys/time.h>
69 *
70 * NB: We use __darwin_time_t and __darwin_suseconds_t here to avoid
71 * improperly exposing time_t and suseconds_t into the namespace.
72 */
73 #ifndef _TIMEVAL
74 #define _TIMEVAL
75 struct timeval {
76 __darwin_time_t tv_sec; /* seconds */
77 __darwin_suseconds_t tv_usec; /* and microseconds */
78 };
79 #endif
80
81 /* The id_t type shall be defined as described in <sys/types.h> */
82 #ifndef _ID_T
83 #define _ID_T
84 typedef __darwin_id_t id_t; /* can hold pid_t, gid_t, or uid_t */
85 #endif
86
87
88 /*
89 * Resource limit type (low 63 bits, excluding the sign bit)
90 */
91 typedef __int64_t rlim_t;
92
93
94 /*****
95 * PRIORITY
96 */
97
98 /*
99 * Possible values of the first parameter to getpriority()/setpriority(),
100 * used to indicate the type of the second parameter.
101 */
102 #define PRIO_PROCESS 0 /* Second argument is a PID */
103 #define PRIO_PGRP 1 /* Second argument is a GID */
104 #define PRIO_USER 2 /* Second argument is a UID */
105
106 #ifndef _POSIX_C_SOURCE
107 /*
108 * Range limitations for the value of the third parameter to setpriority().
109 */
110 #define PRIO_MIN -20
111 #define PRIO_MAX 20
112 #endif /* !_POSIX_C_SOURCE */
113
114
115
116 /*****
117 * RESOURCE USAGE
118 */
119
120 /*
121 * Possible values of the first parameter to getrusage(), used to indicate
122 * the scope of the information to be returned.
123 */
124 #define RUSAGE_SELF 0 /* Current process information */
125 #define RUSAGE_CHILDREN -1 /* Current process' children */
126
127 /*
128 * A structure representing an accounting of resource utilization. The
129 * address of an instance of this structure is the second parameter to
130 * getrusage().
131 *
132 * Note: All values other than ru_utime and ru_stime are implementaiton
133 * defined and subject to change in a future release. Their use
134 * is discouraged for standards compliant programs.
135 */
136 struct rusage {
137 struct timeval ru_utime; /* user time used */
138 struct timeval ru_stime; /* system time used */
139 #ifdef _POSIX_C_SOURCE
140 long ru_opaque[14]; /* implementation defined */
141 #else /* !_POSIX_C_SOURCE */
142 /*
143 * Informational aliases for source compatibility with programs
144 * that need more information than that provided by standards,
145 * and which do not mind being OS-dependent.
146 */
147 long ru_maxrss; /* max resident set size */
148 #define ru_first ru_ixrss /* internal: ruadd() range start */
149 long ru_ixrss; /* integral shared memory size */
150 long ru_idrss; /* integral unshared data " */
151 long ru_isrss; /* integral unshared stack " */
152 long ru_minflt; /* page reclaims */
153 long ru_majflt; /* page faults */
154 long ru_nswap; /* swaps */
155 long ru_inblock; /* block input operations */
156 long ru_oublock; /* block output operations */
157 long ru_msgsnd; /* messages sent */
158 long ru_msgrcv; /* messages received */
159 long ru_nsignals; /* signals received */
160 long ru_nvcsw; /* voluntary context switches */
161 long ru_nivcsw; /* involuntary " */
162 #define ru_last ru_nivcsw /* internal: ruadd() range end */
163 #endif /* !_POSIX_C_SOURCE */
164 };
165
166
167
168 // LP64todo - should this move?
169 #ifdef KERNEL
170 #include <machine/types.h> /* user_time_t */
171
172 /* LP64 version of struct timeval. time_t is a long and must grow when
173 * we're dealing with a 64-bit process.
174 * WARNING - keep in sync with struct timeval
175 */
176
177 #if __DARWIN_ALIGN_NATURAL
178 #pragma options align=natural
179 #endif
180
181 struct user_rusage_timeval {
182 user_time_t tv_sec; /* seconds */
183 __darwin_suseconds_t tv_usec; /* and microseconds */
184 };
185 struct user_rusage {
186 struct user_rusage_timeval ru_utime; /* user time used */
187 struct user_rusage_timeval ru_stime; /* system time used */
188 user_long_t ru_maxrss; /* max resident set size */
189 user_long_t ru_ixrss; /* integral shared memory size */
190 user_long_t ru_idrss; /* integral unshared data " */
191 user_long_t ru_isrss; /* integral unshared stack " */
192 user_long_t ru_minflt; /* page reclaims */
193 user_long_t ru_majflt; /* page faults */
194 user_long_t ru_nswap; /* swaps */
195 user_long_t ru_inblock; /* block input operations */
196 user_long_t ru_oublock; /* block output operations */
197 user_long_t ru_msgsnd; /* messages sent */
198 user_long_t ru_msgrcv; /* messages received */
199 user_long_t ru_nsignals; /* signals received */
200 user_long_t ru_nvcsw; /* voluntary context switches */
201 user_long_t ru_nivcsw; /* involuntary " */
202 };
203
204 #if __DARWIN_ALIGN_NATURAL
205 #pragma options align=reset
206 #endif
207
208 #endif // KERNEL
209
210
211 /*****
212 * RESOURCE LIMITS
213 */
214
215 /*
216 * Symbolic constants for resource limits; since all limits are representable
217 * as a type rlim_t, we are permitted to define RLIM_SAVED_* in terms of
218 * RLIM_INFINITY.
219 */
220 #define RLIM_INFINITY (((__uint64_t)1 << 63) - 1) /* no limit */
221 #define RLIM_SAVED_MAX RLIM_INFINITY /* Unrepresentable hard limit */
222 #define RLIM_SAVED_CUR RLIM_INFINITY /* Unrepresentable soft limit */
223
224 /*
225 * Possible values of the first parameter to getrlimit()/setrlimit(), to
226 * indicate for which resource the operation is being performed.
227 */
228 #define RLIMIT_CPU 0 /* cpu time per process, in ms */
229 #define RLIMIT_FSIZE 1 /* file size */
230 #define RLIMIT_DATA 2 /* data segment size */
231 #define RLIMIT_STACK 3 /* stack size */
232 #define RLIMIT_CORE 4 /* core file size */
233 #define RLIMIT_AS 5 /* address space (resident set size) */
234 #ifndef _POSIX_C_SOURCE
235 #define RLIMIT_RSS RLIMIT_AS /* source compatibility alias */
236 #define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */
237 #define RLIMIT_NPROC 7 /* number of processes */
238 #endif /* !_POSIX_C_SOURCE */
239 #define RLIMIT_NOFILE 8 /* number of open files */
240 #ifndef _POSIX_C_SOURCE
241 #define RLIM_NLIMITS 9 /* total number of resource limits */
242 #endif /* !_POSIX_C_SOURCE */
243
244 /*
245 * A structure representing a resource limit. The address of an instance
246 * of this structure is the second parameter to getrlimit()/setrlimit().
247 */
248 struct rlimit {
249 rlim_t rlim_cur; /* current (soft) limit */
250 rlim_t rlim_max; /* maximum value for rlim_cur */
251 };
252
253
254 #ifndef KERNEL
255
256 __BEGIN_DECLS
257 int getpriority(int, id_t);
258 int getrlimit(int, struct rlimit *);
259 int getrusage(int, struct rusage *);
260 int setpriority(int, id_t, int);
261 int setrlimit(int, const struct rlimit *);
262 __END_DECLS
263
264 #endif /* !KERNEL */
265 #endif /* !_SYS_RESOURCE_H_ */