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