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