xref: /titanic_50/usr/src/uts/common/syscall/sysconfig.c (revision 00792c0b1e9a531b1a2291490070a9611159dc29)
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
534709573Sraf  * Common Development and Distribution License (the "License").
634709573Sraf  * 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  */
2134709573Sraf 
227c478bd9Sstevel@tonic-gate /*
23*00792c0bS  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/param.h>
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
337c478bd9Sstevel@tonic-gate #include <sys/systm.h>
347c478bd9Sstevel@tonic-gate #include <sys/tuneable.h>
357c478bd9Sstevel@tonic-gate #include <sys/errno.h>
367c478bd9Sstevel@tonic-gate #include <sys/var.h>
377c478bd9Sstevel@tonic-gate #include <sys/signal.h>
387c478bd9Sstevel@tonic-gate #include <sys/time.h>
397c478bd9Sstevel@tonic-gate #include <sys/sysconfig.h>
407c478bd9Sstevel@tonic-gate #include <sys/resource.h>
417c478bd9Sstevel@tonic-gate #include <sys/ulimit.h>
427c478bd9Sstevel@tonic-gate #include <sys/unistd.h>
437c478bd9Sstevel@tonic-gate #include <sys/debug.h>
447c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
457c478bd9Sstevel@tonic-gate #include <sys/mman.h>
467c478bd9Sstevel@tonic-gate #include <sys/timer.h>
477c478bd9Sstevel@tonic-gate #include <sys/zone.h>
48*00792c0bS #include <sys/vm_usage.h>
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate long
517c478bd9Sstevel@tonic-gate sysconfig(int which)
527c478bd9Sstevel@tonic-gate {
537c478bd9Sstevel@tonic-gate 	switch (which) {
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate 	/*
567c478bd9Sstevel@tonic-gate 	 * if it is not handled in mach_sysconfig either
577c478bd9Sstevel@tonic-gate 	 * it must be EINVAL.
587c478bd9Sstevel@tonic-gate 	 */
597c478bd9Sstevel@tonic-gate 	default:
607c478bd9Sstevel@tonic-gate 		return (mach_sysconfig(which)); /* `uname -i`/os */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	case _CONFIG_CLK_TCK:
637c478bd9Sstevel@tonic-gate 		return ((long)hz);	/* clock frequency per second */
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 	case _CONFIG_PROF_TCK:
667c478bd9Sstevel@tonic-gate 		return ((long)hz);	/* profiling clock freq per sec */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 	case _CONFIG_NGROUPS:
697c478bd9Sstevel@tonic-gate 		/*
707c478bd9Sstevel@tonic-gate 		 * Maximum number of supplementary groups.
717c478bd9Sstevel@tonic-gate 		 */
727c478bd9Sstevel@tonic-gate 		return (ngroups_max);
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	case _CONFIG_OPEN_FILES:
757c478bd9Sstevel@tonic-gate 		/*
767c478bd9Sstevel@tonic-gate 		 * Maximum number of open files (soft limit).
777c478bd9Sstevel@tonic-gate 		 */
787c478bd9Sstevel@tonic-gate 		{
797c478bd9Sstevel@tonic-gate 			rlim64_t fd_ctl;
807c478bd9Sstevel@tonic-gate 			mutex_enter(&curproc->p_lock);
817c478bd9Sstevel@tonic-gate 			fd_ctl = rctl_enforced_value(
827c478bd9Sstevel@tonic-gate 			    rctlproc_legacy[RLIMIT_NOFILE], curproc->p_rctls,
837c478bd9Sstevel@tonic-gate 			    curproc);
847c478bd9Sstevel@tonic-gate 			mutex_exit(&curproc->p_lock);
857c478bd9Sstevel@tonic-gate 			return ((ulong_t)fd_ctl);
867c478bd9Sstevel@tonic-gate 		}
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	case _CONFIG_CHILD_MAX:
897c478bd9Sstevel@tonic-gate 		/*
907c478bd9Sstevel@tonic-gate 		 * Maximum number of processes.
917c478bd9Sstevel@tonic-gate 		 */
927c478bd9Sstevel@tonic-gate 		return (v.v_maxup);
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	case _CONFIG_POSIX_VER:
957c478bd9Sstevel@tonic-gate 		return (_POSIX_VERSION); /* current POSIX version */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	case _CONFIG_PAGESIZE:
987c478bd9Sstevel@tonic-gate 		return (PAGESIZE);
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	case _CONFIG_XOPEN_VER:
1017c478bd9Sstevel@tonic-gate 		return (_XOPEN_VERSION); /* current XOPEN version */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	case _CONFIG_NPROC_CONF:
1047c478bd9Sstevel@tonic-gate 		return (zone_ncpus_get(curproc->p_zone));
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	case _CONFIG_NPROC_ONLN:
1077c478bd9Sstevel@tonic-gate 		return (zone_ncpus_online_get(curproc->p_zone));
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	case _CONFIG_NPROC_MAX:
1107c478bd9Sstevel@tonic-gate 		return (max_ncpus);
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	case _CONFIG_STACK_PROT:
1137c478bd9Sstevel@tonic-gate 		return (curproc->p_stkprot & ~PROT_USER);
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 	case _CONFIG_AIO_LISTIO_MAX:
1167c478bd9Sstevel@tonic-gate 		return (_AIO_LISTIO_MAX);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	case _CONFIG_AIO_MAX:
1197c478bd9Sstevel@tonic-gate 		return (_AIO_MAX);
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	case _CONFIG_AIO_PRIO_DELTA_MAX:
1227c478bd9Sstevel@tonic-gate 		return (0);
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	case _CONFIG_DELAYTIMER_MAX:
1257c478bd9Sstevel@tonic-gate 		return (INT_MAX);
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	case _CONFIG_MQ_OPEN_MAX:
1287c478bd9Sstevel@tonic-gate 		return (_MQ_OPEN_MAX);
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	case _CONFIG_MQ_PRIO_MAX:
1317c478bd9Sstevel@tonic-gate 		return (_MQ_PRIO_MAX);
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	case _CONFIG_RTSIG_MAX:
1347c478bd9Sstevel@tonic-gate 		return (_SIGRTMAX - _SIGRTMIN + 1);
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 	case _CONFIG_SEM_NSEMS_MAX:
1377c478bd9Sstevel@tonic-gate 		return (_SEM_NSEMS_MAX);
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	case _CONFIG_SEM_VALUE_MAX:
1407c478bd9Sstevel@tonic-gate 		return (_SEM_VALUE_MAX);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	case _CONFIG_SIGQUEUE_MAX:
1437c478bd9Sstevel@tonic-gate 		return (_SIGQUEUE_MAX);
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	case _CONFIG_SIGRT_MIN:
1467c478bd9Sstevel@tonic-gate 		return (_SIGRTMIN);
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	case _CONFIG_SIGRT_MAX:
1497c478bd9Sstevel@tonic-gate 		return (_SIGRTMAX);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	case _CONFIG_TIMER_MAX:
15234709573Sraf 		return (timer_max);
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	case _CONFIG_PHYS_PAGES:
155*00792c0bS 		/*
156*00792c0bS 		 * If the non-global zone has a phys. memory cap, use that.
157*00792c0bS 		 * We always report the system-wide value for the global zone,
158*00792c0bS 		 * even though rcapd can be used on the global zone too.
159*00792c0bS 		 */
160*00792c0bS 		if (!INGLOBALZONE(curproc) &&
161*00792c0bS 		    curproc->p_zone->zone_phys_mcap != 0)
162*00792c0bS 			return (MIN(btop(curproc->p_zone->zone_phys_mcap),
163*00792c0bS 			    physinstalled));
164*00792c0bS 
1657c478bd9Sstevel@tonic-gate 		return (physinstalled);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	case _CONFIG_AVPHYS_PAGES:
168*00792c0bS 		/*
169*00792c0bS 		 * If the non-global zone has a phys. memory cap, use
170*00792c0bS 		 * the phys. memory cap - zone's current rss.  We always
171*00792c0bS 		 * report the system-wide value for the global zone, even
172*00792c0bS 		 * though rcapd can be used on the global zone too.
173*00792c0bS 		 */
174*00792c0bS 		if (!INGLOBALZONE(curproc) &&
175*00792c0bS 		    curproc->p_zone->zone_phys_mcap != 0) {
176*00792c0bS 			pgcnt_t cap, rss, free;
177*00792c0bS 			vmusage_t in_use;
178*00792c0bS 			size_t cnt = 1;
179*00792c0bS 
180*00792c0bS 			cap = btop(curproc->p_zone->zone_phys_mcap);
181*00792c0bS 			if (cap > physinstalled)
182*00792c0bS 				return (freemem);
183*00792c0bS 
184*00792c0bS 			if (vm_getusage(VMUSAGE_ZONE, 1, &in_use, &cnt,
185*00792c0bS 			    FKIOCTL) != 0)
186*00792c0bS 				in_use.vmu_rss_all = 0;
187*00792c0bS 			rss = btop(in_use.vmu_rss_all);
188*00792c0bS 			/*
189*00792c0bS 			 * Because rcapd implements a soft cap, it is possible
190*00792c0bS 			 * for rss to be temporarily over the cap.
191*00792c0bS 			 */
192*00792c0bS 			if (cap > rss)
193*00792c0bS 				free = cap - rss;
194*00792c0bS 			else
195*00792c0bS 				free = 0;
196*00792c0bS 			return (MIN(free, freemem));
197*00792c0bS 		}
198*00792c0bS 
1997c478bd9Sstevel@tonic-gate 		return (freemem);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	case _CONFIG_MAXPID:
2027c478bd9Sstevel@tonic-gate 		return (maxpid);
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 	case _CONFIG_CPUID_MAX:
2057c478bd9Sstevel@tonic-gate 		return (max_cpuid);
2067c478bd9Sstevel@tonic-gate 
207f48205beScasper 	case _CONFIG_EPHID_MAX:
208f48205beScasper 		return (MAXEPHUID);
209f48205beScasper 
2107c478bd9Sstevel@tonic-gate 	case _CONFIG_SYMLOOP_MAX:
2117c478bd9Sstevel@tonic-gate 		return (MAXSYMLINKS);
2127c478bd9Sstevel@tonic-gate 	}
2137c478bd9Sstevel@tonic-gate }
214