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