xref: /titanic_52/usr/src/lib/libc/port/gen/sysconf.c (revision bf56214c0556fa6864189c826d39dbe156bb22a0)
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 			return ((long)_POSIX2_C_BIND);
235 
236 		case _SC_2_CHAR_TERM:
237 			return ((long)_POSIX2_CHAR_TERM);
238 
239 		case _SC_2_C_DEV:
240 			return ((long)_POSIX2_C_DEV);
241 
242 		case _SC_2_C_VERSION:
243 			if (__xpg6 & _C99SUSv3_XPG6_sysconf_version)
244 				return (200112L);
245 			else
246 				return (199209L);
247 
248 		case _SC_2_FORT_DEV:
249 			return (-1L);
250 
251 		case _SC_2_FORT_RUN:
252 			return ((long)_POSIX2_FORT_RUN);
253 
254 		case _SC_2_LOCALEDEF:
255 			return ((long)_POSIX2_LOCALEDEF);
256 
257 		case _SC_2_SW_DEV:
258 			return ((long)_POSIX2_SW_DEV);
259 
260 		case _SC_2_UPE:
261 			return ((long)_POSIX2_UPE);
262 
263 		case _SC_2_VERSION:
264 			if (__xpg6 & _C99SUSv3_XPG6_sysconf_version)
265 				return (200112L);
266 			else
267 				return (199209L);
268 
269 		case _SC_BC_BASE_MAX:
270 			return ((long)BC_BASE_MAX);
271 
272 		case _SC_BC_DIM_MAX:
273 			return ((long)BC_DIM_MAX);
274 
275 		case _SC_BC_SCALE_MAX:
276 			return ((long)BC_SCALE_MAX);
277 
278 		case _SC_BC_STRING_MAX:
279 			return ((long)BC_STRING_MAX);
280 
281 		case _SC_COLL_WEIGHTS_MAX:
282 			return ((long)COLL_WEIGHTS_MAX);
283 
284 		case _SC_EXPR_NEST_MAX:
285 			return ((long)EXPR_NEST_MAX);
286 
287 		case _SC_LINE_MAX:
288 			return ((long)LINE_MAX);
289 
290 		case _SC_RE_DUP_MAX:
291 			return ((long)RE_DUP_MAX);
292 
293 		case _SC_XOPEN_CRYPT:
294 			return (1L);
295 
296 		case _SC_XOPEN_ENH_I18N:
297 			return ((long)_XOPEN_ENH_I18N);
298 
299 		case _SC_XOPEN_SHM:
300 			return ((long)_XOPEN_SHM);
301 
302 		/* XPG4v2 (SUS) names */
303 		case _SC_XOPEN_UNIX:
304 			return (1L);
305 
306 		case _SC_XOPEN_LEGACY:
307 			return (1L);
308 
309 		case _SC_ATEXIT_MAX:
310 			return (-1L);
311 
312 		case _SC_IOV_MAX:
313 			return ((long)IOV_MAX);
314 
315 		case _SC_T_IOV_MAX:
316 			return ((long)T_IOV_MAX);
317 
318 		/* XPG5 (SUSv2) names */
319 		case _SC_XOPEN_REALTIME:
320 			return (1L);
321 
322 		case _SC_XOPEN_REALTIME_THREADS:
323 #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) && \
324 	defined(_POSIX_THREAD_PRIO_INHERIT) && \
325 	defined(_POSIX_THREAD_PRIO_PROTECT)
326 			return (1L);
327 #else
328 			return (-1L);
329 #endif
330 
331 		case _SC_XBS5_ILP32_OFF32:
332 			return (1L);
333 
334 		case _SC_XBS5_ILP32_OFFBIG:
335 			return (1L);
336 
337 		case _SC_XBS5_LP64_OFF64:
338 			return (1L);
339 
340 		case _SC_XBS5_LPBIG_OFFBIG:
341 			return (1L);
342 
343 		/* POSIX.1c names */
344 		case _SC_THREAD_DESTRUCTOR_ITERATIONS:
345 			return (-1L);
346 
347 		case _SC_GETGR_R_SIZE_MAX:
348 			return ((long)NSS_BUFLEN_GROUP);
349 
350 		case _SC_GETPW_R_SIZE_MAX:
351 			return ((long)NSS_BUFLEN_PASSWD);
352 
353 		case _SC_LOGIN_NAME_MAX:
354 			return ((long)(LOGNAME_MAX + 1));
355 
356 		case _SC_THREAD_KEYS_MAX:
357 			return (-1L);
358 
359 		case _SC_THREAD_STACK_MIN:
360 			return ((long)_thr_min_stack());
361 
362 		case _SC_THREAD_THREADS_MAX:
363 			return (-1L);
364 
365 		case _SC_TTY_NAME_MAX:
366 			return ((long)TTYNAME_MAX);
367 
368 		case _SC_BARRIERS:
369 			return ((long)_POSIX_BARRIERS);
370 
371 		case _SC_CLOCK_SELECTION:
372 			return ((long)_POSIX_CLOCK_SELECTION);
373 
374 		case _SC_MONOTONIC_CLOCK:
375 			return ((long)_POSIX_MONOTONIC_CLOCK);
376 
377 		case _SC_SPAWN:
378 			return ((long)_POSIX_SPAWN);
379 
380 		case _SC_SPIN_LOCKS:
381 			return ((long)_POSIX_SPIN_LOCKS);
382 
383 		case _SC_THREADS:
384 		case _SC_THREAD_ATTR_STACKADDR:
385 		case _SC_THREAD_ATTR_STACKSIZE:
386 		case _SC_THREAD_PRIORITY_SCHEDULING:
387 		case _SC_THREAD_PRIO_INHERIT:
388 		case _SC_THREAD_PRIO_PROTECT:
389 		case _SC_THREAD_PROCESS_SHARED:
390 		case _SC_THREAD_SAFE_FUNCTIONS:
391 			if (__xpg6 & _C99SUSv3_mode_ON)
392 				return (200112L);
393 			else
394 				return (1L);
395 
396 		case _SC_TIMEOUTS:
397 			return ((long)_POSIX_TIMEOUTS);
398 
399 		/* 1216676 - cache info */
400 		case _SC_COHER_BLKSZ:
401 			return (_sysconfig(_CONFIG_COHERENCY));
402 
403 		case _SC_SPLIT_CACHE:
404 			return (_sysconfig(_CONFIG_SPLIT_CACHE));
405 
406 		case _SC_ICACHE_SZ:
407 			return (_sysconfig(_CONFIG_ICACHESZ));
408 
409 		case _SC_DCACHE_SZ:
410 			return (_sysconfig(_CONFIG_DCACHESZ));
411 
412 		case _SC_ICACHE_LINESZ:
413 			return (_sysconfig(_CONFIG_ICACHELINESZ));
414 
415 		case _SC_DCACHE_LINESZ:
416 			return (_sysconfig(_CONFIG_DCACHELINESZ));
417 
418 		case _SC_ICACHE_BLKSZ:
419 			return (_sysconfig(_CONFIG_ICACHEBLKSZ));
420 
421 		case _SC_DCACHE_BLKSZ:
422 			return (_sysconfig(_CONFIG_DCACHEBLKSZ));
423 
424 		case _SC_DCACHE_TBLKSZ:
425 			return (_sysconfig(_CONFIG_DCACHETBLKSZ));
426 
427 		case _SC_ICACHE_ASSOC:
428 			return (_sysconfig(_CONFIG_ICACHE_ASSOC));
429 
430 		case _SC_DCACHE_ASSOC:
431 			return (_sysconfig(_CONFIG_DCACHE_ASSOC));
432 
433 		case _SC_MAXPID:
434 			if (_maxpid <= 0)
435 				_maxpid = _sysconfig(_CONFIG_MAXPID);
436 			return (_maxpid);
437 
438 		case _SC_CPUID_MAX:
439 			return (_sysconfig(_CONFIG_CPUID_MAX));
440 
441 		case _SC_EPHID_MAX:
442 			return (_sysconfig(_CONFIG_EPHID_MAX));
443 
444 		/* UNIX 03 names - XPG6/SUSv3/POSIX.1-2001 */
445 
446 		case _SC_REGEXP:
447 			return ((long)_POSIX_REGEXP);
448 
449 		case _SC_SHELL:
450 			return ((long)_POSIX_SHELL);
451 
452 		case _SC_HOST_NAME_MAX:
453 			return ((long)_POSIX_HOST_NAME_MAX);
454 
455 		case _SC_READER_WRITER_LOCKS:
456 			return ((long)_POSIX_READER_WRITER_LOCKS);
457 
458 		case _SC_IPV6:
459 			return ((long)_POSIX_IPV6);
460 
461 		case _SC_RAW_SOCKETS:
462 			return ((long)_POSIX_RAW_SOCKETS);
463 
464 		case _SC_XOPEN_STREAMS:
465 			return ((long)_XOPEN_STREAMS);
466 
467 		case _SC_SYMLOOP_MAX:
468 			return (_sysconfig(_CONFIG_SYMLOOP_MAX));
469 
470 		case _SC_V6_ILP32_OFF32:
471 			return (1L);
472 
473 		case _SC_V6_ILP32_OFFBIG:
474 			return (1L);
475 
476 		case _SC_V6_LP64_OFF64:
477 			return (1L);
478 
479 		case _SC_V6_LPBIG_OFFBIG:
480 			return (1L);
481 
482 		/* Unsupported UNIX 03 options */
483 		case _SC_2_PBS:
484 		case _SC_2_PBS_ACCOUNTING:
485 		case _SC_2_PBS_CHECKPOINT:
486 		case _SC_2_PBS_LOCATE:
487 		case _SC_2_PBS_MESSAGE:
488 		case _SC_2_PBS_TRACK:
489 		case _SC_ADVISORY_INFO:
490 		case _SC_CPUTIME:
491 		case _SC_SPORADIC_SERVER:
492 		case _SC_SS_REPL_MAX:
493 		case _SC_THREAD_CPUTIME:
494 		case _SC_THREAD_SPORADIC_SERVER:
495 		case _SC_TRACE:
496 		case _SC_TRACE_EVENT_FILTER:
497 		case _SC_TRACE_EVENT_NAME_MAX:
498 		case _SC_TRACE_INHERIT:
499 		case _SC_TRACE_LOG:
500 		case _SC_TRACE_NAME_MAX:
501 		case _SC_TRACE_SYS_MAX:
502 		case _SC_TRACE_USER_EVENT_MAX:
503 		case _SC_TYPED_MEMORY_OBJECTS:
504 			return (-1L);
505 	}
506 }
507 
508 /*
509  * UNIX 98 version of sysconf needed in order to set _XOPEN_VERSION to 500.
510  */
511 
512 long
513 __sysconf_xpg5(int name)
514 {
515 	switch (name) {
516 		default:
517 			return (sysconf(name));
518 		case _SC_XOPEN_VERSION:
519 			return (500L);
520 		case _SC_PASS_MAX:
521 			return ((long)_PASS_MAX_XPG);
522 	}
523 }
524