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 /*
2300792c0bS * 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>
4800792c0bS #include <sys/vm_usage.h>
497c478bd9Sstevel@tonic-gate
50*5e989a96SDavid Höppner extern rctl_hndl_t rc_process_sigqueue;
51*5e989a96SDavid Höppner
527c478bd9Sstevel@tonic-gate long
sysconfig(int which)537c478bd9Sstevel@tonic-gate sysconfig(int which)
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate switch (which) {
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate * if it is not handled in mach_sysconfig either
597c478bd9Sstevel@tonic-gate * it must be EINVAL.
607c478bd9Sstevel@tonic-gate */
617c478bd9Sstevel@tonic-gate default:
627c478bd9Sstevel@tonic-gate return (mach_sysconfig(which)); /* `uname -i`/os */
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate case _CONFIG_CLK_TCK:
657c478bd9Sstevel@tonic-gate return ((long)hz); /* clock frequency per second */
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate case _CONFIG_PROF_TCK:
687c478bd9Sstevel@tonic-gate return ((long)hz); /* profiling clock freq per sec */
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate case _CONFIG_NGROUPS:
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate * Maximum number of supplementary groups.
737c478bd9Sstevel@tonic-gate */
747c478bd9Sstevel@tonic-gate return (ngroups_max);
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate case _CONFIG_OPEN_FILES:
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate * Maximum number of open files (soft limit).
797c478bd9Sstevel@tonic-gate */
807c478bd9Sstevel@tonic-gate {
817c478bd9Sstevel@tonic-gate rlim64_t fd_ctl;
827c478bd9Sstevel@tonic-gate mutex_enter(&curproc->p_lock);
837c478bd9Sstevel@tonic-gate fd_ctl = rctl_enforced_value(
847c478bd9Sstevel@tonic-gate rctlproc_legacy[RLIMIT_NOFILE], curproc->p_rctls,
857c478bd9Sstevel@tonic-gate curproc);
867c478bd9Sstevel@tonic-gate mutex_exit(&curproc->p_lock);
877c478bd9Sstevel@tonic-gate return ((ulong_t)fd_ctl);
887c478bd9Sstevel@tonic-gate }
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate case _CONFIG_CHILD_MAX:
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate * Maximum number of processes.
937c478bd9Sstevel@tonic-gate */
947c478bd9Sstevel@tonic-gate return (v.v_maxup);
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate case _CONFIG_POSIX_VER:
977c478bd9Sstevel@tonic-gate return (_POSIX_VERSION); /* current POSIX version */
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate case _CONFIG_PAGESIZE:
1007c478bd9Sstevel@tonic-gate return (PAGESIZE);
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate case _CONFIG_XOPEN_VER:
1037c478bd9Sstevel@tonic-gate return (_XOPEN_VERSION); /* current XOPEN version */
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate case _CONFIG_NPROC_CONF:
1067c478bd9Sstevel@tonic-gate return (zone_ncpus_get(curproc->p_zone));
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate case _CONFIG_NPROC_ONLN:
1097c478bd9Sstevel@tonic-gate return (zone_ncpus_online_get(curproc->p_zone));
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate case _CONFIG_NPROC_MAX:
1127c478bd9Sstevel@tonic-gate return (max_ncpus);
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate case _CONFIG_STACK_PROT:
1157c478bd9Sstevel@tonic-gate return (curproc->p_stkprot & ~PROT_USER);
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate case _CONFIG_AIO_LISTIO_MAX:
1187c478bd9Sstevel@tonic-gate return (_AIO_LISTIO_MAX);
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate case _CONFIG_AIO_MAX:
1217c478bd9Sstevel@tonic-gate return (_AIO_MAX);
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate case _CONFIG_AIO_PRIO_DELTA_MAX:
1247c478bd9Sstevel@tonic-gate return (0);
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate case _CONFIG_DELAYTIMER_MAX:
1277c478bd9Sstevel@tonic-gate return (INT_MAX);
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate case _CONFIG_MQ_OPEN_MAX:
1307c478bd9Sstevel@tonic-gate return (_MQ_OPEN_MAX);
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate case _CONFIG_MQ_PRIO_MAX:
1337c478bd9Sstevel@tonic-gate return (_MQ_PRIO_MAX);
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate case _CONFIG_RTSIG_MAX:
1367c478bd9Sstevel@tonic-gate return (_SIGRTMAX - _SIGRTMIN + 1);
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate case _CONFIG_SEM_NSEMS_MAX:
1397c478bd9Sstevel@tonic-gate return (_SEM_NSEMS_MAX);
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate case _CONFIG_SEM_VALUE_MAX:
1427c478bd9Sstevel@tonic-gate return (_SEM_VALUE_MAX);
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate case _CONFIG_SIGQUEUE_MAX:
145*5e989a96SDavid Höppner /*
146*5e989a96SDavid Höppner * Maximum number of outstanding queued signals.
147*5e989a96SDavid Höppner */
148*5e989a96SDavid Höppner {
149*5e989a96SDavid Höppner rlim64_t sigqsz_max;
150*5e989a96SDavid Höppner mutex_enter(&curproc->p_lock);
151*5e989a96SDavid Höppner sigqsz_max = rctl_enforced_value(rc_process_sigqueue,
152*5e989a96SDavid Höppner curproc->p_rctls, curproc);
153*5e989a96SDavid Höppner mutex_exit(&curproc->p_lock);
154*5e989a96SDavid Höppner return ((uint_t)sigqsz_max);
155*5e989a96SDavid Höppner }
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate case _CONFIG_SIGRT_MIN:
1587c478bd9Sstevel@tonic-gate return (_SIGRTMIN);
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate case _CONFIG_SIGRT_MAX:
1617c478bd9Sstevel@tonic-gate return (_SIGRTMAX);
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate case _CONFIG_TIMER_MAX:
16434709573Sraf return (timer_max);
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate case _CONFIG_PHYS_PAGES:
16700792c0bS /*
16800792c0bS * If the non-global zone has a phys. memory cap, use that.
16900792c0bS * We always report the system-wide value for the global zone,
17000792c0bS * even though rcapd can be used on the global zone too.
17100792c0bS */
17200792c0bS if (!INGLOBALZONE(curproc) &&
17300792c0bS curproc->p_zone->zone_phys_mcap != 0)
17400792c0bS return (MIN(btop(curproc->p_zone->zone_phys_mcap),
17500792c0bS physinstalled));
17600792c0bS
1777c478bd9Sstevel@tonic-gate return (physinstalled);
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate case _CONFIG_AVPHYS_PAGES:
18000792c0bS /*
18100792c0bS * If the non-global zone has a phys. memory cap, use
18200792c0bS * the phys. memory cap - zone's current rss. We always
18300792c0bS * report the system-wide value for the global zone, even
18400792c0bS * though rcapd can be used on the global zone too.
18500792c0bS */
18600792c0bS if (!INGLOBALZONE(curproc) &&
18700792c0bS curproc->p_zone->zone_phys_mcap != 0) {
18800792c0bS pgcnt_t cap, rss, free;
18900792c0bS vmusage_t in_use;
19000792c0bS size_t cnt = 1;
19100792c0bS
19200792c0bS cap = btop(curproc->p_zone->zone_phys_mcap);
19300792c0bS if (cap > physinstalled)
19400792c0bS return (freemem);
19500792c0bS
19600792c0bS if (vm_getusage(VMUSAGE_ZONE, 1, &in_use, &cnt,
19700792c0bS FKIOCTL) != 0)
19800792c0bS in_use.vmu_rss_all = 0;
19900792c0bS rss = btop(in_use.vmu_rss_all);
20000792c0bS /*
20100792c0bS * Because rcapd implements a soft cap, it is possible
20200792c0bS * for rss to be temporarily over the cap.
20300792c0bS */
20400792c0bS if (cap > rss)
20500792c0bS free = cap - rss;
20600792c0bS else
20700792c0bS free = 0;
20800792c0bS return (MIN(free, freemem));
20900792c0bS }
21000792c0bS
2117c478bd9Sstevel@tonic-gate return (freemem);
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate case _CONFIG_MAXPID:
2147c478bd9Sstevel@tonic-gate return (maxpid);
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate case _CONFIG_CPUID_MAX:
2177c478bd9Sstevel@tonic-gate return (max_cpuid);
2187c478bd9Sstevel@tonic-gate
219f48205beScasper case _CONFIG_EPHID_MAX:
220f48205beScasper return (MAXEPHUID);
221f48205beScasper
2227c478bd9Sstevel@tonic-gate case _CONFIG_SYMLOOP_MAX:
2237c478bd9Sstevel@tonic-gate return (MAXSYMLINKS);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate }
226