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