1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (c) 2013 Gary Mills 24 * 25 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29 /* Copyright (c) 1988 AT&T */ 30 /* All Rights Reserved */ 31 32 /* sysconf(3C) - returns system configuration information */ 33 34 #pragma weak _sysconf = sysconf 35 36 #include "lint.h" 37 #include <mtlib.h> 38 #include <sys/types.h> 39 #include <unistd.h> 40 #include <sys/sysconfig.h> 41 #include <limits.h> 42 #include <time.h> 43 #include <errno.h> 44 #include <nss_dbdefs.h> 45 #include <thread.h> 46 #include <xti.h> 47 #include "libc.h" 48 #include "xpg6.h" 49 50 /* from nss_common.c */ 51 extern size_t _nss_get_bufsizes(int); 52 53 long 54 sysconf(int name) 55 { 56 static int _pagesize = 0; 57 static int _hz = 0; 58 static pid_t _maxpid = 0; 59 static int _stackprot = 0; 60 static int _ngroups_max; 61 extern int __xpg4; 62 63 switch (name) { 64 default: 65 errno = EINVAL; 66 return (-1L); 67 68 case _SC_ARG_MAX: 69 return ((long)ARG_MAX); 70 71 case _SC_CLK_TCK: 72 if (_hz <= 0) 73 _hz = _sysconfig(_CONFIG_CLK_TCK); 74 return (_hz); 75 76 case _SC_JOB_CONTROL: 77 return ((long)_POSIX_JOB_CONTROL); 78 79 case _SC_SAVED_IDS: 80 return ((long)_POSIX_SAVED_IDS); 81 82 case _SC_CHILD_MAX: 83 return (_sysconfig(_CONFIG_CHILD_MAX)); 84 85 case _SC_NGROUPS_MAX: 86 if (_ngroups_max <= 0) 87 _ngroups_max = _sysconfig(_CONFIG_NGROUPS); 88 return (_ngroups_max); 89 90 case _SC_OPEN_MAX: 91 return (_sysconfig(_CONFIG_OPEN_FILES)); 92 93 case _SC_VERSION: 94 if (__xpg6 & _C99SUSv3_XPG6_sysconf_version) 95 return (200112L); 96 else 97 return (199506L); 98 99 case _SC_PAGESIZE: 100 if (_pagesize <= 0) 101 _pagesize = _sysconfig(_CONFIG_PAGESIZE); 102 return (_pagesize); 103 104 case _SC_XOPEN_VERSION: 105 if (__xpg6 & _C99SUSv3_XPG6_sysconf_version) 106 return (600L); 107 else if (__xpg4 == 0) 108 return (_sysconfig(_CONFIG_XOPEN_VER)); 109 else 110 return (4L); 111 112 case _SC_XOPEN_XCU_VERSION: 113 if (__xpg6 & _C99SUSv3_XPG6_sysconf_version) 114 return (600L); 115 else 116 return (4L); 117 118 /* 119 * old value for pre XPG5 conformant systems to match 120 * getpass() length. 121 * XPG5 special cased with __sysconf_xpg5() 122 * new value for default and modern XPG systems. 123 */ 124 case _SC_PASS_MAX: 125 if ((__xpg4 == 1) && 126 (!(__xpg6 & _C99SUSv3_XPG6_sysconf_version))) 127 return ((long)_PASS_MAX_XPG); 128 else 129 return ((long)_PASS_MAX); 130 131 case _SC_LOGNAME_MAX: 132 return ((long)LOGNAME_MAX); 133 134 case _SC_STREAM_MAX: 135 return (_sysconfig(_CONFIG_OPEN_FILES)); 136 137 case _SC_TZNAME_MAX: 138 return (-1L); 139 140 case _SC_NPROCESSORS_CONF: 141 return (_sysconfig(_CONFIG_NPROC_CONF)); 142 143 case _SC_NPROCESSORS_ONLN: 144 return (_sysconfig(_CONFIG_NPROC_ONLN)); 145 146 case _SC_NPROCESSORS_MAX: 147 return (_sysconfig(_CONFIG_NPROC_MAX)); 148 149 case _SC_STACK_PROT: 150 if (_stackprot == 0) 151 _stackprot = _sysconfig(_CONFIG_STACK_PROT); 152 return (_stackprot); 153 154 /* POSIX.4 names */ 155 156 /* 157 * Each of the following also have _POSIX_* symbols 158 * defined in <unistd.h>. Values here should align 159 * with values in the header. Up until the SUSv3 standard 160 * we defined these simply as 1. With the introduction 161 * of the new revision, these were changed to 200112L. 162 * The standard allows us to change the value, however, 163 * we have kept both values in case application programs 164 * are relying on the previous value even though an 165 * application doing so is technically wrong. 166 */ 167 case _SC_ASYNCHRONOUS_IO: 168 case _SC_FSYNC: 169 case _SC_MAPPED_FILES: 170 case _SC_MEMLOCK: 171 case _SC_MEMLOCK_RANGE: 172 case _SC_MEMORY_PROTECTION: 173 case _SC_MESSAGE_PASSING: 174 case _SC_PRIORITY_SCHEDULING: 175 case _SC_REALTIME_SIGNALS: 176 case _SC_SEMAPHORES: 177 case _SC_SHARED_MEMORY_OBJECTS: 178 case _SC_SYNCHRONIZED_IO: 179 case _SC_TIMERS: 180 if (__xpg6 & _C99SUSv3_mode_ON) 181 return (200112L); 182 else 183 return (1L); 184 185 case _SC_PRIORITIZED_IO: 186 #ifdef _POSIX_PRIORITIZED_IO 187 return (1L); 188 #else 189 return (-1L); 190 #endif 191 192 case _SC_AIO_LISTIO_MAX: 193 return (_sysconfig(_CONFIG_AIO_LISTIO_MAX)); 194 195 case _SC_AIO_MAX: 196 return (_sysconfig(_CONFIG_AIO_MAX)); 197 198 case _SC_AIO_PRIO_DELTA_MAX: 199 return (_sysconfig(_CONFIG_AIO_PRIO_DELTA_MAX)); 200 201 case _SC_DELAYTIMER_MAX: 202 return (_sysconfig(_CONFIG_DELAYTIMER_MAX)); 203 204 case _SC_MQ_OPEN_MAX: 205 return (_sysconfig(_CONFIG_MQ_OPEN_MAX)); 206 207 case _SC_MQ_PRIO_MAX: 208 return (_sysconfig(_CONFIG_MQ_PRIO_MAX)); 209 210 case _SC_RTSIG_MAX: 211 return (_sysconfig(_CONFIG_RTSIG_MAX)); 212 213 case _SC_SEM_NSEMS_MAX: 214 return (_sysconfig(_CONFIG_SEM_NSEMS_MAX)); 215 216 case _SC_SEM_VALUE_MAX: 217 return (_sysconfig(_CONFIG_SEM_VALUE_MAX)); 218 219 case _SC_SIGQUEUE_MAX: 220 return (_sysconfig(_CONFIG_SIGQUEUE_MAX)); 221 222 case _SC_SIGRT_MAX: 223 return (_sysconfig(_CONFIG_SIGRT_MAX)); 224 225 case _SC_SIGRT_MIN: 226 return (_sysconfig(_CONFIG_SIGRT_MIN)); 227 228 case _SC_TIMER_MAX: 229 return (_sysconfig(_CONFIG_TIMER_MAX)); 230 231 case _SC_PHYS_PAGES: 232 return (_sysconfig(_CONFIG_PHYS_PAGES)); 233 234 case _SC_AVPHYS_PAGES: 235 return (_sysconfig(_CONFIG_AVPHYS_PAGES)); 236 237 /* XPG4/POSIX.1-1990/POSIX.2-1992 names */ 238 case _SC_2_C_BIND: 239 if (__xpg6 & _C99SUSv3_XPG6_sysconf_version) 240 return (200112L); 241 else 242 return (1L); 243 244 case _SC_2_CHAR_TERM: 245 return ((long)_POSIX2_CHAR_TERM); 246 247 case _SC_2_C_DEV: 248 if (__xpg6 & _C99SUSv3_XPG6_sysconf_version) 249 return (200112L); 250 else 251 return (1L); 252 253 case _SC_2_C_VERSION: 254 if (__xpg6 & _C99SUSv3_XPG6_sysconf_version) 255 return (200112L); 256 else 257 return (199209L); 258 259 case _SC_2_FORT_DEV: 260 return (-1L); 261 262 case _SC_2_FORT_RUN: 263 if (__xpg6 & _C99SUSv3_XPG6_sysconf_version) 264 return (200112L); 265 else 266 return (1L); 267 268 case _SC_2_LOCALEDEF: 269 if (__xpg6 & _C99SUSv3_XPG6_sysconf_version) 270 return (200112L); 271 else 272 return (1L); 273 274 case _SC_2_SW_DEV: 275 if (__xpg6 & _C99SUSv3_XPG6_sysconf_version) 276 return (200112L); 277 else 278 return (1L); 279 280 case _SC_2_UPE: 281 if (__xpg6 & _C99SUSv3_XPG6_sysconf_version) 282 return (200112L); 283 else 284 return (1L); 285 286 case _SC_2_VERSION: 287 if (__xpg6 & _C99SUSv3_XPG6_sysconf_version) 288 return (200112L); 289 else 290 return (199209L); 291 292 case _SC_BC_BASE_MAX: 293 return ((long)BC_BASE_MAX); 294 295 case _SC_BC_DIM_MAX: 296 return ((long)BC_DIM_MAX); 297 298 case _SC_BC_SCALE_MAX: 299 return ((long)BC_SCALE_MAX); 300 301 case _SC_BC_STRING_MAX: 302 return ((long)BC_STRING_MAX); 303 304 case _SC_COLL_WEIGHTS_MAX: 305 return ((long)COLL_WEIGHTS_MAX); 306 307 case _SC_EXPR_NEST_MAX: 308 return ((long)EXPR_NEST_MAX); 309 310 case _SC_LINE_MAX: 311 return ((long)LINE_MAX); 312 313 case _SC_RE_DUP_MAX: 314 return ((long)RE_DUP_MAX); 315 316 case _SC_XOPEN_CRYPT: 317 return (1L); 318 319 case _SC_XOPEN_ENH_I18N: 320 return ((long)_XOPEN_ENH_I18N); 321 322 case _SC_XOPEN_SHM: 323 return ((long)_XOPEN_SHM); 324 325 /* XPG4v2 (SUS) names */ 326 case _SC_XOPEN_UNIX: 327 return (1L); 328 329 case _SC_XOPEN_LEGACY: 330 return (1L); 331 332 case _SC_ATEXIT_MAX: 333 return (-1L); 334 335 case _SC_IOV_MAX: 336 return ((long)IOV_MAX); 337 338 case _SC_T_IOV_MAX: 339 return ((long)T_IOV_MAX); 340 341 /* XPG5 (SUSv2) names */ 342 case _SC_XOPEN_REALTIME: 343 return (1L); 344 345 case _SC_XOPEN_REALTIME_THREADS: 346 #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) && \ 347 defined(_POSIX_THREAD_PRIO_INHERIT) && \ 348 defined(_POSIX_THREAD_PRIO_PROTECT) 349 return (1L); 350 #else 351 return (-1L); 352 #endif 353 354 case _SC_XBS5_ILP32_OFF32: 355 return (1L); 356 357 case _SC_XBS5_ILP32_OFFBIG: 358 return (1L); 359 360 case _SC_XBS5_LP64_OFF64: 361 return (1L); 362 363 case _SC_XBS5_LPBIG_OFFBIG: 364 return (1L); 365 366 /* POSIX.1c names */ 367 case _SC_THREAD_DESTRUCTOR_ITERATIONS: 368 return (-1L); 369 370 case _SC_GETGR_R_SIZE_MAX: 371 return ((long)_nss_get_bufsizes(_SC_GETGR_R_SIZE_MAX)); 372 373 case _SC_GETPW_R_SIZE_MAX: 374 return ((long)NSS_BUFLEN_PASSWD); 375 376 case _SC_LOGIN_NAME_MAX: 377 return ((long)(LOGIN_NAME_MAX)); 378 379 case _SC_THREAD_KEYS_MAX: 380 return (-1L); 381 382 case _SC_THREAD_STACK_MIN: 383 return ((long)thr_min_stack()); 384 385 case _SC_THREAD_THREADS_MAX: 386 return (-1L); 387 388 case _SC_TTY_NAME_MAX: 389 return ((long)TTYNAME_MAX); 390 391 case _SC_BARRIERS: 392 return ((long)_POSIX_BARRIERS); 393 394 case _SC_CLOCK_SELECTION: 395 return ((long)_POSIX_CLOCK_SELECTION); 396 397 case _SC_MONOTONIC_CLOCK: 398 return ((long)_POSIX_MONOTONIC_CLOCK); 399 400 case _SC_SPAWN: 401 return ((long)_POSIX_SPAWN); 402 403 case _SC_SPIN_LOCKS: 404 return ((long)_POSIX_SPIN_LOCKS); 405 406 case _SC_THREADS: 407 case _SC_THREAD_ATTR_STACKADDR: 408 case _SC_THREAD_ATTR_STACKSIZE: 409 case _SC_THREAD_PRIORITY_SCHEDULING: 410 case _SC_THREAD_PRIO_INHERIT: 411 case _SC_THREAD_PRIO_PROTECT: 412 case _SC_THREAD_PROCESS_SHARED: 413 case _SC_THREAD_SAFE_FUNCTIONS: 414 if (__xpg6 & _C99SUSv3_mode_ON) 415 return (200112L); 416 else 417 return (1L); 418 419 case _SC_TIMEOUTS: 420 return ((long)_POSIX_TIMEOUTS); 421 422 /* 1216676 - cache info */ 423 case _SC_COHER_BLKSZ: 424 return (_sysconfig(_CONFIG_COHERENCY)); 425 426 case _SC_SPLIT_CACHE: 427 return (_sysconfig(_CONFIG_SPLIT_CACHE)); 428 429 case _SC_ICACHE_SZ: 430 return (_sysconfig(_CONFIG_ICACHESZ)); 431 432 case _SC_DCACHE_SZ: 433 return (_sysconfig(_CONFIG_DCACHESZ)); 434 435 case _SC_ICACHE_LINESZ: 436 return (_sysconfig(_CONFIG_ICACHELINESZ)); 437 438 case _SC_DCACHE_LINESZ: 439 return (_sysconfig(_CONFIG_DCACHELINESZ)); 440 441 case _SC_ICACHE_BLKSZ: 442 return (_sysconfig(_CONFIG_ICACHEBLKSZ)); 443 444 case _SC_DCACHE_BLKSZ: 445 return (_sysconfig(_CONFIG_DCACHEBLKSZ)); 446 447 case _SC_DCACHE_TBLKSZ: 448 return (_sysconfig(_CONFIG_DCACHETBLKSZ)); 449 450 case _SC_ICACHE_ASSOC: 451 return (_sysconfig(_CONFIG_ICACHE_ASSOC)); 452 453 case _SC_DCACHE_ASSOC: 454 return (_sysconfig(_CONFIG_DCACHE_ASSOC)); 455 456 case _SC_MAXPID: 457 if (_maxpid <= 0) 458 _maxpid = _sysconfig(_CONFIG_MAXPID); 459 return (_maxpid); 460 461 case _SC_CPUID_MAX: 462 return (_sysconfig(_CONFIG_CPUID_MAX)); 463 464 case _SC_EPHID_MAX: 465 return (_sysconfig(_CONFIG_EPHID_MAX)); 466 467 /* UNIX 03 names - XPG6/SUSv3/POSIX.1-2001 */ 468 469 case _SC_REGEXP: 470 return ((long)_POSIX_REGEXP); 471 472 case _SC_SHELL: 473 return ((long)_POSIX_SHELL); 474 475 case _SC_ADVISORY_INFO: 476 return ((long)_POSIX_ADVISORY_INFO); 477 478 case _SC_HOST_NAME_MAX: 479 return ((long)_POSIX_HOST_NAME_MAX); 480 481 case _SC_READER_WRITER_LOCKS: 482 return ((long)_POSIX_READER_WRITER_LOCKS); 483 484 case _SC_IPV6: 485 return ((long)_POSIX_IPV6); 486 487 case _SC_RAW_SOCKETS: 488 return ((long)_POSIX_RAW_SOCKETS); 489 490 case _SC_XOPEN_STREAMS: 491 return ((long)_XOPEN_STREAMS); 492 493 case _SC_SYMLOOP_MAX: 494 return (_sysconfig(_CONFIG_SYMLOOP_MAX)); 495 496 case _SC_V6_ILP32_OFF32: 497 return (1L); 498 499 case _SC_V6_ILP32_OFFBIG: 500 return (1L); 501 502 case _SC_V6_LP64_OFF64: 503 return (1L); 504 505 case _SC_V6_LPBIG_OFFBIG: 506 return (1L); 507 508 /* Unsupported UNIX 03 options */ 509 case _SC_2_PBS: 510 case _SC_2_PBS_ACCOUNTING: 511 case _SC_2_PBS_CHECKPOINT: 512 case _SC_2_PBS_LOCATE: 513 case _SC_2_PBS_MESSAGE: 514 case _SC_2_PBS_TRACK: 515 case _SC_CPUTIME: 516 case _SC_SPORADIC_SERVER: 517 case _SC_SS_REPL_MAX: 518 case _SC_THREAD_CPUTIME: 519 case _SC_THREAD_SPORADIC_SERVER: 520 case _SC_TRACE: 521 case _SC_TRACE_EVENT_FILTER: 522 case _SC_TRACE_EVENT_NAME_MAX: 523 case _SC_TRACE_INHERIT: 524 case _SC_TRACE_LOG: 525 case _SC_TRACE_NAME_MAX: 526 case _SC_TRACE_SYS_MAX: 527 case _SC_TRACE_USER_EVENT_MAX: 528 case _SC_TYPED_MEMORY_OBJECTS: 529 return (-1L); 530 } 531 } 532 533 /* 534 * UNIX 98 version of sysconf needed in order to set _XOPEN_VERSION to 500. 535 */ 536 537 long 538 __sysconf_xpg5(int name) 539 { 540 switch (name) { 541 default: 542 return (sysconf(name)); 543 case _SC_XOPEN_VERSION: 544 return (500L); 545 case _SC_PASS_MAX: 546 return ((long)_PASS_MAX_XPG); 547 } 548 }