Home | History | Annotate | Line # | Download | only in gen
      1  1.45  riastrad /*	$NetBSD: sysconf.c,v 1.45 2024/12/22 23:17:26 riastradh Exp $	*/
      2   1.2       cgd 
      3   1.1       cgd /*-
      4   1.1       cgd  * Copyright (c) 1993
      5   1.1       cgd  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * This code is derived from software contributed to Berkeley by
      8   1.1       cgd  * Sean Eric Fagan of Cygnus Support.
      9   1.1       cgd  *
     10   1.1       cgd  * Redistribution and use in source and binary forms, with or without
     11   1.1       cgd  * modification, are permitted provided that the following conditions
     12   1.1       cgd  * are met:
     13   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     14   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     15   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     18  1.19       agc  * 3. Neither the name of the University nor the names of its contributors
     19   1.1       cgd  *    may be used to endorse or promote products derived from this software
     20   1.1       cgd  *    without specific prior written permission.
     21   1.1       cgd  *
     22   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.1       cgd  * SUCH DAMAGE.
     33   1.1       cgd  */
     34   1.1       cgd 
     35   1.4  christos #include <sys/cdefs.h>
     36   1.1       cgd #if defined(LIBC_SCCS) && !defined(lint)
     37   1.2       cgd #if 0
     38   1.1       cgd static char sccsid[] = "@(#)sysconf.c	8.2 (Berkeley) 3/20/94";
     39   1.2       cgd #else
     40  1.45  riastrad __RCSID("$NetBSD: sysconf.c,v 1.45 2024/12/22 23:17:26 riastradh Exp $");
     41   1.2       cgd #endif
     42   1.1       cgd #endif /* LIBC_SCCS and not lint */
     43   1.1       cgd 
     44   1.5       jtc #include "namespace.h"
     45   1.1       cgd #include <sys/param.h>
     46   1.1       cgd #include <sys/sysctl.h>
     47   1.1       cgd #include <sys/time.h>
     48   1.1       cgd #include <sys/resource.h>
     49  1.44    simonb #include <uvm/uvm_extern.h>
     50   1.1       cgd 
     51   1.1       cgd #include <errno.h>
     52  1.21     lukem #include <limits.h>
     53   1.7    kleink #include <time.h>
     54   1.1       cgd #include <unistd.h>
     55  1.32        ad #include <paths.h>
     56  1.33      matt #include <pwd.h>
     57   1.5       jtc 
     58   1.5       jtc #ifdef __weak_alias
     59  1.13    kleink __weak_alias(sysconf,__sysconf)
     60   1.5       jtc #endif
     61   1.1       cgd 
     62   1.1       cgd /*
     63   1.1       cgd  * sysconf --
     64   1.1       cgd  *	get configurable system variables.
     65   1.1       cgd  *
     66   1.1       cgd  * XXX
     67   1.1       cgd  * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values
     68   1.1       cgd  * not change during the lifetime of the calling process.  This would seem
     69   1.1       cgd  * to require that any change to system limits kill all running processes.
     70   1.1       cgd  * A workaround might be to cache the values when they are first retrieved
     71   1.1       cgd  * and then simply return the cached value on subsequent calls.  This is
     72   1.1       cgd  * less useful than returning up-to-date values, however.
     73   1.1       cgd  */
     74   1.1       cgd long
     75  1.23     rmind sysconf(int name)
     76   1.1       cgd {
     77   1.1       cgd 	struct rlimit rl;
     78   1.1       cgd 	size_t len;
     79  1.35  christos 	uint64_t mem;
     80  1.23     rmind 	int mib[CTL_MAXNAME], value;
     81  1.23     rmind 	unsigned int mib_len;
     82  1.15     perry 	struct clockinfo tmpclock;
     83  1.44    simonb 	struct uvmexp_sysctl uvmexp;
     84  1.15     perry 	static int clk_tck;
     85   1.1       cgd 
     86   1.1       cgd 	len = sizeof(value);
     87   1.1       cgd 
     88  1.23     rmind 	/* Default length of the MIB */
     89  1.23     rmind 	mib_len = 2;
     90  1.23     rmind 
     91   1.1       cgd 	switch (name) {
     92  1.20     lukem 
     93   1.1       cgd /* 1003.1 */
     94   1.1       cgd 	case _SC_ARG_MAX:
     95   1.1       cgd 		mib[0] = CTL_KERN;
     96   1.1       cgd 		mib[1] = KERN_ARGMAX;
     97   1.1       cgd 		break;
     98   1.1       cgd 	case _SC_CHILD_MAX:
     99   1.6     perry 		return (getrlimit(RLIMIT_NPROC, &rl) ? -1 : (long)rl.rlim_cur);
    100  1.16     bjh21 	case _O_SC_CLK_TCK:
    101  1.16     bjh21 		/*
    102  1.16     bjh21 		 * For applications compiled when CLK_TCK was a compile-time
    103  1.16     bjh21 		 * constant.
    104  1.16     bjh21 		 */
    105  1.16     bjh21 		return 100;
    106   1.1       cgd 	case _SC_CLK_TCK:
    107  1.15     perry 		/*
    108  1.15     perry 		 * Has to be handled specially because it returns a
    109  1.15     perry 		 * struct clockinfo instead of an integer. Also, since
    110  1.15     perry 		 * this might be called often by some things that
    111  1.15     perry 		 * don't grok CLK_TCK can be a macro expanding to a
    112  1.15     perry 		 * function, cache the value.
    113  1.15     perry 		 */
    114  1.15     perry 		if (clk_tck == 0) {
    115  1.15     perry 			mib[0] = CTL_KERN;
    116  1.15     perry 			mib[1] = KERN_CLOCKRATE;
    117  1.15     perry 			len = sizeof(struct clockinfo);
    118  1.15     perry 			clk_tck = sysctl(mib, 2, &tmpclock, &len, NULL, 0)
    119  1.15     perry 			    == -1 ? -1 : tmpclock.hz;
    120  1.15     perry 		}
    121  1.15     perry 		return(clk_tck);
    122   1.1       cgd 	case _SC_JOB_CONTROL:
    123   1.1       cgd 		mib[0] = CTL_KERN;
    124   1.1       cgd 		mib[1] = KERN_JOB_CONTROL;
    125   1.1       cgd 		goto yesno;
    126   1.1       cgd 	case _SC_NGROUPS_MAX:
    127   1.1       cgd 		mib[0] = CTL_KERN;
    128   1.1       cgd 		mib[1] = KERN_NGROUPS;
    129   1.1       cgd 		break;
    130   1.1       cgd 	case _SC_OPEN_MAX:
    131  1.45  riastrad 		return (getrlimit(RLIMIT_NOFILE, &rl) ? -1
    132  1.45  riastrad 		    : (long)rl.rlim_cur);
    133   1.1       cgd 	case _SC_STREAM_MAX:
    134   1.1       cgd 		mib[0] = CTL_USER;
    135   1.1       cgd 		mib[1] = USER_STREAM_MAX;
    136   1.1       cgd 		break;
    137   1.1       cgd 	case _SC_TZNAME_MAX:
    138   1.1       cgd 		mib[0] = CTL_USER;
    139   1.1       cgd 		mib[1] = USER_TZNAME_MAX;
    140   1.1       cgd 		break;
    141   1.1       cgd 	case _SC_SAVED_IDS:
    142   1.1       cgd 		mib[0] = CTL_KERN;
    143   1.1       cgd 		mib[1] = KERN_SAVED_IDS;
    144   1.1       cgd 		goto yesno;
    145   1.1       cgd 	case _SC_VERSION:
    146   1.1       cgd 		mib[0] = CTL_KERN;
    147   1.1       cgd 		mib[1] = KERN_POSIX1;
    148   1.1       cgd 		break;
    149   1.1       cgd 
    150   1.8    kleink /* 1003.1b */
    151   1.8    kleink 	case _SC_PAGESIZE:
    152  1.28      yamt 		return _getpagesize();
    153   1.8    kleink 	case _SC_FSYNC:
    154   1.8    kleink 		mib[0] = CTL_KERN;
    155   1.8    kleink 		mib[1] = KERN_FSYNC;
    156   1.8    kleink 		goto yesno;
    157   1.9    kleink 	case _SC_SYNCHRONIZED_IO:
    158   1.9    kleink 		mib[0] = CTL_KERN;
    159   1.9    kleink 		mib[1] = KERN_SYNCHRONIZED_IO;
    160  1.10    kleink 		goto yesno;
    161  1.10    kleink 	case _SC_MAPPED_FILES:
    162  1.10    kleink 		mib[0] = CTL_KERN;
    163  1.10    kleink 		mib[1] = KERN_MAPPED_FILES;
    164  1.10    kleink 		goto yesno;
    165  1.10    kleink 	case _SC_MEMLOCK:
    166  1.10    kleink 		mib[0] = CTL_KERN;
    167  1.10    kleink 		mib[1] = KERN_MEMLOCK;
    168  1.10    kleink 		goto yesno;
    169  1.10    kleink 	case _SC_MEMLOCK_RANGE:
    170  1.10    kleink 		mib[0] = CTL_KERN;
    171  1.10    kleink 		mib[1] = KERN_MEMLOCK_RANGE;
    172  1.10    kleink 		goto yesno;
    173  1.10    kleink 	case _SC_MEMORY_PROTECTION:
    174  1.10    kleink 		mib[0] = CTL_KERN;
    175  1.10    kleink 		mib[1] = KERN_MEMORY_PROTECTION;
    176  1.14    kleink 		goto yesno;
    177  1.14    kleink 	case _SC_MONOTONIC_CLOCK:
    178  1.14    kleink 		mib[0] = CTL_KERN;
    179  1.14    kleink 		mib[1] = KERN_MONOTONIC_CLOCK;
    180   1.9    kleink 		goto yesno;
    181  1.18    kleink 	case _SC_SEMAPHORES:
    182  1.18    kleink 		mib[0] = CTL_KERN;
    183  1.18    kleink 		mib[1] = KERN_POSIX_SEMAPHORES;
    184  1.18    kleink 		goto yesno;
    185  1.18    kleink 	case _SC_TIMERS:
    186  1.18    kleink 		mib[0] = CTL_KERN;
    187  1.18    kleink 		mib[1] = KERN_POSIX_TIMERS;
    188  1.18    kleink 		goto yesno;
    189  1.11    kleink 
    190  1.11    kleink /* 1003.1c */
    191  1.11    kleink 	case _SC_LOGIN_NAME_MAX:
    192  1.11    kleink 		mib[0] = CTL_KERN;
    193  1.11    kleink 		mib[1] = KERN_LOGIN_NAME_MAX;
    194  1.11    kleink 		break;
    195  1.18    kleink 	case _SC_THREADS:
    196  1.18    kleink 		mib[0] = CTL_KERN;
    197  1.18    kleink 		mib[1] = KERN_POSIX_THREADS;
    198  1.18    kleink 		goto yesno;
    199  1.18    kleink 
    200  1.18    kleink /* 1003.1j */
    201  1.18    kleink 	case _SC_BARRIERS:
    202  1.18    kleink 		mib[0] = CTL_KERN;
    203  1.18    kleink 		mib[1] = KERN_POSIX_BARRIERS;
    204  1.18    kleink 		goto yesno;
    205  1.18    kleink 	case _SC_SPIN_LOCKS:
    206  1.18    kleink 		mib[0] = CTL_KERN;
    207  1.18    kleink 		mib[1] = KERN_POSIX_SPIN_LOCKS;
    208  1.18    kleink 		goto yesno;
    209  1.18    kleink 	/* Historical; Threads option in 1003.1-2001 */
    210  1.18    kleink 	case _SC_READER_WRITER_LOCKS:
    211  1.18    kleink 		mib[0] = CTL_KERN;
    212  1.18    kleink 		mib[1] = KERN_POSIX_READER_WRITER_LOCKS;
    213  1.18    kleink 		goto yesno;
    214   1.8    kleink 
    215   1.1       cgd /* 1003.2 */
    216   1.1       cgd 	case _SC_BC_BASE_MAX:
    217   1.1       cgd 		mib[0] = CTL_USER;
    218   1.1       cgd 		mib[1] = USER_BC_BASE_MAX;
    219   1.1       cgd 		break;
    220   1.1       cgd 	case _SC_BC_DIM_MAX:
    221   1.1       cgd 		mib[0] = CTL_USER;
    222   1.1       cgd 		mib[1] = USER_BC_DIM_MAX;
    223   1.1       cgd 		break;
    224   1.1       cgd 	case _SC_BC_SCALE_MAX:
    225   1.1       cgd 		mib[0] = CTL_USER;
    226   1.1       cgd 		mib[1] = USER_BC_SCALE_MAX;
    227   1.1       cgd 		break;
    228   1.1       cgd 	case _SC_BC_STRING_MAX:
    229   1.1       cgd 		mib[0] = CTL_USER;
    230   1.1       cgd 		mib[1] = USER_BC_STRING_MAX;
    231   1.1       cgd 		break;
    232   1.1       cgd 	case _SC_COLL_WEIGHTS_MAX:
    233   1.1       cgd 		mib[0] = CTL_USER;
    234   1.1       cgd 		mib[1] = USER_COLL_WEIGHTS_MAX;
    235   1.1       cgd 		break;
    236   1.1       cgd 	case _SC_EXPR_NEST_MAX:
    237   1.1       cgd 		mib[0] = CTL_USER;
    238   1.1       cgd 		mib[1] = USER_EXPR_NEST_MAX;
    239   1.1       cgd 		break;
    240   1.1       cgd 	case _SC_LINE_MAX:
    241   1.1       cgd 		mib[0] = CTL_USER;
    242   1.1       cgd 		mib[1] = USER_LINE_MAX;
    243   1.1       cgd 		break;
    244   1.1       cgd 	case _SC_RE_DUP_MAX:
    245   1.1       cgd 		mib[0] = CTL_USER;
    246   1.1       cgd 		mib[1] = USER_RE_DUP_MAX;
    247   1.1       cgd 		break;
    248   1.1       cgd 	case _SC_2_VERSION:
    249   1.1       cgd 		mib[0] = CTL_USER;
    250   1.1       cgd 		mib[1] = USER_POSIX2_VERSION;
    251   1.1       cgd 		break;
    252   1.1       cgd 	case _SC_2_C_BIND:
    253   1.1       cgd 		mib[0] = CTL_USER;
    254   1.1       cgd 		mib[1] = USER_POSIX2_C_BIND;
    255   1.1       cgd 		goto yesno;
    256   1.1       cgd 	case _SC_2_C_DEV:
    257   1.1       cgd 		mib[0] = CTL_USER;
    258   1.1       cgd 		mib[1] = USER_POSIX2_C_DEV;
    259   1.1       cgd 		goto yesno;
    260   1.1       cgd 	case _SC_2_CHAR_TERM:
    261   1.1       cgd 		mib[0] = CTL_USER;
    262   1.1       cgd 		mib[1] = USER_POSIX2_CHAR_TERM;
    263   1.1       cgd 		goto yesno;
    264   1.1       cgd 	case _SC_2_FORT_DEV:
    265   1.1       cgd 		mib[0] = CTL_USER;
    266   1.1       cgd 		mib[1] = USER_POSIX2_FORT_DEV;
    267   1.1       cgd 		goto yesno;
    268   1.1       cgd 	case _SC_2_FORT_RUN:
    269   1.1       cgd 		mib[0] = CTL_USER;
    270   1.1       cgd 		mib[1] = USER_POSIX2_FORT_RUN;
    271   1.1       cgd 		goto yesno;
    272   1.1       cgd 	case _SC_2_LOCALEDEF:
    273   1.1       cgd 		mib[0] = CTL_USER;
    274   1.1       cgd 		mib[1] = USER_POSIX2_LOCALEDEF;
    275   1.1       cgd 		goto yesno;
    276   1.1       cgd 	case _SC_2_SW_DEV:
    277   1.1       cgd 		mib[0] = CTL_USER;
    278   1.1       cgd 		mib[1] = USER_POSIX2_SW_DEV;
    279   1.1       cgd 		goto yesno;
    280   1.1       cgd 	case _SC_2_UPE:
    281   1.1       cgd 		mib[0] = CTL_USER;
    282   1.1       cgd 		mib[1] = USER_POSIX2_UPE;
    283   1.8    kleink 		goto yesno;
    284   1.8    kleink 
    285   1.8    kleink /* XPG 4.2 */
    286   1.9    kleink 	case _SC_IOV_MAX:
    287   1.9    kleink 		mib[0] = CTL_KERN;
    288   1.9    kleink 		mib[1] = KERN_IOV_MAX;
    289   1.9    kleink 		break;
    290   1.8    kleink 	case _SC_XOPEN_SHM:
    291   1.8    kleink 		mib[0] = CTL_KERN;
    292  1.22  christos 		mib[1] = KERN_SYSVIPC;
    293  1.22  christos 		mib[2] = KERN_SYSVIPC_SHM;
    294  1.23     rmind 		mib_len = 3;
    295  1.23     rmind 		goto yesno;
    296  1.17    kleink 
    297  1.17    kleink /* 1003.1-2001, XSI Option Group */
    298  1.23     rmind 	case _SC_AIO_LISTIO_MAX:
    299  1.23     rmind 		if (sysctlgetmibinfo("kern.aio_listio_max", &mib[0], &mib_len,
    300  1.23     rmind 		    NULL, NULL, NULL, SYSCTL_VERSION))
    301  1.23     rmind 			return -1;
    302  1.45  riastrad 		break;
    303  1.23     rmind 	case _SC_AIO_MAX:
    304  1.23     rmind 		if (sysctlgetmibinfo("kern.aio_max", &mib[0], &mib_len,
    305  1.23     rmind 		    NULL, NULL, NULL, SYSCTL_VERSION))
    306  1.23     rmind 			return -1;
    307  1.45  riastrad 		break;
    308  1.23     rmind 	case _SC_ASYNCHRONOUS_IO:
    309  1.23     rmind 		if (sysctlgetmibinfo("kern.posix_aio", &mib[0], &mib_len,
    310  1.23     rmind 		    NULL, NULL, NULL, SYSCTL_VERSION))
    311  1.23     rmind 			return -1;
    312  1.23     rmind 		goto yesno;
    313  1.24     rmind 	case _SC_MESSAGE_PASSING:
    314  1.24     rmind 		if (sysctlgetmibinfo("kern.posix_msg", &mib[0], &mib_len,
    315  1.24     rmind 		    NULL, NULL, NULL, SYSCTL_VERSION))
    316  1.24     rmind 			return -1;
    317  1.24     rmind 		goto yesno;
    318  1.24     rmind 	case _SC_MQ_OPEN_MAX:
    319  1.29     njoly 		if (sysctlgetmibinfo("kern.mqueue.mq_open_max", &mib[0],
    320  1.29     njoly 		    &mib_len, NULL, NULL, NULL, SYSCTL_VERSION))
    321  1.24     rmind 			return -1;
    322  1.45  riastrad 		break;
    323  1.24     rmind 	case _SC_MQ_PRIO_MAX:
    324  1.29     njoly 		if (sysctlgetmibinfo("kern.mqueue.mq_prio_max", &mib[0],
    325  1.29     njoly 		    &mib_len, NULL, NULL, NULL, SYSCTL_VERSION))
    326  1.24     rmind 			return -1;
    327  1.45  riastrad 		break;
    328  1.26     rmind 	case _SC_PRIORITY_SCHEDULING:
    329  1.26     rmind 		if (sysctlgetmibinfo("kern.posix_sched", &mib[0], &mib_len,
    330  1.26     rmind 		    NULL, NULL, NULL, SYSCTL_VERSION))
    331  1.26     rmind 			return -1;
    332  1.26     rmind 		goto yesno;
    333  1.17    kleink 	case _SC_ATEXIT_MAX:
    334  1.17    kleink 		mib[0] = CTL_USER;
    335  1.17    kleink 		mib[1] = USER_ATEXIT_MAX;
    336  1.17    kleink 		break;
    337  1.17    kleink 
    338  1.20     lukem /* 1003.1-2001, TSF */
    339  1.20     lukem 	case _SC_GETGR_R_SIZE_MAX:
    340  1.20     lukem 		return _GETGR_R_SIZE_MAX;
    341  1.20     lukem 	case _SC_GETPW_R_SIZE_MAX:
    342  1.20     lukem 		return _GETPW_R_SIZE_MAX;
    343  1.20     lukem 
    344  1.33      matt /* Unsorted */
    345  1.42      maya 	case _SC_RTSIG_MAX:
    346  1.42      maya 		return SIGRTMAX - SIGRTMIN;
    347  1.33      matt 	case _SC_HOST_NAME_MAX:
    348  1.33      matt 		return MAXHOSTNAMELEN;
    349  1.33      matt 	case _SC_PASS_MAX:
    350  1.33      matt 		return _PASSWORD_LEN;
    351  1.33      matt 	case _SC_REGEXP:
    352  1.33      matt 		return _POSIX_REGEXP;
    353  1.36     rmind 	case _SC_SHARED_MEMORY_OBJECTS:
    354  1.36     rmind 		return _POSIX_SHARED_MEMORY_OBJECTS;
    355  1.33      matt 	case _SC_SHELL:
    356  1.33      matt 		return _POSIX_SHELL;
    357  1.34    martin 	case _SC_SPAWN:
    358  1.34    martin 		return _POSIX_SPAWN;
    359  1.33      matt 	case _SC_SYMLOOP_MAX:
    360  1.33      matt 		return MAXSYMLINKS;
    361  1.33      matt 
    362  1.23     rmind yesno:		if (sysctl(mib, mib_len, &value, &len, NULL, 0) == -1)
    363  1.45  riastrad 			return -1;
    364   1.1       cgd 		if (value == 0)
    365  1.45  riastrad 			return -1;
    366  1.45  riastrad 		return value;
    367  1.25        ad 
    368  1.25        ad /* Extensions */
    369  1.25        ad 	case _SC_NPROCESSORS_CONF:
    370  1.25        ad 		mib[0] = CTL_HW;
    371  1.25        ad 		mib[1] = HW_NCPU;
    372  1.25        ad 		break;
    373  1.25        ad 	case _SC_NPROCESSORS_ONLN:
    374  1.25        ad 		mib[0] = CTL_HW;
    375  1.25        ad 		mib[1] = HW_NCPUONLINE;
    376  1.25        ad 		break;
    377  1.25        ad 
    378  1.35  christos /* Linux/Solaris */
    379  1.35  christos 	case _SC_PHYS_PAGES:
    380  1.35  christos 		len = sizeof(mem);
    381  1.35  christos 		mib[0] = CTL_HW;
    382  1.35  christos 		mib[1] = HW_PHYSMEM64;
    383  1.45  riastrad 		return (sysctl(mib, 2, &mem, &len, NULL, 0) == -1 ? -1
    384  1.45  riastrad 		    : (long)(mem / _getpagesize()));
    385  1.35  christos 
    386  1.44    simonb 	case _SC_AVPHYS_PAGES:
    387  1.44    simonb 		len = sizeof(uvmexp);
    388  1.44    simonb 		mib[0] = CTL_VM;
    389  1.44    simonb 		mib[1] = VM_UVMEXP2;
    390  1.45  riastrad 		return (sysctl(mib, 2, &uvmexp, &len, NULL, 0) == -1 ? -1
    391  1.45  riastrad 		    : (long)(uvmexp.free));
    392  1.44    simonb 
    393  1.26     rmind /* Native */
    394  1.26     rmind 	case _SC_SCHED_RT_TS:
    395  1.27     rmind 		if (sysctlgetmibinfo("kern.sched.rtts", &mib[0], &mib_len,
    396  1.45  riastrad 		    NULL, NULL, NULL, SYSCTL_VERSION))
    397  1.45  riastrad 			return -1;
    398  1.26     rmind 		break;
    399  1.26     rmind 	case _SC_SCHED_PRI_MIN:
    400  1.26     rmind 		if (sysctlgetmibinfo("kern.sched.pri_min", &mib[0], &mib_len,
    401  1.26     rmind 		    NULL, NULL, NULL, SYSCTL_VERSION))
    402  1.26     rmind 			return -1;
    403  1.26     rmind 		break;
    404  1.26     rmind 	case _SC_SCHED_PRI_MAX:
    405  1.26     rmind 		if (sysctlgetmibinfo("kern.sched.pri_max", &mib[0], &mib_len,
    406  1.26     rmind 		    NULL, NULL, NULL, SYSCTL_VERSION))
    407  1.26     rmind 			return -1;
    408  1.26     rmind 		break;
    409  1.30        ad 	case _SC_THREAD_DESTRUCTOR_ITERATIONS:
    410  1.30        ad 		return _POSIX_THREAD_DESTRUCTOR_ITERATIONS;
    411  1.30        ad 	case _SC_THREAD_KEYS_MAX:
    412  1.30        ad 		return _POSIX_THREAD_KEYS_MAX;
    413  1.30        ad 	case _SC_THREAD_STACK_MIN:
    414  1.30        ad 		return _getpagesize();
    415  1.30        ad 	case _SC_THREAD_THREADS_MAX:
    416  1.30        ad 		if (sysctlgetmibinfo("kern.maxproc", &mib[0], &mib_len,
    417  1.30        ad 		    NULL, NULL, NULL, SYSCTL_VERSION))	/* XXX */
    418  1.30        ad 			return -1;
    419  1.30        ad 		goto yesno;
    420  1.30        ad 	case _SC_THREAD_ATTR_STACKADDR:
    421  1.30        ad 		return _POSIX_THREAD_ATTR_STACKADDR;
    422  1.30        ad 	case _SC_THREAD_ATTR_STACKSIZE:
    423  1.30        ad 		return _POSIX_THREAD_ATTR_STACKSIZE;
    424  1.30        ad 	case _SC_THREAD_SAFE_FUNCTIONS:
    425  1.30        ad 		return _POSIX_THREAD_SAFE_FUNCTIONS;
    426  1.40  christos 	case _SC_THREAD_PRIO_PROTECT:
    427  1.40  christos 		return _POSIX_THREAD_PRIO_PROTECT;
    428  1.30        ad 	case _SC_THREAD_PRIORITY_SCHEDULING:
    429  1.30        ad 	case _SC_THREAD_PRIO_INHERIT:
    430  1.30        ad 	case _SC_THREAD_PROCESS_SHARED:
    431  1.31        ad 		return -1;
    432  1.32        ad 	case _SC_TTY_NAME_MAX:
    433  1.32        ad 		return pathconf(_PATH_DEV, _PC_NAME_MAX);
    434  1.37  christos 	case _SC_TIMER_MAX:
    435  1.37  christos 		return _POSIX_TIMER_MAX;
    436  1.38  christos 	case _SC_SEM_NSEMS_MAX:
    437  1.43     joerg 		return LONG_MAX;
    438  1.39  christos 	case _SC_CPUTIME:
    439  1.39  christos 		return _POSIX_CPUTIME;
    440  1.39  christos 	case _SC_THREAD_CPUTIME:
    441  1.39  christos 		return _POSIX_THREAD_CPUTIME;
    442  1.39  christos 	case _SC_DELAYTIMER_MAX:
    443  1.39  christos 		return _POSIX_DELAYTIMER_MAX;
    444  1.41  christos 	case _SC_SIGQUEUE_MAX:
    445  1.41  christos 		return _POSIX_SIGQUEUE_MAX;
    446  1.41  christos 	case _SC_REALTIME_SIGNALS:
    447  1.41  christos 		return 200112L;
    448   1.1       cgd 	default:
    449   1.1       cgd 		errno = EINVAL;
    450  1.45  riastrad 		return -1;
    451   1.1       cgd 	}
    452  1.45  riastrad 	return (sysctl(mib, mib_len, &value, &len, NULL, 0) == -1 ? -1
    453  1.45  riastrad 	    : value);
    454   1.1       cgd }
    455