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