xref: /onnv-gate/usr/src/uts/common/sys/resource.h (revision 3247:e05001c14ea2)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*3247Sgjelinek  * Common Development and Distribution License (the "License").
6*3247Sgjelinek  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*3247Sgjelinek  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
310Sstevel@tonic-gate  * The Regents of the University of California
320Sstevel@tonic-gate  * All Rights Reserved
330Sstevel@tonic-gate  *
340Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
350Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
360Sstevel@tonic-gate  * contributors.
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifndef _SYS_RESOURCE_H
400Sstevel@tonic-gate #define	_SYS_RESOURCE_H
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #include <sys/feature_tests.h>
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #include <sys/types.h>
470Sstevel@tonic-gate #include <sys/time.h>
480Sstevel@tonic-gate 
490Sstevel@tonic-gate #ifdef	__cplusplus
500Sstevel@tonic-gate extern "C" {
510Sstevel@tonic-gate #endif
520Sstevel@tonic-gate 
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate  * Process priority specifications
550Sstevel@tonic-gate  */
560Sstevel@tonic-gate #define	PRIO_PROCESS	0
570Sstevel@tonic-gate #define	PRIO_PGRP	1
580Sstevel@tonic-gate #define	PRIO_USER	2
590Sstevel@tonic-gate #define	PRIO_GROUP	3
600Sstevel@tonic-gate #define	PRIO_SESSION	4
610Sstevel@tonic-gate #define	PRIO_LWP	5
620Sstevel@tonic-gate #define	PRIO_TASK	6
630Sstevel@tonic-gate #define	PRIO_PROJECT	7
640Sstevel@tonic-gate #define	PRIO_ZONE	8
650Sstevel@tonic-gate #define	PRIO_CONTRACT	9
660Sstevel@tonic-gate 
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate  * Resource limits
690Sstevel@tonic-gate  */
700Sstevel@tonic-gate #define	RLIMIT_CPU	0		/* cpu time in seconds */
710Sstevel@tonic-gate #define	RLIMIT_FSIZE	1		/* maximum file size */
720Sstevel@tonic-gate #define	RLIMIT_DATA	2		/* data size */
730Sstevel@tonic-gate #define	RLIMIT_STACK	3		/* stack size */
740Sstevel@tonic-gate #define	RLIMIT_CORE	4		/* core file size */
750Sstevel@tonic-gate #define	RLIMIT_NOFILE	5		/* file descriptors */
760Sstevel@tonic-gate #define	RLIMIT_VMEM	6		/* maximum mapped memory */
770Sstevel@tonic-gate #define	RLIMIT_AS	RLIMIT_VMEM
780Sstevel@tonic-gate 
790Sstevel@tonic-gate #define	RLIM_NLIMITS	7		/* number of resource limits */
800Sstevel@tonic-gate 
810Sstevel@tonic-gate #if defined(_LP64)
820Sstevel@tonic-gate 
830Sstevel@tonic-gate typedef	unsigned long	rlim_t;
840Sstevel@tonic-gate 
850Sstevel@tonic-gate #define	RLIM_INFINITY	(-3l)
860Sstevel@tonic-gate #define	RLIM_SAVED_MAX	(-2l)
870Sstevel@tonic-gate #define	RLIM_SAVED_CUR	(-1l)
880Sstevel@tonic-gate 
890Sstevel@tonic-gate #else	/* _LP64 */
900Sstevel@tonic-gate 
910Sstevel@tonic-gate /*
920Sstevel@tonic-gate  * The definitions of the following types and constants differ between the
930Sstevel@tonic-gate  * regular and large file compilation environments.
940Sstevel@tonic-gate  */
950Sstevel@tonic-gate #if _FILE_OFFSET_BITS == 32
960Sstevel@tonic-gate 
970Sstevel@tonic-gate typedef unsigned long	rlim_t;
980Sstevel@tonic-gate 
990Sstevel@tonic-gate #define	RLIM_INFINITY	0x7fffffff
1000Sstevel@tonic-gate #define	RLIM_SAVED_MAX	0x7ffffffe
1010Sstevel@tonic-gate #define	RLIM_SAVED_CUR	0x7ffffffd
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate #else	/* _FILE_OFFSET_BITS == 32 */
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate typedef u_longlong_t	rlim_t;
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate #define	RLIM_INFINITY	((rlim_t)-3)
1080Sstevel@tonic-gate #define	RLIM_SAVED_MAX	((rlim_t)-2)
1090Sstevel@tonic-gate #define	RLIM_SAVED_CUR	((rlim_t)-1)
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate #endif	/* _FILE_OFFSET_BITS == 32 */
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate #endif	/* _LP64 */
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate #if defined(_SYSCALL32)
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate /* Kernel's view of user ILP32 rlimits */
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate typedef	uint32_t	rlim32_t;
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate #define	RLIM32_INFINITY		0x7fffffff
1220Sstevel@tonic-gate #define	RLIM32_SAVED_MAX	0x7ffffffe
1230Sstevel@tonic-gate #define	RLIM32_SAVED_CUR	0x7ffffffd
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate struct rlimit32 {
1260Sstevel@tonic-gate 	rlim32_t	rlim_cur;	/* current limit */
1270Sstevel@tonic-gate 	rlim32_t	rlim_max;	/* maximum value for rlim_cur */
1280Sstevel@tonic-gate };
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate #endif /* _SYSCALL32 */
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate struct rlimit {
1330Sstevel@tonic-gate 	rlim_t	rlim_cur;		/* current limit */
1340Sstevel@tonic-gate 	rlim_t	rlim_max;		/* maximum value for rlim_cur */
1350Sstevel@tonic-gate };
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate /* transitional large file interface versions */
1380Sstevel@tonic-gate #ifdef	_LARGEFILE64_SOURCE
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate typedef u_longlong_t	rlim64_t;
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate #define	RLIM64_INFINITY		((rlim64_t)-3)
1430Sstevel@tonic-gate #define	RLIM64_SAVED_MAX	((rlim64_t)-2)
1440Sstevel@tonic-gate #define	RLIM64_SAVED_CUR	((rlim64_t)-1)
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate struct rlimit64 {
1470Sstevel@tonic-gate 	rlim64_t	rlim_cur;	/* current limit */
1480Sstevel@tonic-gate 	rlim64_t	rlim_max;	/* maximum value for rlim_cur */
1490Sstevel@tonic-gate };
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate #endif
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate /*
1540Sstevel@tonic-gate  * Although the saved rlimits were initially introduced by the large file API,
1550Sstevel@tonic-gate  * they are now available for all resource limits on the 64-bit kernel and for
1560Sstevel@tonic-gate  * cpu time and file size limits on the 32-bit kernel.
1570Sstevel@tonic-gate  */
1580Sstevel@tonic-gate #if defined(_LP64)
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate #define	RLIM_SAVED(x)	(1)			/* save all resource limits */
1610Sstevel@tonic-gate #define	RLIM_NSAVED	RLIM_NLIMITS		/* size of u_saved_rlimits[] */
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate #else	/* _LP64 */
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate #define	RLIM_SAVED(x)	(x <= RLIMIT_FSIZE)	/* cpu time and file size */
1660Sstevel@tonic-gate #define	RLIM_NSAVED	(RLIMIT_FSIZE + 1)	/* size of u_saved_rlimits[] */
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate #endif	/* _LP64 */
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate struct	rusage {
1720Sstevel@tonic-gate 	struct timeval ru_utime;	/* user time used */
1730Sstevel@tonic-gate 	struct timeval ru_stime;	/* system time used */
1740Sstevel@tonic-gate 	long	ru_maxrss;		/* <unimp> */
1750Sstevel@tonic-gate 	long	ru_ixrss;		/* <unimp> */
1760Sstevel@tonic-gate 	long	ru_idrss;		/* <unimp> */
1770Sstevel@tonic-gate 	long	ru_isrss;		/* <unimp> */
1780Sstevel@tonic-gate 	long	ru_minflt;		/* any page faults not requiring I/O */
1790Sstevel@tonic-gate 	long	ru_majflt;		/* any page faults requiring I/O */
1800Sstevel@tonic-gate 	long	ru_nswap;		/* swaps */
1810Sstevel@tonic-gate 	long	ru_inblock;		/* block input operations */
1820Sstevel@tonic-gate 	long	ru_oublock;		/* block output operations */
1830Sstevel@tonic-gate 	long	ru_msgsnd;		/* streams messsages sent */
1840Sstevel@tonic-gate 	long	ru_msgrcv;		/* streams messages received */
1850Sstevel@tonic-gate 	long	ru_nsignals;		/* signals received */
1860Sstevel@tonic-gate 	long	ru_nvcsw;		/* voluntary context switches */
1870Sstevel@tonic-gate 	long	ru_nivcsw;		/* involuntary " */
1880Sstevel@tonic-gate };
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate #define	_RUSAGESYS_GETRUSAGE		0	/* rusage process */
1910Sstevel@tonic-gate #define	_RUSAGESYS_GETRUSAGE_CHLD	1	/* rusage child process */
1920Sstevel@tonic-gate #define	_RUSAGESYS_GETRUSAGE_LWP	2	/* rusage lwp */
193*3247Sgjelinek #define	_RUSAGESYS_GETVMUSAGE		3	/* getvmusage */
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate #if defined(_SYSCALL32)
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate struct	rusage32 {
1980Sstevel@tonic-gate 	struct timeval32 ru_utime;	/* user time used */
1990Sstevel@tonic-gate 	struct timeval32 ru_stime;	/* system time used */
2000Sstevel@tonic-gate 	int	ru_maxrss;		/* <unimp> */
2010Sstevel@tonic-gate 	int	ru_ixrss;		/* <unimp> */
2020Sstevel@tonic-gate 	int	ru_idrss;		/* <unimp> */
2030Sstevel@tonic-gate 	int	ru_isrss;		/* <unimp> */
2040Sstevel@tonic-gate 	int	ru_minflt;		/* any page faults not requiring I/O */
2050Sstevel@tonic-gate 	int	ru_majflt;		/* any page faults requiring I/O */
2060Sstevel@tonic-gate 	int	ru_nswap;		/* swaps */
2070Sstevel@tonic-gate 	int	ru_inblock;		/* block input operations */
2080Sstevel@tonic-gate 	int	ru_oublock;		/* block output operations */
2090Sstevel@tonic-gate 	int	ru_msgsnd;		/* streams messages sent */
2100Sstevel@tonic-gate 	int	ru_msgrcv;		/* streams messages received */
2110Sstevel@tonic-gate 	int	ru_nsignals;		/* signals received */
2120Sstevel@tonic-gate 	int	ru_nvcsw;		/* voluntary context switches */
2130Sstevel@tonic-gate 	int	ru_nivcsw;		/* involuntary " */
2140Sstevel@tonic-gate };
2150Sstevel@tonic-gate 
2160Sstevel@tonic-gate #endif	/* _SYSCALL32 */
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate #ifdef _KERNEL
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate #include <sys/model.h>
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate struct proc;
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate #else
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate #define	RUSAGE_SELF	0
2280Sstevel@tonic-gate #define	RUSAGE_LWP	1
2290Sstevel@tonic-gate #define	RUSAGE_CHILDREN	-1
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
2330Sstevel@tonic-gate /*
2340Sstevel@tonic-gate  * large file compilation environment setup
2350Sstevel@tonic-gate  */
2360Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
2370Sstevel@tonic-gate #pragma redefine_extname	setrlimit	setrlimit64
2380Sstevel@tonic-gate #pragma redefine_extname	getrlimit	getrlimit64
2390Sstevel@tonic-gate #else
2400Sstevel@tonic-gate #define	setrlimit		setrlimit64
2410Sstevel@tonic-gate #define	getrlimit		getrlimit64
2420Sstevel@tonic-gate #define	rlimit			rlimit64
2430Sstevel@tonic-gate #endif
2440Sstevel@tonic-gate #endif	/* !_LP64 && _FILE_OFFSET_BITS == 64 */
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
2470Sstevel@tonic-gate /*
2480Sstevel@tonic-gate  * In the LP64 compilation environment, map large file interfaces
2490Sstevel@tonic-gate  * back to native versions where possible.
2500Sstevel@tonic-gate  */
2510Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
2520Sstevel@tonic-gate #pragma	redefine_extname	setrlimit64	setrlimit
2530Sstevel@tonic-gate #pragma	redefine_extname	getrlimit64	getrlimit
2540Sstevel@tonic-gate #else
2550Sstevel@tonic-gate #define	setrlimit64		setrlimit
2560Sstevel@tonic-gate #define	getrlimit64		getrlimit
2570Sstevel@tonic-gate #define	rlimit64		rlimit
2580Sstevel@tonic-gate #endif
2590Sstevel@tonic-gate #endif	/* _LP64 && _LARGEFILE64_SOURCE */
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate #if defined(__STDC__)
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate extern int setrlimit(int, const struct rlimit *);
2640Sstevel@tonic-gate extern int getrlimit(int, struct rlimit *);
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate /* transitional large file interfaces */
2670Sstevel@tonic-gate #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
2680Sstevel@tonic-gate 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
2690Sstevel@tonic-gate extern int setrlimit64(int, const struct rlimit64 *);
2700Sstevel@tonic-gate extern int getrlimit64(int, struct rlimit64 *);
2710Sstevel@tonic-gate #endif	/* _LARGEFILE64_SOURCE... */
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate extern int getpriority(int, id_t);
2740Sstevel@tonic-gate extern int setpriority(int, id_t, int);
2750Sstevel@tonic-gate extern int getrusage(int, struct rusage *);
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate #else	/* __STDC__ */
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate extern int getrlimit();
2800Sstevel@tonic-gate extern int setrlimit();
2810Sstevel@tonic-gate 
2820Sstevel@tonic-gate /* transitional large file interfaces */
2830Sstevel@tonic-gate #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
2840Sstevel@tonic-gate 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
2850Sstevel@tonic-gate extern int setrlimit64();
2860Sstevel@tonic-gate extern int getrlimit64();
2870Sstevel@tonic-gate #endif	/* _LARGEFILE64_SOURCE... */
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate extern	int getpriority();
2900Sstevel@tonic-gate extern	int setpriority();
2910Sstevel@tonic-gate extern	int getrusage();
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate #endif  /* __STDC__ */
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate #endif	/* _KERNEL */
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate #ifdef	__cplusplus
2980Sstevel@tonic-gate }
2990Sstevel@tonic-gate #endif
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate #endif	/* _SYS_RESOURCE_H */
302