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