1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Sean Eric Fagan of Cygnus Support. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 #if defined(LIBC_SCCS) && !defined(lint) 36 static char sccsid[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94"; 37 #endif /* LIBC_SCCS and not lint */ 38 #include <sys/cdefs.h> 39 __FBSDID("$FreeBSD$"); 40 41 #include "namespace.h" 42 #include <sys/param.h> 43 #include <sys/time.h> 44 #include <sys/sysctl.h> 45 #include <sys/resource.h> 46 #include <sys/socket.h> 47 48 #include <elf.h> 49 #include <errno.h> 50 #include <limits.h> 51 #include <paths.h> 52 #include <pthread.h> /* we just need the limits */ 53 #include <semaphore.h> 54 #include <time.h> 55 #include <unistd.h> 56 #include "un-namespace.h" 57 58 #include "../stdlib/atexit.h" 59 #include "tzfile.h" /* from ../../../contrib/tzcode/stdtime */ 60 #include "libc_private.h" 61 62 #define _PATH_ZONEINFO TZDIR /* from tzfile.h */ 63 64 /* 65 * sysconf -- 66 * get configurable system variables. 67 * 68 * XXX 69 * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values 70 * not change during the lifetime of the calling process. This would seem 71 * to require that any change to system limits kill all running processes. 72 * A workaround might be to cache the values when they are first retrieved 73 * and then simply return the cached value on subsequent calls. This is 74 * less useful than returning up-to-date values, however. 75 */ 76 long 77 sysconf(int name) 78 { 79 struct rlimit rl; 80 size_t len; 81 int mib[2], sverrno, value; 82 long lvalue, defaultresult; 83 const char *path; 84 85 defaultresult = -1; 86 87 switch (name) { 88 case _SC_ARG_MAX: 89 mib[0] = CTL_KERN; 90 mib[1] = KERN_ARGMAX; 91 break; 92 case _SC_CHILD_MAX: 93 if (getrlimit(RLIMIT_NPROC, &rl) != 0) 94 return (-1); 95 if (rl.rlim_cur == RLIM_INFINITY) 96 return (-1); 97 if (rl.rlim_cur > LONG_MAX) { 98 errno = EOVERFLOW; 99 return (-1); 100 } 101 return ((long)rl.rlim_cur); 102 case _SC_CLK_TCK: 103 return (CLK_TCK); 104 case _SC_NGROUPS_MAX: 105 mib[0] = CTL_KERN; 106 mib[1] = KERN_NGROUPS; 107 break; 108 case _SC_OPEN_MAX: 109 if (getrlimit(RLIMIT_NOFILE, &rl) != 0) 110 return (-1); 111 if (rl.rlim_cur == RLIM_INFINITY) 112 return (-1); 113 if (rl.rlim_cur > LONG_MAX) { 114 errno = EOVERFLOW; 115 return (-1); 116 } 117 return ((long)rl.rlim_cur); 118 case _SC_STREAM_MAX: 119 if (getrlimit(RLIMIT_NOFILE, &rl) != 0) 120 return (-1); 121 if (rl.rlim_cur == RLIM_INFINITY) 122 return (-1); 123 if (rl.rlim_cur > LONG_MAX) { 124 errno = EOVERFLOW; 125 return (-1); 126 } 127 /* 128 * struct __sFILE currently has a limitation that 129 * file descriptors must fit in a signed short. 130 * This doesn't precisely capture the letter of POSIX 131 * but approximates the spirit. 132 */ 133 if (rl.rlim_cur > SHRT_MAX) 134 return (SHRT_MAX); 135 136 return ((long)rl.rlim_cur); 137 case _SC_JOB_CONTROL: 138 return (_POSIX_JOB_CONTROL); 139 case _SC_SAVED_IDS: 140 /* XXX - must be 1 */ 141 mib[0] = CTL_KERN; 142 mib[1] = KERN_SAVED_IDS; 143 goto yesno; 144 case _SC_VERSION: 145 mib[0] = CTL_KERN; 146 mib[1] = KERN_POSIX1; 147 break; 148 case _SC_BC_BASE_MAX: 149 return (BC_BASE_MAX); 150 case _SC_BC_DIM_MAX: 151 return (BC_DIM_MAX); 152 case _SC_BC_SCALE_MAX: 153 return (BC_SCALE_MAX); 154 case _SC_BC_STRING_MAX: 155 return (BC_STRING_MAX); 156 case _SC_COLL_WEIGHTS_MAX: 157 return (COLL_WEIGHTS_MAX); 158 case _SC_EXPR_NEST_MAX: 159 return (EXPR_NEST_MAX); 160 case _SC_LINE_MAX: 161 return (LINE_MAX); 162 case _SC_RE_DUP_MAX: 163 return (RE_DUP_MAX); 164 case _SC_2_VERSION: 165 /* 166 * This is something of a lie, but it would be silly at 167 * this point to try to deduce this from the contents 168 * of the filesystem. 169 */ 170 return (_POSIX2_VERSION); 171 case _SC_2_C_BIND: 172 return (_POSIX2_C_BIND); 173 case _SC_2_C_DEV: 174 return (_POSIX2_C_DEV); 175 case _SC_2_CHAR_TERM: 176 return (_POSIX2_CHAR_TERM); 177 case _SC_2_FORT_DEV: 178 return (_POSIX2_FORT_DEV); 179 case _SC_2_FORT_RUN: 180 return (_POSIX2_FORT_RUN); 181 case _SC_2_LOCALEDEF: 182 return (_POSIX2_LOCALEDEF); 183 case _SC_2_SW_DEV: 184 return (_POSIX2_SW_DEV); 185 case _SC_2_UPE: 186 return (_POSIX2_UPE); 187 case _SC_TZNAME_MAX: 188 path = _PATH_ZONEINFO; 189 do_NAME_MAX: 190 sverrno = errno; 191 errno = 0; 192 lvalue = pathconf(path, _PC_NAME_MAX); 193 if (lvalue == -1 && errno != 0) 194 return (-1); 195 errno = sverrno; 196 return (lvalue); 197 198 case _SC_ASYNCHRONOUS_IO: 199 #if _POSIX_ASYNCHRONOUS_IO == 0 200 mib[0] = CTL_P1003_1B; 201 mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO; 202 break; 203 #else 204 return (_POSIX_ASYNCHRONOUS_IO); 205 #endif 206 case _SC_MAPPED_FILES: 207 return (_POSIX_MAPPED_FILES); 208 case _SC_MEMLOCK: 209 return (_POSIX_MEMLOCK); 210 case _SC_MEMLOCK_RANGE: 211 return (_POSIX_MEMLOCK_RANGE); 212 case _SC_MEMORY_PROTECTION: 213 return (_POSIX_MEMORY_PROTECTION); 214 case _SC_MESSAGE_PASSING: 215 #if _POSIX_MESSAGE_PASSING == 0 216 mib[0] = CTL_P1003_1B; 217 mib[1] = CTL_P1003_1B_MESSAGE_PASSING; 218 goto yesno; 219 #else 220 return (_POSIX_MESSAGE_PASSING); 221 #endif 222 case _SC_PRIORITIZED_IO: 223 #if _POSIX_PRIORITIZED_IO == 0 224 mib[0] = CTL_P1003_1B; 225 mib[1] = CTL_P1003_1B_PRIORITIZED_IO; 226 goto yesno; 227 #else 228 return (_POSIX_PRIORITIZED_IO); 229 #endif 230 case _SC_PRIORITY_SCHEDULING: 231 #if _POSIX_PRIORITY_SCHEDULING == 0 232 mib[0] = CTL_P1003_1B; 233 mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING; 234 goto yesno; 235 #else 236 return (_POSIX_PRIORITY_SCHEDULING); 237 #endif 238 case _SC_REALTIME_SIGNALS: 239 #if _POSIX_REALTIME_SIGNALS == 0 240 mib[0] = CTL_P1003_1B; 241 mib[1] = CTL_P1003_1B_REALTIME_SIGNALS; 242 goto yesno; 243 #else 244 return (_POSIX_REALTIME_SIGNALS); 245 #endif 246 case _SC_SEMAPHORES: 247 #if _POSIX_SEMAPHORES == 0 248 mib[0] = CTL_P1003_1B; 249 mib[1] = CTL_P1003_1B_SEMAPHORES; 250 goto yesno; 251 #else 252 return (_POSIX_SEMAPHORES); 253 #endif 254 case _SC_FSYNC: 255 return (_POSIX_FSYNC); 256 257 case _SC_SHARED_MEMORY_OBJECTS: 258 return (_POSIX_SHARED_MEMORY_OBJECTS); 259 case _SC_SYNCHRONIZED_IO: 260 #if _POSIX_SYNCHRONIZED_IO == 0 261 mib[0] = CTL_P1003_1B; 262 mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO; 263 goto yesno; 264 #else 265 return (_POSIX_SYNCHRONIZED_IO); 266 #endif 267 case _SC_TIMERS: 268 #if _POSIX_TIMERS == 0 269 mib[0] = CTL_P1003_1B; 270 mib[1] = CTL_P1003_1B_TIMERS; 271 goto yesno; 272 #else 273 return (_POSIX_TIMERS); 274 #endif 275 case _SC_AIO_LISTIO_MAX: 276 mib[0] = CTL_P1003_1B; 277 mib[1] = CTL_P1003_1B_AIO_LISTIO_MAX; 278 break; 279 case _SC_AIO_MAX: 280 mib[0] = CTL_P1003_1B; 281 mib[1] = CTL_P1003_1B_AIO_MAX; 282 break; 283 case _SC_AIO_PRIO_DELTA_MAX: 284 mib[0] = CTL_P1003_1B; 285 mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX; 286 break; 287 case _SC_DELAYTIMER_MAX: 288 mib[0] = CTL_P1003_1B; 289 mib[1] = CTL_P1003_1B_DELAYTIMER_MAX; 290 goto yesno; 291 case _SC_MQ_OPEN_MAX: 292 mib[0] = CTL_P1003_1B; 293 mib[1] = CTL_P1003_1B_MQ_OPEN_MAX; 294 goto yesno; 295 case _SC_PAGESIZE: 296 defaultresult = getpagesize(); 297 mib[0] = CTL_P1003_1B; 298 mib[1] = CTL_P1003_1B_PAGESIZE; 299 goto yesno; 300 case _SC_RTSIG_MAX: 301 mib[0] = CTL_P1003_1B; 302 mib[1] = CTL_P1003_1B_RTSIG_MAX; 303 goto yesno; 304 case _SC_SEM_NSEMS_MAX: 305 return (-1); 306 case _SC_SEM_VALUE_MAX: 307 return (SEM_VALUE_MAX); 308 case _SC_SIGQUEUE_MAX: 309 mib[0] = CTL_P1003_1B; 310 mib[1] = CTL_P1003_1B_SIGQUEUE_MAX; 311 goto yesno; 312 case _SC_TIMER_MAX: 313 mib[0] = CTL_P1003_1B; 314 mib[1] = CTL_P1003_1B_TIMER_MAX; 315 yesno: 316 len = sizeof(value); 317 if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) 318 return (-1); 319 if (value == 0) 320 return (defaultresult); 321 return ((long)value); 322 323 case _SC_2_PBS: 324 case _SC_2_PBS_ACCOUNTING: 325 case _SC_2_PBS_CHECKPOINT: 326 case _SC_2_PBS_LOCATE: 327 case _SC_2_PBS_MESSAGE: 328 case _SC_2_PBS_TRACK: 329 #if _POSIX2_PBS == 0 330 #error "don't know how to determine _SC_2_PBS" 331 /* 332 * This probably requires digging through the filesystem 333 * to see if the appropriate package has been installed. 334 * Since we don't currently support this option at all, 335 * it's not worth the effort to write the code now. 336 * Figuring out which of the sub-options are supported 337 * would be even more difficult, so it's probably easier 338 * to always say ``no''. 339 */ 340 #else 341 return (_POSIX2_PBS); 342 #endif 343 case _SC_ADVISORY_INFO: 344 #if _POSIX_ADVISORY_INFO == 0 345 #error "_POSIX_ADVISORY_INFO" 346 #else 347 return (_POSIX_ADVISORY_INFO); 348 #endif 349 case _SC_BARRIERS: 350 #if _POSIX_BARRIERS == 0 351 #error "_POSIX_BARRIERS" 352 #else 353 return (_POSIX_BARRIERS); 354 #endif 355 case _SC_CLOCK_SELECTION: 356 #if _POSIX_CLOCK_SELECTION == 0 357 #error "_POSIX_CLOCK_SELECTION" 358 #else 359 return (_POSIX_CLOCK_SELECTION); 360 #endif 361 case _SC_CPUTIME: 362 return (_POSIX_CPUTIME); 363 #ifdef notdef 364 case _SC_FILE_LOCKING: 365 /* 366 * XXX - The standard doesn't tell us how to define 367 * _POSIX_FILE_LOCKING, so we can't answer this one. 368 */ 369 #endif 370 371 /* 372 * SUSv4tc1 says the following about _SC_GETGR_R_SIZE_MAX and 373 * _SC_GETPW_R_SIZE_MAX: 374 * Note that sysconf(_SC_GETGR_R_SIZE_MAX) may return -1 if 375 * there is no hard limit on the size of the buffer needed to 376 * store all the groups returned. 377 */ 378 case _SC_GETGR_R_SIZE_MAX: 379 case _SC_GETPW_R_SIZE_MAX: 380 return (-1); 381 case _SC_HOST_NAME_MAX: 382 return (MAXHOSTNAMELEN - 1); /* does not include \0 */ 383 case _SC_LOGIN_NAME_MAX: 384 return (MAXLOGNAME); 385 case _SC_MONOTONIC_CLOCK: 386 #if _POSIX_MONOTONIC_CLOCK == 0 387 #error "_POSIX_MONOTONIC_CLOCK" 388 #else 389 return (_POSIX_MONOTONIC_CLOCK); 390 #endif 391 #if _POSIX_MESSAGE_PASSING > -1 392 case _SC_MQ_PRIO_MAX: 393 return (MQ_PRIO_MAX); 394 #endif 395 case _SC_READER_WRITER_LOCKS: 396 return (_POSIX_READER_WRITER_LOCKS); 397 case _SC_REGEXP: 398 return (_POSIX_REGEXP); 399 case _SC_SHELL: 400 return (_POSIX_SHELL); 401 case _SC_SPAWN: 402 return (_POSIX_SPAWN); 403 case _SC_SPIN_LOCKS: 404 return (_POSIX_SPIN_LOCKS); 405 case _SC_SPORADIC_SERVER: 406 #if _POSIX_SPORADIC_SERVER == 0 407 #error "_POSIX_SPORADIC_SERVER" 408 #else 409 return (_POSIX_SPORADIC_SERVER); 410 #endif 411 case _SC_THREAD_ATTR_STACKADDR: 412 return (_POSIX_THREAD_ATTR_STACKADDR); 413 case _SC_THREAD_ATTR_STACKSIZE: 414 return (_POSIX_THREAD_ATTR_STACKSIZE); 415 case _SC_THREAD_CPUTIME: 416 return (_POSIX_THREAD_CPUTIME); 417 case _SC_THREAD_DESTRUCTOR_ITERATIONS: 418 return (PTHREAD_DESTRUCTOR_ITERATIONS); 419 case _SC_THREAD_KEYS_MAX: 420 return (PTHREAD_KEYS_MAX); 421 case _SC_THREAD_PRIO_INHERIT: 422 return (_POSIX_THREAD_PRIO_INHERIT); 423 case _SC_THREAD_PRIO_PROTECT: 424 return (_POSIX_THREAD_PRIO_PROTECT); 425 case _SC_THREAD_PRIORITY_SCHEDULING: 426 return (_POSIX_THREAD_PRIORITY_SCHEDULING); 427 case _SC_THREAD_PROCESS_SHARED: 428 return (_POSIX_THREAD_PROCESS_SHARED); 429 case _SC_THREAD_SAFE_FUNCTIONS: 430 return (_POSIX_THREAD_SAFE_FUNCTIONS); 431 case _SC_THREAD_STACK_MIN: 432 return (PTHREAD_STACK_MIN); 433 case _SC_THREAD_THREADS_MAX: 434 return (PTHREAD_THREADS_MAX); /* XXX wrong type! */ 435 case _SC_TIMEOUTS: 436 return (_POSIX_TIMEOUTS); 437 case _SC_THREADS: 438 return (_POSIX_THREADS); 439 case _SC_TRACE: 440 #if _POSIX_TRACE == 0 441 #error "_POSIX_TRACE" 442 /* While you're implementing this, also do the ones below. */ 443 #else 444 return (_POSIX_TRACE); 445 #endif 446 #if _POSIX_TRACE > -1 447 case _SC_TRACE_EVENT_FILTER: 448 return (_POSIX_TRACE_EVENT_FILTER); 449 case _SC_TRACE_INHERIT: 450 return (_POSIX_TRACE_INHERIT); 451 case _SC_TRACE_LOG: 452 return (_POSIX_TRACE_LOG); 453 #endif 454 case _SC_TTY_NAME_MAX: 455 path = _PATH_DEV; 456 goto do_NAME_MAX; 457 case _SC_TYPED_MEMORY_OBJECTS: 458 #if _POSIX_TYPED_MEMORY_OBJECTS == 0 459 #error "_POSIX_TYPED_MEMORY_OBJECTS" 460 #else 461 return (_POSIX_TYPED_MEMORY_OBJECTS); 462 #endif 463 case _SC_V6_ILP32_OFF32: 464 #if _V6_ILP32_OFF32 == 0 465 if (sizeof(int) * CHAR_BIT == 32 && 466 sizeof(int) == sizeof(long) && 467 sizeof(long) == sizeof(void *) && 468 sizeof(void *) == sizeof(off_t)) 469 return 1; 470 else 471 return -1; 472 #else 473 return (_V6_ILP32_OFF32); 474 #endif 475 case _SC_V6_ILP32_OFFBIG: 476 #if _V6_ILP32_OFFBIG == 0 477 if (sizeof(int) * CHAR_BIT == 32 && 478 sizeof(int) == sizeof(long) && 479 sizeof(long) == sizeof(void *) && 480 sizeof(off_t) * CHAR_BIT >= 64) 481 return 1; 482 else 483 return -1; 484 #else 485 return (_V6_ILP32_OFFBIG); 486 #endif 487 case _SC_V6_LP64_OFF64: 488 #if _V6_LP64_OFF64 == 0 489 if (sizeof(int) * CHAR_BIT == 32 && 490 sizeof(long) * CHAR_BIT == 64 && 491 sizeof(long) == sizeof(void *) && 492 sizeof(void *) == sizeof(off_t)) 493 return 1; 494 else 495 return -1; 496 #else 497 return (_V6_LP64_OFF64); 498 #endif 499 case _SC_V6_LPBIG_OFFBIG: 500 #if _V6_LPBIG_OFFBIG == 0 501 if (sizeof(int) * CHAR_BIT >= 32 && 502 sizeof(long) * CHAR_BIT >= 64 && 503 sizeof(void *) * CHAR_BIT >= 64 && 504 sizeof(off_t) * CHAR_BIT >= 64) 505 return 1; 506 else 507 return -1; 508 #else 509 return (_V6_LPBIG_OFFBIG); 510 #endif 511 case _SC_ATEXIT_MAX: 512 return (ATEXIT_SIZE); 513 case _SC_IOV_MAX: 514 mib[0] = CTL_KERN; 515 mib[1] = KERN_IOV_MAX; 516 break; 517 case _SC_XOPEN_CRYPT: 518 return (_XOPEN_CRYPT); 519 case _SC_XOPEN_ENH_I18N: 520 return (_XOPEN_ENH_I18N); 521 case _SC_XOPEN_LEGACY: 522 return (_XOPEN_LEGACY); 523 case _SC_XOPEN_REALTIME: 524 #if _XOPEN_REALTIME == 0 525 sverrno = errno; 526 value = sysconf(_SC_ASYNCHRONOUS_IO) > 0 && 527 sysconf(_SC_MEMLOCK) > 0 && 528 sysconf(_SC_MEMLOCK_RANGE) > 0 && 529 sysconf(_SC_MESSAGE_PASSING) > 0 && 530 sysconf(_SC_PRIORITY_SCHEDULING) > 0 && 531 sysconf(_SC_REALTIME_SIGNALS) > 0 && 532 sysconf(_SC_SEMAPHORES) > 0 && 533 sysconf(_SC_SHARED_MEMORY_OBJECTS) > 0 && 534 sysconf(_SC_SYNCHRONIZED_IO) > 0 && 535 sysconf(_SC_TIMERS) > 0; 536 errno = sverrno; 537 if (value) 538 return (200112L); 539 else 540 return (-1); 541 #else 542 return (_XOPEN_REALTIME); 543 #endif 544 case _SC_XOPEN_REALTIME_THREADS: 545 #if _XOPEN_REALTIME_THREADS == 0 546 #error "_XOPEN_REALTIME_THREADS" 547 #else 548 return (_XOPEN_REALTIME_THREADS); 549 #endif 550 case _SC_XOPEN_SHM: 551 len = sizeof(lvalue); 552 sverrno = errno; 553 if (sysctlbyname("kern.ipc.shmmin", &lvalue, &len, NULL, 554 0) == -1) { 555 errno = sverrno; 556 return (-1); 557 } 558 errno = sverrno; 559 return (1); 560 case _SC_XOPEN_STREAMS: 561 return (_XOPEN_STREAMS); 562 case _SC_XOPEN_UNIX: 563 return (_XOPEN_UNIX); 564 #ifdef _XOPEN_VERSION 565 case _SC_XOPEN_VERSION: 566 return (_XOPEN_VERSION); 567 #endif 568 #ifdef _XOPEN_XCU_VERSION 569 case _SC_XOPEN_XCU_VERSION: 570 return (_XOPEN_XCU_VERSION); 571 #endif 572 case _SC_SYMLOOP_MAX: 573 return (MAXSYMLINKS); 574 case _SC_RAW_SOCKETS: 575 return (_POSIX_RAW_SOCKETS); 576 case _SC_IPV6: 577 #if _POSIX_IPV6 == 0 578 sverrno = errno; 579 value = _socket(PF_INET6, SOCK_DGRAM, 0); 580 errno = sverrno; 581 if (value >= 0) { 582 _close(value); 583 return (200112L); 584 } else 585 return (0); 586 #else 587 return (_POSIX_IPV6); 588 #endif 589 590 case _SC_NPROCESSORS_CONF: 591 case _SC_NPROCESSORS_ONLN: 592 if (_elf_aux_info(AT_NCPUS, &value, sizeof(value)) == 0) 593 return ((long)value); 594 mib[0] = CTL_HW; 595 mib[1] = HW_NCPU; 596 break; 597 598 #ifdef _SC_PHYS_PAGES 599 case _SC_PHYS_PAGES: 600 len = sizeof(lvalue); 601 if (sysctlbyname("hw.availpages", &lvalue, &len, NULL, 0) == -1) 602 return (-1); 603 return (lvalue); 604 #endif 605 606 #ifdef _SC_CPUSET_SIZE 607 case _SC_CPUSET_SIZE: 608 len = sizeof(value); 609 if (sysctlbyname("kern.sched.cpusetsize", &value, &len, NULL, 610 0) == -1) 611 return (-1); 612 return ((long)value); 613 #endif 614 615 default: 616 errno = EINVAL; 617 return (-1); 618 } 619 len = sizeof(value); 620 if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) 621 value = -1; 622 return ((long)value); 623 } 624