xref: /illumos-gate/usr/src/uts/common/sys/resource.h (revision 0209230bf1261579beab4f55226bb509e6b850cb)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0209230bSgjelinek  * Common Development and Distribution License (the "License").
6*0209230bSgjelinek  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*0209230bSgjelinek  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
317c478bd9Sstevel@tonic-gate  * The Regents of the University of California
327c478bd9Sstevel@tonic-gate  * All Rights Reserved
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
357c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
367c478bd9Sstevel@tonic-gate  * contributors.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifndef _SYS_RESOURCE_H
407c478bd9Sstevel@tonic-gate #define	_SYS_RESOURCE_H
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #include <sys/types.h>
477c478bd9Sstevel@tonic-gate #include <sys/time.h>
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
507c478bd9Sstevel@tonic-gate extern "C" {
517c478bd9Sstevel@tonic-gate #endif
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * Process priority specifications
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate #define	PRIO_PROCESS	0
577c478bd9Sstevel@tonic-gate #define	PRIO_PGRP	1
587c478bd9Sstevel@tonic-gate #define	PRIO_USER	2
597c478bd9Sstevel@tonic-gate #define	PRIO_GROUP	3
607c478bd9Sstevel@tonic-gate #define	PRIO_SESSION	4
617c478bd9Sstevel@tonic-gate #define	PRIO_LWP	5
627c478bd9Sstevel@tonic-gate #define	PRIO_TASK	6
637c478bd9Sstevel@tonic-gate #define	PRIO_PROJECT	7
647c478bd9Sstevel@tonic-gate #define	PRIO_ZONE	8
657c478bd9Sstevel@tonic-gate #define	PRIO_CONTRACT	9
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate  * Resource limits
697c478bd9Sstevel@tonic-gate  */
707c478bd9Sstevel@tonic-gate #define	RLIMIT_CPU	0		/* cpu time in seconds */
717c478bd9Sstevel@tonic-gate #define	RLIMIT_FSIZE	1		/* maximum file size */
727c478bd9Sstevel@tonic-gate #define	RLIMIT_DATA	2		/* data size */
737c478bd9Sstevel@tonic-gate #define	RLIMIT_STACK	3		/* stack size */
747c478bd9Sstevel@tonic-gate #define	RLIMIT_CORE	4		/* core file size */
757c478bd9Sstevel@tonic-gate #define	RLIMIT_NOFILE	5		/* file descriptors */
767c478bd9Sstevel@tonic-gate #define	RLIMIT_VMEM	6		/* maximum mapped memory */
777c478bd9Sstevel@tonic-gate #define	RLIMIT_AS	RLIMIT_VMEM
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	RLIM_NLIMITS	7		/* number of resource limits */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #if defined(_LP64)
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate typedef	unsigned long	rlim_t;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate #define	RLIM_INFINITY	(-3l)
867c478bd9Sstevel@tonic-gate #define	RLIM_SAVED_MAX	(-2l)
877c478bd9Sstevel@tonic-gate #define	RLIM_SAVED_CUR	(-1l)
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #else	/* _LP64 */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * The definitions of the following types and constants differ between the
937c478bd9Sstevel@tonic-gate  * regular and large file compilation environments.
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate #if _FILE_OFFSET_BITS == 32
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate typedef unsigned long	rlim_t;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #define	RLIM_INFINITY	0x7fffffff
1007c478bd9Sstevel@tonic-gate #define	RLIM_SAVED_MAX	0x7ffffffe
1017c478bd9Sstevel@tonic-gate #define	RLIM_SAVED_CUR	0x7ffffffd
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #else	/* _FILE_OFFSET_BITS == 32 */
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate typedef u_longlong_t	rlim_t;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #define	RLIM_INFINITY	((rlim_t)-3)
1087c478bd9Sstevel@tonic-gate #define	RLIM_SAVED_MAX	((rlim_t)-2)
1097c478bd9Sstevel@tonic-gate #define	RLIM_SAVED_CUR	((rlim_t)-1)
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #endif	/* _FILE_OFFSET_BITS == 32 */
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #endif	/* _LP64 */
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /* Kernel's view of user ILP32 rlimits */
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate typedef	uint32_t	rlim32_t;
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #define	RLIM32_INFINITY		0x7fffffff
1227c478bd9Sstevel@tonic-gate #define	RLIM32_SAVED_MAX	0x7ffffffe
1237c478bd9Sstevel@tonic-gate #define	RLIM32_SAVED_CUR	0x7ffffffd
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate struct rlimit32 {
1267c478bd9Sstevel@tonic-gate 	rlim32_t	rlim_cur;	/* current limit */
1277c478bd9Sstevel@tonic-gate 	rlim32_t	rlim_max;	/* maximum value for rlim_cur */
1287c478bd9Sstevel@tonic-gate };
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate struct rlimit {
1337c478bd9Sstevel@tonic-gate 	rlim_t	rlim_cur;		/* current limit */
1347c478bd9Sstevel@tonic-gate 	rlim_t	rlim_max;		/* maximum value for rlim_cur */
1357c478bd9Sstevel@tonic-gate };
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /* transitional large file interface versions */
1387c478bd9Sstevel@tonic-gate #ifdef	_LARGEFILE64_SOURCE
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate typedef u_longlong_t	rlim64_t;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #define	RLIM64_INFINITY		((rlim64_t)-3)
1437c478bd9Sstevel@tonic-gate #define	RLIM64_SAVED_MAX	((rlim64_t)-2)
1447c478bd9Sstevel@tonic-gate #define	RLIM64_SAVED_CUR	((rlim64_t)-1)
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate struct rlimit64 {
1477c478bd9Sstevel@tonic-gate 	rlim64_t	rlim_cur;	/* current limit */
1487c478bd9Sstevel@tonic-gate 	rlim64_t	rlim_max;	/* maximum value for rlim_cur */
1497c478bd9Sstevel@tonic-gate };
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #endif
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate  * Although the saved rlimits were initially introduced by the large file API,
1557c478bd9Sstevel@tonic-gate  * they are now available for all resource limits on the 64-bit kernel and for
1567c478bd9Sstevel@tonic-gate  * cpu time and file size limits on the 32-bit kernel.
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate #if defined(_LP64)
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #define	RLIM_SAVED(x)	(1)			/* save all resource limits */
1617c478bd9Sstevel@tonic-gate #define	RLIM_NSAVED	RLIM_NLIMITS		/* size of u_saved_rlimits[] */
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #else	/* _LP64 */
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #define	RLIM_SAVED(x)	(x <= RLIMIT_FSIZE)	/* cpu time and file size */
1667c478bd9Sstevel@tonic-gate #define	RLIM_NSAVED	(RLIMIT_FSIZE + 1)	/* size of u_saved_rlimits[] */
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate #endif	/* _LP64 */
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate struct	rusage {
1727c478bd9Sstevel@tonic-gate 	struct timeval ru_utime;	/* user time used */
1737c478bd9Sstevel@tonic-gate 	struct timeval ru_stime;	/* system time used */
1747c478bd9Sstevel@tonic-gate 	long	ru_maxrss;		/* <unimp> */
1757c478bd9Sstevel@tonic-gate 	long	ru_ixrss;		/* <unimp> */
1767c478bd9Sstevel@tonic-gate 	long	ru_idrss;		/* <unimp> */
1777c478bd9Sstevel@tonic-gate 	long	ru_isrss;		/* <unimp> */
1787c478bd9Sstevel@tonic-gate 	long	ru_minflt;		/* any page faults not requiring I/O */
1797c478bd9Sstevel@tonic-gate 	long	ru_majflt;		/* any page faults requiring I/O */
1807c478bd9Sstevel@tonic-gate 	long	ru_nswap;		/* swaps */
1817c478bd9Sstevel@tonic-gate 	long	ru_inblock;		/* block input operations */
1827c478bd9Sstevel@tonic-gate 	long	ru_oublock;		/* block output operations */
1837c478bd9Sstevel@tonic-gate 	long	ru_msgsnd;		/* streams messsages sent */
1847c478bd9Sstevel@tonic-gate 	long	ru_msgrcv;		/* streams messages received */
1857c478bd9Sstevel@tonic-gate 	long	ru_nsignals;		/* signals received */
1867c478bd9Sstevel@tonic-gate 	long	ru_nvcsw;		/* voluntary context switches */
1877c478bd9Sstevel@tonic-gate 	long	ru_nivcsw;		/* involuntary " */
1887c478bd9Sstevel@tonic-gate };
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate #define	_RUSAGESYS_GETRUSAGE		0	/* rusage process */
1917c478bd9Sstevel@tonic-gate #define	_RUSAGESYS_GETRUSAGE_CHLD	1	/* rusage child process */
1927c478bd9Sstevel@tonic-gate #define	_RUSAGESYS_GETRUSAGE_LWP	2	/* rusage lwp */
193*0209230bSgjelinek #define	_RUSAGESYS_GETVMUSAGE		3	/* getvmusage */
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate struct	rusage32 {
1987c478bd9Sstevel@tonic-gate 	struct timeval32 ru_utime;	/* user time used */
1997c478bd9Sstevel@tonic-gate 	struct timeval32 ru_stime;	/* system time used */
2007c478bd9Sstevel@tonic-gate 	int	ru_maxrss;		/* <unimp> */
2017c478bd9Sstevel@tonic-gate 	int	ru_ixrss;		/* <unimp> */
2027c478bd9Sstevel@tonic-gate 	int	ru_idrss;		/* <unimp> */
2037c478bd9Sstevel@tonic-gate 	int	ru_isrss;		/* <unimp> */
2047c478bd9Sstevel@tonic-gate 	int	ru_minflt;		/* any page faults not requiring I/O */
2057c478bd9Sstevel@tonic-gate 	int	ru_majflt;		/* any page faults requiring I/O */
2067c478bd9Sstevel@tonic-gate 	int	ru_nswap;		/* swaps */
2077c478bd9Sstevel@tonic-gate 	int	ru_inblock;		/* block input operations */
2087c478bd9Sstevel@tonic-gate 	int	ru_oublock;		/* block output operations */
2097c478bd9Sstevel@tonic-gate 	int	ru_msgsnd;		/* streams messages sent */
2107c478bd9Sstevel@tonic-gate 	int	ru_msgrcv;		/* streams messages received */
2117c478bd9Sstevel@tonic-gate 	int	ru_nsignals;		/* signals received */
2127c478bd9Sstevel@tonic-gate 	int	ru_nvcsw;		/* voluntary context switches */
2137c478bd9Sstevel@tonic-gate 	int	ru_nivcsw;		/* involuntary " */
2147c478bd9Sstevel@tonic-gate };
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate #ifdef _KERNEL
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate #include <sys/model.h>
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate struct proc;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #else
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate #define	RUSAGE_SELF	0
2287c478bd9Sstevel@tonic-gate #define	RUSAGE_LWP	1
2297c478bd9Sstevel@tonic-gate #define	RUSAGE_CHILDREN	-1
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
2337c478bd9Sstevel@tonic-gate /*
2347c478bd9Sstevel@tonic-gate  * large file compilation environment setup
2357c478bd9Sstevel@tonic-gate  */
2367c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
2377c478bd9Sstevel@tonic-gate #pragma redefine_extname	setrlimit	setrlimit64
2387c478bd9Sstevel@tonic-gate #pragma redefine_extname	getrlimit	getrlimit64
2397c478bd9Sstevel@tonic-gate #else
2407c478bd9Sstevel@tonic-gate #define	setrlimit		setrlimit64
2417c478bd9Sstevel@tonic-gate #define	getrlimit		getrlimit64
2427c478bd9Sstevel@tonic-gate #define	rlimit			rlimit64
2437c478bd9Sstevel@tonic-gate #endif
2447c478bd9Sstevel@tonic-gate #endif	/* !_LP64 && _FILE_OFFSET_BITS == 64 */
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
2477c478bd9Sstevel@tonic-gate /*
2487c478bd9Sstevel@tonic-gate  * In the LP64 compilation environment, map large file interfaces
2497c478bd9Sstevel@tonic-gate  * back to native versions where possible.
2507c478bd9Sstevel@tonic-gate  */
2517c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
2527c478bd9Sstevel@tonic-gate #pragma	redefine_extname	setrlimit64	setrlimit
2537c478bd9Sstevel@tonic-gate #pragma	redefine_extname	getrlimit64	getrlimit
2547c478bd9Sstevel@tonic-gate #else
2557c478bd9Sstevel@tonic-gate #define	setrlimit64		setrlimit
2567c478bd9Sstevel@tonic-gate #define	getrlimit64		getrlimit
2577c478bd9Sstevel@tonic-gate #define	rlimit64		rlimit
2587c478bd9Sstevel@tonic-gate #endif
2597c478bd9Sstevel@tonic-gate #endif	/* _LP64 && _LARGEFILE64_SOURCE */
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate #if defined(__STDC__)
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate extern int setrlimit(int, const struct rlimit *);
2647c478bd9Sstevel@tonic-gate extern int getrlimit(int, struct rlimit *);
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /* transitional large file interfaces */
2677c478bd9Sstevel@tonic-gate #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
2687c478bd9Sstevel@tonic-gate 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
2697c478bd9Sstevel@tonic-gate extern int setrlimit64(int, const struct rlimit64 *);
2707c478bd9Sstevel@tonic-gate extern int getrlimit64(int, struct rlimit64 *);
2717c478bd9Sstevel@tonic-gate #endif	/* _LARGEFILE64_SOURCE... */
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate extern int getpriority(int, id_t);
2747c478bd9Sstevel@tonic-gate extern int setpriority(int, id_t, int);
2757c478bd9Sstevel@tonic-gate extern int getrusage(int, struct rusage *);
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate #else	/* __STDC__ */
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate extern int getrlimit();
2807c478bd9Sstevel@tonic-gate extern int setrlimit();
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate /* transitional large file interfaces */
2837c478bd9Sstevel@tonic-gate #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
2847c478bd9Sstevel@tonic-gate 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
2857c478bd9Sstevel@tonic-gate extern int setrlimit64();
2867c478bd9Sstevel@tonic-gate extern int getrlimit64();
2877c478bd9Sstevel@tonic-gate #endif	/* _LARGEFILE64_SOURCE... */
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate extern	int getpriority();
2907c478bd9Sstevel@tonic-gate extern	int setpriority();
2917c478bd9Sstevel@tonic-gate extern	int getrusage();
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate #endif  /* __STDC__ */
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate #endif
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate #endif	/* _SYS_RESOURCE_H */
302