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 * 3. 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 "namespace.h" 40 #include <sys/param.h> 41 #include <sys/time.h> 42 #include <sys/sysctl.h> 43 #include <sys/resource.h> 44 #include <sys/socket.h> 45 46 #include <elf.h> 47 #include <errno.h> 48 #include <limits.h> 49 #include <paths.h> 50 #include <pthread.h> /* we just need the limits */ 51 #include <semaphore.h> 52 #include <time.h> 53 #include <unistd.h> 54 #include "un-namespace.h" 55 56 #include "../stdlib/atexit.h" 57 #include "tzfile.h" /* from ../../../contrib/tzcode/stdtime */ 58 #include "libc_private.h" 59 60 #define _PATH_ZONEINFO TZDIR /* from tzfile.h */ 61 62 /* 63 * sysconf -- 64 * get configurable system variables. 65 * 66 * XXX 67 * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values 68 * not change during the lifetime of the calling process. This would seem 69 * to require that any change to system limits kill all running processes. 70 * A workaround might be to cache the values when they are first retrieved 71 * and then simply return the cached value on subsequent calls. This is 72 * less useful than returning up-to-date values, however. 73 */ 74 long 75 sysconf(int name) 76 { 77 struct rlimit rl; 78 size_t len; 79 int mib[2], sverrno, value; 80 long lvalue, defaultresult; 81 const char *path; 82 83 defaultresult = -1; 84 85 switch (name) { 86 case _SC_ARG_MAX: 87 mib[0] = CTL_KERN; 88 mib[1] = KERN_ARGMAX; 89 break; 90 case _SC_CHILD_MAX: 91 if (getrlimit(RLIMIT_NPROC, &rl) != 0) 92 return (-1); 93 if (rl.rlim_cur == RLIM_INFINITY) 94 return (-1); 95 if (rl.rlim_cur > LONG_MAX) { 96 errno = EOVERFLOW; 97 return (-1); 98 } 99 return ((long)rl.rlim_cur); 100 case _SC_CLK_TCK: 101 return (CLK_TCK); 102 case _SC_NGROUPS_MAX: 103 mib[0] = CTL_KERN; 104 mib[1] = KERN_NGROUPS; 105 break; 106 case _SC_OPEN_MAX: 107 if (getrlimit(RLIMIT_NOFILE, &rl) != 0) 108 return (-1); 109 if (rl.rlim_cur == RLIM_INFINITY) 110 return (-1); 111 if (rl.rlim_cur > LONG_MAX) { 112 errno = EOVERFLOW; 113 return (-1); 114 } 115 return ((long)rl.rlim_cur); 116 case _SC_STREAM_MAX: 117 if (getrlimit(RLIMIT_NOFILE, &rl) != 0) 118 return (-1); 119 if (rl.rlim_cur == RLIM_INFINITY) 120 return (-1); 121 if (rl.rlim_cur > LONG_MAX) { 122 errno = EOVERFLOW; 123 return (-1); 124 } 125 /* 126 * struct __sFILE currently has a limitation that 127 * file descriptors must fit in a signed short. 128 * This doesn't precisely capture the letter of POSIX 129 * but approximates the spirit. 130 */ 131 if (rl.rlim_cur > SHRT_MAX) 132 return (SHRT_MAX); 133 134 return ((long)rl.rlim_cur); 135 case _SC_JOB_CONTROL: 136 return (_POSIX_JOB_CONTROL); 137 case _SC_SAVED_IDS: 138 /* XXX - must be 1 */ 139 mib[0] = CTL_KERN; 140 mib[1] = KERN_SAVED_IDS; 141 goto yesno; 142 case _SC_VERSION: 143 mib[0] = CTL_KERN; 144 mib[1] = KERN_POSIX1; 145 break; 146 case _SC_BC_BASE_MAX: 147 return (BC_BASE_MAX); 148 case _SC_BC_DIM_MAX: 149 return (BC_DIM_MAX); 150 case _SC_BC_SCALE_MAX: 151 return (BC_SCALE_MAX); 152 case _SC_BC_STRING_MAX: 153 return (BC_STRING_MAX); 154 case _SC_COLL_WEIGHTS_MAX: 155 return (COLL_WEIGHTS_MAX); 156 case _SC_EXPR_NEST_MAX: 157 return (EXPR_NEST_MAX); 158 case _SC_LINE_MAX: 159 return (LINE_MAX); 160 case _SC_RE_DUP_MAX: 161 return (RE_DUP_MAX); 162 case _SC_2_VERSION: 163 /* 164 * This is something of a lie, but it would be silly at 165 * this point to try to deduce this from the contents 166 * of the filesystem. 167 */ 168 return (_POSIX2_VERSION); 169 case _SC_2_C_BIND: 170 return (_POSIX2_C_BIND); 171 case _SC_2_C_DEV: 172 return (_POSIX2_C_DEV); 173 case _SC_2_CHAR_TERM: 174 return (_POSIX2_CHAR_TERM); 175 case _SC_2_FORT_DEV: 176 return (_POSIX2_FORT_DEV); 177 case _SC_2_FORT_RUN: 178 return (_POSIX2_FORT_RUN); 179 case _SC_2_LOCALEDEF: 180 return (_POSIX2_LOCALEDEF); 181 case _SC_2_SW_DEV: 182 return (_POSIX2_SW_DEV); 183 case _SC_2_UPE: 184 return (_POSIX2_UPE); 185 case _SC_TZNAME_MAX: 186 path = _PATH_ZONEINFO; 187 do_NAME_MAX: 188 sverrno = errno; 189 errno = 0; 190 lvalue = pathconf(path, _PC_NAME_MAX); 191 if (lvalue == -1 && errno != 0) 192 return (-1); 193 errno = sverrno; 194 return (lvalue); 195 196 case _SC_ASYNCHRONOUS_IO: 197 #if _POSIX_ASYNCHRONOUS_IO == 0 198 mib[0] = CTL_P1003_1B; 199 mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO; 200 break; 201 #else 202 return (_POSIX_ASYNCHRONOUS_IO); 203 #endif 204 case _SC_MAPPED_FILES: 205 return (_POSIX_MAPPED_FILES); 206 case _SC_MEMLOCK: 207 return (_POSIX_MEMLOCK); 208 case _SC_MEMLOCK_RANGE: 209 return (_POSIX_MEMLOCK_RANGE); 210 case _SC_MEMORY_PROTECTION: 211 return (_POSIX_MEMORY_PROTECTION); 212 case _SC_MESSAGE_PASSING: 213 #if _POSIX_MESSAGE_PASSING == 0 214 mib[0] = CTL_P1003_1B; 215 mib[1] = CTL_P1003_1B_MESSAGE_PASSING; 216 goto yesno; 217 #else 218 return (_POSIX_MESSAGE_PASSING); 219 #endif 220 case _SC_PRIORITIZED_IO: 221 #if _POSIX_PRIORITIZED_IO == 0 222 mib[0] = CTL_P1003_1B; 223 mib[1] = CTL_P1003_1B_PRIORITIZED_IO; 224 goto yesno; 225 #else 226 return (_POSIX_PRIORITIZED_IO); 227 #endif 228 case _SC_PRIORITY_SCHEDULING: 229 #if _POSIX_PRIORITY_SCHEDULING == 0 230 mib[0] = CTL_P1003_1B; 231 mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING; 232 goto yesno; 233 #else 234 return (_POSIX_PRIORITY_SCHEDULING); 235 #endif 236 case _SC_REALTIME_SIGNALS: 237 #if _POSIX_REALTIME_SIGNALS == 0 238 mib[0] = CTL_P1003_1B; 239 mib[1] = CTL_P1003_1B_REALTIME_SIGNALS; 240 goto yesno; 241 #else 242 return (_POSIX_REALTIME_SIGNALS); 243 #endif 244 case _SC_SEMAPHORES: 245 #if _POSIX_SEMAPHORES == 0 246 mib[0] = CTL_P1003_1B; 247 mib[1] = CTL_P1003_1B_SEMAPHORES; 248 goto yesno; 249 #else 250 return (_POSIX_SEMAPHORES); 251 #endif 252 case _SC_FSYNC: 253 return (_POSIX_FSYNC); 254 255 case _SC_SHARED_MEMORY_OBJECTS: 256 return (_POSIX_SHARED_MEMORY_OBJECTS); 257 case _SC_SYNCHRONIZED_IO: 258 #if _POSIX_SYNCHRONIZED_IO == 0 259 mib[0] = CTL_P1003_1B; 260 mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO; 261 goto yesno; 262 #else 263 return (_POSIX_SYNCHRONIZED_IO); 264 #endif 265 case _SC_TIMERS: 266 #if _POSIX_TIMERS == 0 267 mib[0] = CTL_P1003_1B; 268 mib[1] = CTL_P1003_1B_TIMERS; 269 goto yesno; 270 #else 271 return (_POSIX_TIMERS); 272 #endif 273 case _SC_AIO_LISTIO_MAX: 274 mib[0] = CTL_P1003_1B; 275 mib[1] = CTL_P1003_1B_AIO_LISTIO_MAX; 276 break; 277 case _SC_AIO_MAX: 278 mib[0] = CTL_P1003_1B; 279 mib[1] = CTL_P1003_1B_AIO_MAX; 280 break; 281 case _SC_AIO_PRIO_DELTA_MAX: 282 mib[0] = CTL_P1003_1B; 283 mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX; 284 break; 285 case _SC_DELAYTIMER_MAX: 286 mib[0] = CTL_P1003_1B; 287 mib[1] = CTL_P1003_1B_DELAYTIMER_MAX; 288 goto yesno; 289 case _SC_MQ_OPEN_MAX: 290 mib[0] = CTL_P1003_1B; 291 mib[1] = CTL_P1003_1B_MQ_OPEN_MAX; 292 goto yesno; 293 case _SC_PAGESIZE: 294 defaultresult = getpagesize(); 295 mib[0] = CTL_P1003_1B; 296 mib[1] = CTL_P1003_1B_PAGESIZE; 297 goto yesno; 298 case _SC_RTSIG_MAX: 299 mib[0] = CTL_P1003_1B; 300 mib[1] = CTL_P1003_1B_RTSIG_MAX; 301 goto yesno; 302 case _SC_SEM_NSEMS_MAX: 303 return (-1); 304 case _SC_SEM_VALUE_MAX: 305 return (SEM_VALUE_MAX); 306 case _SC_SIGQUEUE_MAX: 307 mib[0] = CTL_P1003_1B; 308 mib[1] = CTL_P1003_1B_SIGQUEUE_MAX; 309 goto yesno; 310 case _SC_TIMER_MAX: 311 mib[0] = CTL_P1003_1B; 312 mib[1] = CTL_P1003_1B_TIMER_MAX; 313 yesno: 314 len = sizeof(value); 315 if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) 316 return (-1); 317 if (value == 0) 318 return (defaultresult); 319 return ((long)value); 320 321 case _SC_2_PBS: 322 case _SC_2_PBS_ACCOUNTING: 323 case _SC_2_PBS_CHECKPOINT: 324 case _SC_2_PBS_LOCATE: 325 case _SC_2_PBS_MESSAGE: 326 case _SC_2_PBS_TRACK: 327 #if _POSIX2_PBS == 0 328 #error "don't know how to determine _SC_2_PBS" 329 /* 330 * This probably requires digging through the filesystem 331 * to see if the appropriate package has been installed. 332 * Since we don't currently support this option at all, 333 * it's not worth the effort to write the code now. 334 * Figuring out which of the sub-options are supported 335 * would be even more difficult, so it's probably easier 336 * to always say ``no''. 337 */ 338 #else 339 return (_POSIX2_PBS); 340 #endif 341 case _SC_ADVISORY_INFO: 342 #if _POSIX_ADVISORY_INFO == 0 343 #error "_POSIX_ADVISORY_INFO" 344 #else 345 return (_POSIX_ADVISORY_INFO); 346 #endif 347 case _SC_BARRIERS: 348 #if _POSIX_BARRIERS == 0 349 #error "_POSIX_BARRIERS" 350 #else 351 return (_POSIX_BARRIERS); 352 #endif 353 case _SC_CLOCK_SELECTION: 354 #if _POSIX_CLOCK_SELECTION == 0 355 #error "_POSIX_CLOCK_SELECTION" 356 #else 357 return (_POSIX_CLOCK_SELECTION); 358 #endif 359 case _SC_CPUTIME: 360 return (_POSIX_CPUTIME); 361 #ifdef notdef 362 case _SC_FILE_LOCKING: 363 /* 364 * XXX - The standard doesn't tell us how to define 365 * _POSIX_FILE_LOCKING, so we can't answer this one. 366 */ 367 #endif 368 369 /* 370 * SUSv4tc1 says the following about _SC_GETGR_R_SIZE_MAX and 371 * _SC_GETPW_R_SIZE_MAX: 372 * Note that sysconf(_SC_GETGR_R_SIZE_MAX) may return -1 if 373 * there is no hard limit on the size of the buffer needed to 374 * store all the groups returned. 375 */ 376 case _SC_GETGR_R_SIZE_MAX: 377 case _SC_GETPW_R_SIZE_MAX: 378 return (-1); 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