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