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