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