xref: /titanic_50/usr/src/uts/common/sys/resource.h (revision 554ff184129088135ad2643c1c9832174a17be88)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #ifndef _SYS_RESOURCE_H
41 #define	_SYS_RESOURCE_H
42 
43 #pragma ident	"%Z%%M%	%I%	%E% SMI"
44 
45 #include <sys/feature_tests.h>
46 
47 #include <sys/types.h>
48 #include <sys/time.h>
49 
50 #ifdef	__cplusplus
51 extern "C" {
52 #endif
53 
54 /*
55  * Process priority specifications
56  */
57 #define	PRIO_PROCESS	0
58 #define	PRIO_PGRP	1
59 #define	PRIO_USER	2
60 #define	PRIO_GROUP	3
61 #define	PRIO_SESSION	4
62 #define	PRIO_LWP	5
63 #define	PRIO_TASK	6
64 #define	PRIO_PROJECT	7
65 #define	PRIO_ZONE	8
66 #define	PRIO_CONTRACT	9
67 
68 /*
69  * Resource limits
70  */
71 #define	RLIMIT_CPU	0		/* cpu time in seconds */
72 #define	RLIMIT_FSIZE	1		/* maximum file size */
73 #define	RLIMIT_DATA	2		/* data size */
74 #define	RLIMIT_STACK	3		/* stack size */
75 #define	RLIMIT_CORE	4		/* core file size */
76 #define	RLIMIT_NOFILE	5		/* file descriptors */
77 #define	RLIMIT_VMEM	6		/* maximum mapped memory */
78 #define	RLIMIT_AS	RLIMIT_VMEM
79 
80 #define	RLIM_NLIMITS	7		/* number of resource limits */
81 
82 #if defined(_LP64)
83 
84 typedef	unsigned long	rlim_t;
85 
86 #define	RLIM_INFINITY	(-3l)
87 #define	RLIM_SAVED_MAX	(-2l)
88 #define	RLIM_SAVED_CUR	(-1l)
89 
90 #else	/* _LP64 */
91 
92 /*
93  * The definitions of the following types and constants differ between the
94  * regular and large file compilation environments.
95  */
96 #if _FILE_OFFSET_BITS == 32
97 
98 typedef unsigned long	rlim_t;
99 
100 #define	RLIM_INFINITY	0x7fffffff
101 #define	RLIM_SAVED_MAX	0x7ffffffe
102 #define	RLIM_SAVED_CUR	0x7ffffffd
103 
104 #else	/* _FILE_OFFSET_BITS == 32 */
105 
106 typedef u_longlong_t	rlim_t;
107 
108 #define	RLIM_INFINITY	((rlim_t)-3)
109 #define	RLIM_SAVED_MAX	((rlim_t)-2)
110 #define	RLIM_SAVED_CUR	((rlim_t)-1)
111 
112 #endif	/* _FILE_OFFSET_BITS == 32 */
113 
114 #endif	/* _LP64 */
115 
116 #if defined(_SYSCALL32)
117 
118 /* Kernel's view of user ILP32 rlimits */
119 
120 typedef	uint32_t	rlim32_t;
121 
122 #define	RLIM32_INFINITY		0x7fffffff
123 #define	RLIM32_SAVED_MAX	0x7ffffffe
124 #define	RLIM32_SAVED_CUR	0x7ffffffd
125 
126 struct rlimit32 {
127 	rlim32_t	rlim_cur;	/* current limit */
128 	rlim32_t	rlim_max;	/* maximum value for rlim_cur */
129 };
130 
131 #endif /* _SYSCALL32 */
132 
133 struct rlimit {
134 	rlim_t	rlim_cur;		/* current limit */
135 	rlim_t	rlim_max;		/* maximum value for rlim_cur */
136 };
137 
138 /* transitional large file interface versions */
139 #ifdef	_LARGEFILE64_SOURCE
140 
141 typedef u_longlong_t	rlim64_t;
142 
143 #define	RLIM64_INFINITY		((rlim64_t)-3)
144 #define	RLIM64_SAVED_MAX	((rlim64_t)-2)
145 #define	RLIM64_SAVED_CUR	((rlim64_t)-1)
146 
147 struct rlimit64 {
148 	rlim64_t	rlim_cur;	/* current limit */
149 	rlim64_t	rlim_max;	/* maximum value for rlim_cur */
150 };
151 
152 #endif
153 
154 /*
155  * Although the saved rlimits were initially introduced by the large file API,
156  * they are now available for all resource limits on the 64-bit kernel and for
157  * cpu time and file size limits on the 32-bit kernel.
158  */
159 #if defined(_LP64)
160 
161 #define	RLIM_SAVED(x)	(1)			/* save all resource limits */
162 #define	RLIM_NSAVED	RLIM_NLIMITS		/* size of u_saved_rlimits[] */
163 
164 #else	/* _LP64 */
165 
166 #define	RLIM_SAVED(x)	(x <= RLIMIT_FSIZE)	/* cpu time and file size */
167 #define	RLIM_NSAVED	(RLIMIT_FSIZE + 1)	/* size of u_saved_rlimits[] */
168 
169 #endif	/* _LP64 */
170 
171 
172 struct	rusage {
173 	struct timeval ru_utime;	/* user time used */
174 	struct timeval ru_stime;	/* system time used */
175 	long	ru_maxrss;		/* <unimp> */
176 	long	ru_ixrss;		/* <unimp> */
177 	long	ru_idrss;		/* <unimp> */
178 	long	ru_isrss;		/* <unimp> */
179 	long	ru_minflt;		/* any page faults not requiring I/O */
180 	long	ru_majflt;		/* any page faults requiring I/O */
181 	long	ru_nswap;		/* swaps */
182 	long	ru_inblock;		/* block input operations */
183 	long	ru_oublock;		/* block output operations */
184 	long	ru_msgsnd;		/* streams messsages sent */
185 	long	ru_msgrcv;		/* streams messages received */
186 	long	ru_nsignals;		/* signals received */
187 	long	ru_nvcsw;		/* voluntary context switches */
188 	long	ru_nivcsw;		/* involuntary " */
189 };
190 
191 #define	_RUSAGESYS_GETRUSAGE		0	/* rusage process */
192 #define	_RUSAGESYS_GETRUSAGE_CHLD	1	/* rusage child process */
193 #define	_RUSAGESYS_GETRUSAGE_LWP	2	/* rusage lwp */
194 
195 #if defined(_SYSCALL32)
196 
197 struct	rusage32 {
198 	struct timeval32 ru_utime;	/* user time used */
199 	struct timeval32 ru_stime;	/* system time used */
200 	int	ru_maxrss;		/* <unimp> */
201 	int	ru_ixrss;		/* <unimp> */
202 	int	ru_idrss;		/* <unimp> */
203 	int	ru_isrss;		/* <unimp> */
204 	int	ru_minflt;		/* any page faults not requiring I/O */
205 	int	ru_majflt;		/* any page faults requiring I/O */
206 	int	ru_nswap;		/* swaps */
207 	int	ru_inblock;		/* block input operations */
208 	int	ru_oublock;		/* block output operations */
209 	int	ru_msgsnd;		/* streams messages sent */
210 	int	ru_msgrcv;		/* streams messages received */
211 	int	ru_nsignals;		/* signals received */
212 	int	ru_nvcsw;		/* voluntary context switches */
213 	int	ru_nivcsw;		/* involuntary " */
214 };
215 
216 #endif	/* _SYSCALL32 */
217 
218 
219 #ifdef _KERNEL
220 
221 #include <sys/model.h>
222 
223 struct proc;
224 
225 #else
226 
227 #define	RUSAGE_SELF	0
228 #define	RUSAGE_LWP	1
229 #define	RUSAGE_CHILDREN	-1
230 
231 
232 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
233 /*
234  * large file compilation environment setup
235  */
236 #ifdef __PRAGMA_REDEFINE_EXTNAME
237 #pragma redefine_extname	setrlimit	setrlimit64
238 #pragma redefine_extname	getrlimit	getrlimit64
239 #else
240 #define	setrlimit		setrlimit64
241 #define	getrlimit		getrlimit64
242 #define	rlimit			rlimit64
243 #endif
244 #endif	/* !_LP64 && _FILE_OFFSET_BITS == 64 */
245 
246 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
247 /*
248  * In the LP64 compilation environment, map large file interfaces
249  * back to native versions where possible.
250  */
251 #ifdef __PRAGMA_REDEFINE_EXTNAME
252 #pragma	redefine_extname	setrlimit64	setrlimit
253 #pragma	redefine_extname	getrlimit64	getrlimit
254 #else
255 #define	setrlimit64		setrlimit
256 #define	getrlimit64		getrlimit
257 #define	rlimit64		rlimit
258 #endif
259 #endif	/* _LP64 && _LARGEFILE64_SOURCE */
260 
261 #if defined(__STDC__)
262 
263 extern int setrlimit(int, const struct rlimit *);
264 extern int getrlimit(int, struct rlimit *);
265 
266 /* transitional large file interfaces */
267 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
268 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
269 extern int setrlimit64(int, const struct rlimit64 *);
270 extern int getrlimit64(int, struct rlimit64 *);
271 #endif	/* _LARGEFILE64_SOURCE... */
272 
273 extern int getpriority(int, id_t);
274 extern int setpriority(int, id_t, int);
275 extern int getrusage(int, struct rusage *);
276 
277 #else	/* __STDC__ */
278 
279 extern int getrlimit();
280 extern int setrlimit();
281 
282 /* transitional large file interfaces */
283 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
284 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
285 extern int setrlimit64();
286 extern int getrlimit64();
287 #endif	/* _LARGEFILE64_SOURCE... */
288 
289 extern	int getpriority();
290 extern	int setpriority();
291 extern	int getrusage();
292 
293 #endif  /* __STDC__ */
294 
295 #endif	/* _KERNEL */
296 
297 #ifdef	__cplusplus
298 }
299 #endif
300 
301 #endif	/* _SYS_RESOURCE_H */
302