]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. |
1c79356b A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
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. | |
1c79356b | 11 | * |
37839358 A |
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 | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
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. | |
1c79356b A |
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 | ||
9bccf70c | 61 | #include <sys/appleapiopts.h> |
91447636 A |
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 | ||
9bccf70c | 86 | |
1c79356b | 87 | /* |
91447636 A |
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(). | |
1c79356b A |
108 | */ |
109 | #define PRIO_MIN -20 | |
110 | #define PRIO_MAX 20 | |
91447636 | 111 | #endif /* !_POSIX_C_SOURCE */ |
1c79356b | 112 | |
1c79356b | 113 | |
91447636 A |
114 | |
115 | /***** | |
116 | * RESOURCE USAGE | |
1c79356b A |
117 | */ |
118 | ||
91447636 A |
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 */ | |
1c79356b | 125 | |
91447636 A |
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 | */ | |
1c79356b A |
135 | struct rusage { |
136 | struct timeval ru_utime; /* user time used */ | |
137 | struct timeval ru_stime; /* system time used */ | |
91447636 A |
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 | */ | |
1c79356b | 146 | long ru_maxrss; /* max resident set size */ |
91447636 | 147 | #define ru_first ru_ixrss /* internal: ruadd() range start */ |
1c79356b A |
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 " */ | |
91447636 A |
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 | #if __DARWIN_ALIGN_NATURAL | |
177 | #pragma options align=natural | |
178 | #endif | |
179 | ||
180 | struct user_rusage_timeval { | |
181 | user_time_t tv_sec; /* seconds */ | |
182 | __darwin_suseconds_t tv_usec; /* and microseconds */ | |
183 | }; | |
184 | struct user_rusage { | |
185 | struct user_rusage_timeval ru_utime; /* user time used */ | |
186 | struct user_rusage_timeval ru_stime; /* system time used */ | |
187 | user_long_t ru_maxrss; /* max resident set size */ | |
188 | user_long_t ru_ixrss; /* integral shared memory size */ | |
189 | user_long_t ru_idrss; /* integral unshared data " */ | |
190 | user_long_t ru_isrss; /* integral unshared stack " */ | |
191 | user_long_t ru_minflt; /* page reclaims */ | |
192 | user_long_t ru_majflt; /* page faults */ | |
193 | user_long_t ru_nswap; /* swaps */ | |
194 | user_long_t ru_inblock; /* block input operations */ | |
195 | user_long_t ru_oublock; /* block output operations */ | |
196 | user_long_t ru_msgsnd; /* messages sent */ | |
197 | user_long_t ru_msgrcv; /* messages received */ | |
198 | user_long_t ru_nsignals; /* signals received */ | |
199 | user_long_t ru_nvcsw; /* voluntary context switches */ | |
200 | user_long_t ru_nivcsw; /* involuntary " */ | |
1c79356b A |
201 | }; |
202 | ||
91447636 A |
203 | #if __DARWIN_ALIGN_NATURAL |
204 | #pragma options align=reset | |
205 | #endif | |
206 | ||
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_ */ |