xref: /onnv-gate/usr/src/uts/common/syscall/sysconfig.c (revision 7884:66b5b9486f94)
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
51885Sraf  * Common Development and Distribution License (the "License").
61885Sraf  * 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  */
211885Sraf 
220Sstevel@tonic-gate /*
23*7884Sgerald.jelinek@sun.com  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <sys/param.h>
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <sys/sysmacros.h>
330Sstevel@tonic-gate #include <sys/systm.h>
340Sstevel@tonic-gate #include <sys/tuneable.h>
350Sstevel@tonic-gate #include <sys/errno.h>
360Sstevel@tonic-gate #include <sys/var.h>
370Sstevel@tonic-gate #include <sys/signal.h>
380Sstevel@tonic-gate #include <sys/time.h>
390Sstevel@tonic-gate #include <sys/sysconfig.h>
400Sstevel@tonic-gate #include <sys/resource.h>
410Sstevel@tonic-gate #include <sys/ulimit.h>
420Sstevel@tonic-gate #include <sys/unistd.h>
430Sstevel@tonic-gate #include <sys/debug.h>
440Sstevel@tonic-gate #include <sys/cpuvar.h>
450Sstevel@tonic-gate #include <sys/mman.h>
460Sstevel@tonic-gate #include <sys/timer.h>
470Sstevel@tonic-gate #include <sys/zone.h>
48*7884Sgerald.jelinek@sun.com #include <sys/vm_usage.h>
490Sstevel@tonic-gate 
500Sstevel@tonic-gate long
sysconfig(int which)510Sstevel@tonic-gate sysconfig(int which)
520Sstevel@tonic-gate {
530Sstevel@tonic-gate 	switch (which) {
540Sstevel@tonic-gate 
550Sstevel@tonic-gate 	/*
560Sstevel@tonic-gate 	 * if it is not handled in mach_sysconfig either
570Sstevel@tonic-gate 	 * it must be EINVAL.
580Sstevel@tonic-gate 	 */
590Sstevel@tonic-gate 	default:
600Sstevel@tonic-gate 		return (mach_sysconfig(which)); /* `uname -i`/os */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 	case _CONFIG_CLK_TCK:
630Sstevel@tonic-gate 		return ((long)hz);	/* clock frequency per second */
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	case _CONFIG_PROF_TCK:
660Sstevel@tonic-gate 		return ((long)hz);	/* profiling clock freq per sec */
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	case _CONFIG_NGROUPS:
690Sstevel@tonic-gate 		/*
700Sstevel@tonic-gate 		 * Maximum number of supplementary groups.
710Sstevel@tonic-gate 		 */
720Sstevel@tonic-gate 		return (ngroups_max);
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	case _CONFIG_OPEN_FILES:
750Sstevel@tonic-gate 		/*
760Sstevel@tonic-gate 		 * Maximum number of open files (soft limit).
770Sstevel@tonic-gate 		 */
780Sstevel@tonic-gate 		{
790Sstevel@tonic-gate 			rlim64_t fd_ctl;
800Sstevel@tonic-gate 			mutex_enter(&curproc->p_lock);
810Sstevel@tonic-gate 			fd_ctl = rctl_enforced_value(
820Sstevel@tonic-gate 			    rctlproc_legacy[RLIMIT_NOFILE], curproc->p_rctls,
830Sstevel@tonic-gate 			    curproc);
840Sstevel@tonic-gate 			mutex_exit(&curproc->p_lock);
850Sstevel@tonic-gate 			return ((ulong_t)fd_ctl);
860Sstevel@tonic-gate 		}
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	case _CONFIG_CHILD_MAX:
890Sstevel@tonic-gate 		/*
900Sstevel@tonic-gate 		 * Maximum number of processes.
910Sstevel@tonic-gate 		 */
920Sstevel@tonic-gate 		return (v.v_maxup);
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	case _CONFIG_POSIX_VER:
950Sstevel@tonic-gate 		return (_POSIX_VERSION); /* current POSIX version */
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	case _CONFIG_PAGESIZE:
980Sstevel@tonic-gate 		return (PAGESIZE);
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 	case _CONFIG_XOPEN_VER:
1010Sstevel@tonic-gate 		return (_XOPEN_VERSION); /* current XOPEN version */
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	case _CONFIG_NPROC_CONF:
1040Sstevel@tonic-gate 		return (zone_ncpus_get(curproc->p_zone));
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	case _CONFIG_NPROC_ONLN:
1070Sstevel@tonic-gate 		return (zone_ncpus_online_get(curproc->p_zone));
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 	case _CONFIG_NPROC_MAX:
1100Sstevel@tonic-gate 		return (max_ncpus);
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 	case _CONFIG_STACK_PROT:
1130Sstevel@tonic-gate 		return (curproc->p_stkprot & ~PROT_USER);
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 	case _CONFIG_AIO_LISTIO_MAX:
1160Sstevel@tonic-gate 		return (_AIO_LISTIO_MAX);
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 	case _CONFIG_AIO_MAX:
1190Sstevel@tonic-gate 		return (_AIO_MAX);
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	case _CONFIG_AIO_PRIO_DELTA_MAX:
1220Sstevel@tonic-gate 		return (0);
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	case _CONFIG_DELAYTIMER_MAX:
1250Sstevel@tonic-gate 		return (INT_MAX);
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 	case _CONFIG_MQ_OPEN_MAX:
1280Sstevel@tonic-gate 		return (_MQ_OPEN_MAX);
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	case _CONFIG_MQ_PRIO_MAX:
1310Sstevel@tonic-gate 		return (_MQ_PRIO_MAX);
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	case _CONFIG_RTSIG_MAX:
1340Sstevel@tonic-gate 		return (_SIGRTMAX - _SIGRTMIN + 1);
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	case _CONFIG_SEM_NSEMS_MAX:
1370Sstevel@tonic-gate 		return (_SEM_NSEMS_MAX);
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	case _CONFIG_SEM_VALUE_MAX:
1400Sstevel@tonic-gate 		return (_SEM_VALUE_MAX);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	case _CONFIG_SIGQUEUE_MAX:
1430Sstevel@tonic-gate 		return (_SIGQUEUE_MAX);
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 	case _CONFIG_SIGRT_MIN:
1460Sstevel@tonic-gate 		return (_SIGRTMIN);
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 	case _CONFIG_SIGRT_MAX:
1490Sstevel@tonic-gate 		return (_SIGRTMAX);
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 	case _CONFIG_TIMER_MAX:
1521885Sraf 		return (timer_max);
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	case _CONFIG_PHYS_PAGES:
155*7884Sgerald.jelinek@sun.com 		/*
156*7884Sgerald.jelinek@sun.com 		 * If the non-global zone has a phys. memory cap, use that.
157*7884Sgerald.jelinek@sun.com 		 * We always report the system-wide value for the global zone,
158*7884Sgerald.jelinek@sun.com 		 * even though rcapd can be used on the global zone too.
159*7884Sgerald.jelinek@sun.com 		 */
160*7884Sgerald.jelinek@sun.com 		if (!INGLOBALZONE(curproc) &&
161*7884Sgerald.jelinek@sun.com 		    curproc->p_zone->zone_phys_mcap != 0)
162*7884Sgerald.jelinek@sun.com 			return (MIN(btop(curproc->p_zone->zone_phys_mcap),
163*7884Sgerald.jelinek@sun.com 			    physinstalled));
164*7884Sgerald.jelinek@sun.com 
1650Sstevel@tonic-gate 		return (physinstalled);
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate 	case _CONFIG_AVPHYS_PAGES:
168*7884Sgerald.jelinek@sun.com 		/*
169*7884Sgerald.jelinek@sun.com 		 * If the non-global zone has a phys. memory cap, use
170*7884Sgerald.jelinek@sun.com 		 * the phys. memory cap - zone's current rss.  We always
171*7884Sgerald.jelinek@sun.com 		 * report the system-wide value for the global zone, even
172*7884Sgerald.jelinek@sun.com 		 * though rcapd can be used on the global zone too.
173*7884Sgerald.jelinek@sun.com 		 */
174*7884Sgerald.jelinek@sun.com 		if (!INGLOBALZONE(curproc) &&
175*7884Sgerald.jelinek@sun.com 		    curproc->p_zone->zone_phys_mcap != 0) {
176*7884Sgerald.jelinek@sun.com 			pgcnt_t cap, rss, free;
177*7884Sgerald.jelinek@sun.com 			vmusage_t in_use;
178*7884Sgerald.jelinek@sun.com 			size_t cnt = 1;
179*7884Sgerald.jelinek@sun.com 
180*7884Sgerald.jelinek@sun.com 			cap = btop(curproc->p_zone->zone_phys_mcap);
181*7884Sgerald.jelinek@sun.com 			if (cap > physinstalled)
182*7884Sgerald.jelinek@sun.com 				return (freemem);
183*7884Sgerald.jelinek@sun.com 
184*7884Sgerald.jelinek@sun.com 			if (vm_getusage(VMUSAGE_ZONE, 1, &in_use, &cnt,
185*7884Sgerald.jelinek@sun.com 			    FKIOCTL) != 0)
186*7884Sgerald.jelinek@sun.com 				in_use.vmu_rss_all = 0;
187*7884Sgerald.jelinek@sun.com 			rss = btop(in_use.vmu_rss_all);
188*7884Sgerald.jelinek@sun.com 			/*
189*7884Sgerald.jelinek@sun.com 			 * Because rcapd implements a soft cap, it is possible
190*7884Sgerald.jelinek@sun.com 			 * for rss to be temporarily over the cap.
191*7884Sgerald.jelinek@sun.com 			 */
192*7884Sgerald.jelinek@sun.com 			if (cap > rss)
193*7884Sgerald.jelinek@sun.com 				free = cap - rss;
194*7884Sgerald.jelinek@sun.com 			else
195*7884Sgerald.jelinek@sun.com 				free = 0;
196*7884Sgerald.jelinek@sun.com 			return (MIN(free, freemem));
197*7884Sgerald.jelinek@sun.com 		}
198*7884Sgerald.jelinek@sun.com 
1990Sstevel@tonic-gate 		return (freemem);
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate 	case _CONFIG_MAXPID:
2020Sstevel@tonic-gate 		return (maxpid);
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate 	case _CONFIG_CPUID_MAX:
2050Sstevel@tonic-gate 		return (max_cpuid);
2060Sstevel@tonic-gate 
2074321Scasper 	case _CONFIG_EPHID_MAX:
2084321Scasper 		return (MAXEPHUID);
2094321Scasper 
2100Sstevel@tonic-gate 	case _CONFIG_SYMLOOP_MAX:
2110Sstevel@tonic-gate 		return (MAXSYMLINKS);
2120Sstevel@tonic-gate 	}
2130Sstevel@tonic-gate }
214