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.
25*440a8a36SPatrick Mooney * Copyright 2016 Joyent, Inc.
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
297c478bd9Sstevel@tonic-gate /* All Rights Reserved */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #include <sys/param.h>
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
347c478bd9Sstevel@tonic-gate #include <sys/systm.h>
357c478bd9Sstevel@tonic-gate #include <sys/tuneable.h>
367c478bd9Sstevel@tonic-gate #include <sys/errno.h>
377c478bd9Sstevel@tonic-gate #include <sys/var.h>
387c478bd9Sstevel@tonic-gate #include <sys/signal.h>
397c478bd9Sstevel@tonic-gate #include <sys/time.h>
407c478bd9Sstevel@tonic-gate #include <sys/sysconfig.h>
417c478bd9Sstevel@tonic-gate #include <sys/resource.h>
427c478bd9Sstevel@tonic-gate #include <sys/ulimit.h>
437c478bd9Sstevel@tonic-gate #include <sys/unistd.h>
447c478bd9Sstevel@tonic-gate #include <sys/debug.h>
457c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
467c478bd9Sstevel@tonic-gate #include <sys/mman.h>
477c478bd9Sstevel@tonic-gate #include <sys/timer.h>
487c478bd9Sstevel@tonic-gate #include <sys/zone.h>
4900792c0bS #include <sys/vm_usage.h>
504c46c814SRobert Mustacchi #include <vm/as.h>
517c478bd9Sstevel@tonic-gate
525e989a96SDavid Höppner extern rctl_hndl_t rc_process_sigqueue;
535e989a96SDavid Höppner
547c478bd9Sstevel@tonic-gate long
sysconfig(int which)557c478bd9Sstevel@tonic-gate sysconfig(int which)
567c478bd9Sstevel@tonic-gate {
577c478bd9Sstevel@tonic-gate switch (which) {
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate * if it is not handled in mach_sysconfig either
617c478bd9Sstevel@tonic-gate * it must be EINVAL.
627c478bd9Sstevel@tonic-gate */
637c478bd9Sstevel@tonic-gate default:
647c478bd9Sstevel@tonic-gate return (mach_sysconfig(which)); /* `uname -i`/os */
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate case _CONFIG_CLK_TCK:
677c478bd9Sstevel@tonic-gate return ((long)hz); /* clock frequency per second */
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate case _CONFIG_PROF_TCK:
707c478bd9Sstevel@tonic-gate return ((long)hz); /* profiling clock freq per sec */
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate case _CONFIG_NGROUPS:
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate * Maximum number of supplementary groups.
757c478bd9Sstevel@tonic-gate */
767c478bd9Sstevel@tonic-gate return (ngroups_max);
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate case _CONFIG_OPEN_FILES:
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate * Maximum number of open files (soft limit).
817c478bd9Sstevel@tonic-gate */
827c478bd9Sstevel@tonic-gate {
837c478bd9Sstevel@tonic-gate rlim64_t fd_ctl;
847c478bd9Sstevel@tonic-gate mutex_enter(&curproc->p_lock);
857c478bd9Sstevel@tonic-gate fd_ctl = rctl_enforced_value(
867c478bd9Sstevel@tonic-gate rctlproc_legacy[RLIMIT_NOFILE], curproc->p_rctls,
877c478bd9Sstevel@tonic-gate curproc);
887c478bd9Sstevel@tonic-gate mutex_exit(&curproc->p_lock);
897c478bd9Sstevel@tonic-gate return ((ulong_t)fd_ctl);
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate case _CONFIG_CHILD_MAX:
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate * Maximum number of processes.
957c478bd9Sstevel@tonic-gate */
967c478bd9Sstevel@tonic-gate return (v.v_maxup);
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate case _CONFIG_POSIX_VER:
997c478bd9Sstevel@tonic-gate return (_POSIX_VERSION); /* current POSIX version */
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate case _CONFIG_PAGESIZE:
1027c478bd9Sstevel@tonic-gate return (PAGESIZE);
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate case _CONFIG_XOPEN_VER:
1057c478bd9Sstevel@tonic-gate return (_XOPEN_VERSION); /* current XOPEN version */
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate case _CONFIG_NPROC_CONF:
1087c478bd9Sstevel@tonic-gate return (zone_ncpus_get(curproc->p_zone));
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate case _CONFIG_NPROC_ONLN:
1117c478bd9Sstevel@tonic-gate return (zone_ncpus_online_get(curproc->p_zone));
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate case _CONFIG_NPROC_MAX:
1147c478bd9Sstevel@tonic-gate return (max_ncpus);
1157c478bd9Sstevel@tonic-gate
116*440a8a36SPatrick Mooney case _CONFIG_NPROC_NCPU:
117*440a8a36SPatrick Mooney return (NCPU); /* Private sysconfig for direct NCPU access */
118*440a8a36SPatrick Mooney
1197c478bd9Sstevel@tonic-gate case _CONFIG_STACK_PROT:
1207c478bd9Sstevel@tonic-gate return (curproc->p_stkprot & ~PROT_USER);
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate case _CONFIG_AIO_LISTIO_MAX:
1237c478bd9Sstevel@tonic-gate return (_AIO_LISTIO_MAX);
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate case _CONFIG_AIO_MAX:
1267c478bd9Sstevel@tonic-gate return (_AIO_MAX);
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate case _CONFIG_AIO_PRIO_DELTA_MAX:
1297c478bd9Sstevel@tonic-gate return (0);
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate case _CONFIG_DELAYTIMER_MAX:
1327c478bd9Sstevel@tonic-gate return (INT_MAX);
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate case _CONFIG_MQ_OPEN_MAX:
1357c478bd9Sstevel@tonic-gate return (_MQ_OPEN_MAX);
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate case _CONFIG_MQ_PRIO_MAX:
1387c478bd9Sstevel@tonic-gate return (_MQ_PRIO_MAX);
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate case _CONFIG_RTSIG_MAX:
1417c478bd9Sstevel@tonic-gate return (_SIGRTMAX - _SIGRTMIN + 1);
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate case _CONFIG_SEM_NSEMS_MAX:
1447c478bd9Sstevel@tonic-gate return (_SEM_NSEMS_MAX);
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate case _CONFIG_SEM_VALUE_MAX:
1477c478bd9Sstevel@tonic-gate return (_SEM_VALUE_MAX);
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate case _CONFIG_SIGQUEUE_MAX:
1505e989a96SDavid Höppner /*
1515e989a96SDavid Höppner * Maximum number of outstanding queued signals.
1525e989a96SDavid Höppner */
1535e989a96SDavid Höppner {
1545e989a96SDavid Höppner rlim64_t sigqsz_max;
1555e989a96SDavid Höppner mutex_enter(&curproc->p_lock);
1565e989a96SDavid Höppner sigqsz_max = rctl_enforced_value(rc_process_sigqueue,
1575e989a96SDavid Höppner curproc->p_rctls, curproc);
1585e989a96SDavid Höppner mutex_exit(&curproc->p_lock);
1595e989a96SDavid Höppner return ((uint_t)sigqsz_max);
1605e989a96SDavid Höppner }
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate case _CONFIG_SIGRT_MIN:
1637c478bd9Sstevel@tonic-gate return (_SIGRTMIN);
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate case _CONFIG_SIGRT_MAX:
1667c478bd9Sstevel@tonic-gate return (_SIGRTMAX);
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate case _CONFIG_TIMER_MAX:
16934709573Sraf return (timer_max);
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate case _CONFIG_PHYS_PAGES:
17200792c0bS /*
17300792c0bS * If the non-global zone has a phys. memory cap, use that.
17400792c0bS * We always report the system-wide value for the global zone,
17500792c0bS * even though rcapd can be used on the global zone too.
17600792c0bS */
17700792c0bS if (!INGLOBALZONE(curproc) &&
17800792c0bS curproc->p_zone->zone_phys_mcap != 0)
17900792c0bS return (MIN(btop(curproc->p_zone->zone_phys_mcap),
18000792c0bS physinstalled));
18100792c0bS
1827c478bd9Sstevel@tonic-gate return (physinstalled);
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate case _CONFIG_AVPHYS_PAGES:
18500792c0bS /*
18600792c0bS * If the non-global zone has a phys. memory cap, use
18700792c0bS * the phys. memory cap - zone's current rss. We always
18800792c0bS * report the system-wide value for the global zone, even
18900792c0bS * though rcapd can be used on the global zone too.
19000792c0bS */
19100792c0bS if (!INGLOBALZONE(curproc) &&
19200792c0bS curproc->p_zone->zone_phys_mcap != 0) {
19300792c0bS pgcnt_t cap, rss, free;
19400792c0bS vmusage_t in_use;
19500792c0bS size_t cnt = 1;
19600792c0bS
19700792c0bS cap = btop(curproc->p_zone->zone_phys_mcap);
19800792c0bS if (cap > physinstalled)
19900792c0bS return (freemem);
20000792c0bS
20100792c0bS if (vm_getusage(VMUSAGE_ZONE, 1, &in_use, &cnt,
20200792c0bS FKIOCTL) != 0)
20300792c0bS in_use.vmu_rss_all = 0;
20400792c0bS rss = btop(in_use.vmu_rss_all);
20500792c0bS /*
20600792c0bS * Because rcapd implements a soft cap, it is possible
20700792c0bS * for rss to be temporarily over the cap.
20800792c0bS */
20900792c0bS if (cap > rss)
21000792c0bS free = cap - rss;
21100792c0bS else
21200792c0bS free = 0;
21300792c0bS return (MIN(free, freemem));
21400792c0bS }
21500792c0bS
2167c478bd9Sstevel@tonic-gate return (freemem);
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate case _CONFIG_MAXPID:
2197c478bd9Sstevel@tonic-gate return (maxpid);
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate case _CONFIG_CPUID_MAX:
2227c478bd9Sstevel@tonic-gate return (max_cpuid);
2237c478bd9Sstevel@tonic-gate
224f48205beScasper case _CONFIG_EPHID_MAX:
225f48205beScasper return (MAXEPHUID);
226f48205beScasper
2274c46c814SRobert Mustacchi case _CONFIG_UADDR_MAX:
2284c46c814SRobert Mustacchi return ((long)(uintptr_t)curproc->p_as->a_userlimit);
2294c46c814SRobert Mustacchi
2307c478bd9Sstevel@tonic-gate case _CONFIG_SYMLOOP_MAX:
2317c478bd9Sstevel@tonic-gate return (MAXSYMLINKS);
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate }
234