xref: /titanic_52/usr/src/uts/common/sys/param.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #ifndef _SYS_PARAM_H
41 #define	_SYS_PARAM_H
42 
43 #pragma ident	"%Z%%M%	%I%	%E% SMI"
44 
45 #ifndef _ASM		/* Avoid typedef headaches for assembly files */
46 #include <sys/types.h>
47 #include <sys/isa_defs.h>
48 #endif /* _ASM */
49 
50 
51 #ifdef	__cplusplus
52 extern "C" {
53 #endif
54 
55 /*
56  * Fundamental variables; don't change too often.
57  */
58 
59 /*
60  * _POSIX_VDISABLE has historically been defined in <sys/param.h> since
61  * an early merge with AT&T source.  It has also historically been defined
62  * in <sys/termios.h>. The POSIX standard, IEEE Std. 1003.1-1988 initially
63  * required the existence of _POSIX_VDISABLE in <sys/termios.h>.
64  * Subsequent versions of the IEEE Standard as well as the X/Open
65  * specifications required that _POSIX_VDISABLE be defined in <unistd.h>
66  * while still allowing for it's existence in other headers.  With the
67  * introduction of XPG6, _POSIX_VDISABLE can only be defined in <unistd.h>.
68  */
69 #if !defined(_XPG6) || defined(__EXTENSIONS__)
70 #ifndef	_POSIX_VDISABLE
71 #define	_POSIX_VDISABLE 0	/* Disable special character functions */
72 #endif
73 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
74 
75 #ifndef	MAX_INPUT
76 #define	MAX_INPUT	512	/* Maximum bytes stored in the input queue */
77 #endif
78 
79 #ifndef	MAX_CANON
80 #define	MAX_CANON	256	/* Maximum bytes for canonical processing */
81 #endif
82 
83 #define	UID_NOBODY	60001	/* user ID no body */
84 #define	GID_NOBODY	UID_NOBODY
85 
86 #define	UID_NOACCESS	60002	/* user ID no access */
87 
88 #ifdef _KERNEL
89 #define	MAX_TASKID	999999
90 #define	MAX_MAXPID	999999
91 #endif
92 
93 #ifdef DEBUG
94 #define	DEFAULT_MAXPID	999999
95 #define	DEFAULT_JUMPPID	100000
96 #else
97 #define	DEFAULT_MAXPID	30000
98 #define	DEFAULT_JUMPPID	0
99 
100 #endif
101 
102 #define	MAXUID		2147483647	/* max user id */
103 #define	MAXPROJID	MAXUID		/* max project id */
104 #define	MAXLINK		32767	/* max links */
105 
106 #define	NMOUNT		40	/* est. of # mountable fs for quota calc */
107 
108 #define	CANBSIZ		256	/* max size of typewriter line	*/
109 
110 #define	NOFILE		20	/* this define is here for	*/
111 				/* compatibility purposes only	*/
112 				/* and will be removed in a	*/
113 				/* later release		*/
114 
115 /*
116  * These define the maximum and minimum allowable values of the
117  * configurable parameter NGROUPS_MAX.
118  */
119 #define	NGROUPS_UMIN	0
120 #define	NGROUPS_UMAX	32
121 
122 /*
123  * NGROUPS_MAX_DEFAULT: *MUST* match NGROUPS_MAX value in limits.h.
124  * Remember that the NFS protocol must rev. before this can be increased
125  */
126 #define	NGROUPS_MAX_DEFAULT	16
127 
128 /*
129  * Default process priority.  Keep it in sync with limits.h.
130  */
131 #define	NZERO	20
132 
133 /*
134  * Fundamental constants of the implementation--cannot be changed easily.
135  */
136 
137 #define	NBPW	sizeof (int)	/* number of bytes in an integer */
138 
139 #ifndef	NULL
140 #if defined(_LP64)
141 #define	NULL    0L
142 #else
143 #define	NULL	0
144 #endif
145 #endif
146 
147 #define	CMASK	022		/* default mask for file creation */
148 #define	CDLIMIT	(1L<<11)	/* default max write address */
149 #define	NBPS		0x20000	/* Number of bytes per segment */
150 #define	NBPSCTR		512	/* Bytes per disk sector.	*/
151 #define	UBSIZE		512	/* unix block size.		*/
152 #define	SCTRSHFT	9	/* Shift for BPSECT.		*/
153 
154 #ifdef _LITTLE_ENDIAN
155 #define	lobyte(X)	(((unsigned char *)&(X))[0])
156 #define	hibyte(X)	(((unsigned char *)&(X))[1])
157 #define	loword(X)	(((ushort_t *)&(X))[0])
158 #define	hiword(X)	(((ushort_t *)&(X))[1])
159 #endif
160 #ifdef _BIG_ENDIAN
161 #define	lobyte(X)	(((unsigned char *)&(X))[1])
162 #define	hibyte(X)	(((unsigned char *)&(X))[0])
163 #define	loword(X)	(((ushort_t *)&(X))[1])
164 #define	hiword(X)	(((ushort_t *)&(X))[0])
165 #endif
166 
167 /* REMOTE -- whether machine is primary, secondary, or regular */
168 #define	SYSNAME 9		/* # chars in system name */
169 #define	PREMOTE 39
170 
171 /*
172  * MAXPATHLEN defines the longest permissible path length,
173  * including the terminating null, after expanding symbolic links.
174  * TYPICALMAXPATHLEN is used in a few places as an optimization
175  * with a local buffer on the stack to avoid kmem_alloc().
176  * MAXSYMLINKS defines the maximum number of symbolic links
177  * that may be expanded in a path name. It should be set high
178  * enough to allow all legitimate uses, but halt infinite loops
179  * reasonably quickly.
180  * MAXNAMELEN is the length (including the terminating null) of
181  * the longest permissible file (component) name.
182  */
183 #define	MAXPATHLEN	1024
184 #define	TYPICALMAXPATHLEN	64
185 #define	MAXSYMLINKS	20
186 #define	MAXNAMELEN	256
187 
188 #ifndef NADDR
189 #define	NADDR 13
190 #endif
191 
192 /*
193  * The following are defined to be the same as
194  * defined in /usr/include/limits.h.  They are
195  * needed for pipe and FIFO compatibility.
196  */
197 #ifndef PIPE_BUF	/* max # bytes atomic in write to a pipe */
198 #define	PIPE_BUF	5120
199 #endif	/* PIPE_BUF */
200 
201 #ifndef PIPE_MAX	/* max # bytes written to a pipe in a write */
202 #define	PIPE_MAX	5120
203 #endif	/* PIPE_MAX */
204 
205 #ifndef NBBY
206 #define	NBBY	8			/* number of bits per byte */
207 #endif
208 
209 /* macros replacing interleaving functions */
210 #define	dkblock(bp)	((bp)->b_blkno)
211 #define	dkunit(bp)	(minor((bp)->b_dev) >> 3)
212 
213 /*
214  * File system parameters and macros.
215  *
216  * The file system is made out of blocks of at most MAXBSIZE units,
217  * with smaller units (fragments) only in the last direct block.
218  * MAXBSIZE primarily determines the size of buffers in the buffer
219  * pool. It may be made larger without any effect on existing
220  * file systems; however making it smaller make make some file
221  * systems unmountable.
222  *
223  * Note that the blocked devices are assumed to have DEV_BSIZE
224  * "sectors" and that fragments must be some multiple of this size.
225  */
226 #define	MAXBSIZE	8192
227 #define	DEV_BSIZE	512
228 #define	DEV_BSHIFT	9		/* log2(DEV_BSIZE) */
229 #define	MAXFRAG 	8
230 #ifdef	_SYSCALL32
231 #define	MAXOFF32_T	0x7fffffff
232 #endif
233 #ifdef	_LP64
234 #define	MAXOFF_T	0x7fffffffffffffffl
235 #define	MAXOFFSET_T	0x7fffffffffffffffl
236 #else
237 #define	MAXOFF_T	0x7fffffffl
238 #ifdef _LONGLONG_TYPE
239 #define	MAXOFFSET_T 	0x7fffffffffffffffLL
240 #else
241 #define	MAXOFFSET_T	0x7fffffff
242 #endif
243 #endif	/* _LP64 */
244 
245 #define	btodb(bytes)			/* calculates (bytes / DEV_BSIZE) */ \
246 	((unsigned long)(bytes) >> DEV_BSHIFT)
247 #define	dbtob(db)			/* calculates (db * DEV_BSIZE) */ \
248 	((unsigned long)(db) << DEV_BSHIFT)
249 
250 /*	64 bit versions of btodb and dbtob */
251 #define	lbtodb(bytes)			/* calculates (bytes / DEV_BSIZE) */ \
252 	((u_offset_t)(bytes) >> DEV_BSHIFT)
253 #define	ldbtob(db)			/* calculates (db * DEV_BSIZE) */ \
254 	((u_offset_t)(db) << DEV_BSHIFT)
255 
256 #ifndef _ASM	/* Avoid typedef headaches for assembly files */
257 #ifndef NODEV
258 #define	NODEV	(dev_t)(-1l)
259 #ifdef _SYSCALL32
260 #define	NODEV32	(dev32_t)(-1)
261 #endif	/* _SYSCALL32 */
262 #endif	/* NODEV */
263 #endif	/* _ASM */
264 
265 /*
266  * Size of arg list passed in by user.
267  */
268 #define	NCARGS32	0x100000
269 #define	NCARGS64	0x200000
270 #ifdef	_LP64
271 #define	NCARGS		NCARGS64
272 #else	/* _LP64 */
273 #define	NCARGS		NCARGS32
274 #endif	/* _LP64 */
275 
276 /*
277  * Scale factor for scaled integers used to count
278  * %cpu time and load averages.
279  */
280 #define	FSHIFT	8		/* bits to right of fixed binary point */
281 #define	FSCALE	(1<<FSHIFT)
282 
283 /*
284  * Delay units are in microseconds.
285  *
286  * XXX	These macros are not part of the DDI!
287  */
288 #if defined(_KERNEL) && !defined(_ASM)
289 extern void drv_usecwait(clock_t);
290 #define	DELAY(n)	drv_usecwait(n)
291 #define	CDELAY(c, n)	\
292 { \
293 	register int N = n; \
294 	while (--N > 0) { \
295 		if (c) \
296 			break; \
297 		drv_usecwait(1); \
298 	} \
299 }
300 #endif	/* defined(_KERNEL) && !defined(_ASM) */
301 
302 #ifdef	__cplusplus
303 }
304 #endif
305 
306 /*
307  * The following is to free utilities from machine dependencies within
308  * an architecture. Must be included after definition of DEV_BSIZE.
309  */
310 
311 #if (defined(_KERNEL) || defined(_KMEMUSER))
312 
313 #if defined(_MACHDEP)
314 #include <sys/machparam.h>
315 #endif
316 
317 #ifdef	__cplusplus
318 extern "C" {
319 #endif
320 
321 #if defined(_KERNEL) && !defined(_ASM)
322 extern int cpu_decay_factor;
323 extern pid_t maxpid;
324 extern pid_t jump_pid;
325 
326 extern uintptr_t _kernelbase;
327 extern uintptr_t _userlimit;
328 extern uintptr_t _userlimit32;
329 #endif  /* defined(_KERNEL) && !defined(_ASM) */
330 
331 
332 #if !defined(_MACHDEP)
333 
334 /*
335  * Implementation architecture independent sections of the kernel use
336  * this section.
337  */
338 #if defined(_KERNEL) && !defined(_ASM)
339 extern int hz;
340 extern int snooping;
341 extern uint_t snoop_interval;
342 extern const unsigned long _pagesize;
343 extern const unsigned int _pageshift;
344 extern const unsigned long _pageoffset;
345 extern const unsigned long long _pagemask;
346 extern const unsigned long _mmu_pagesize;
347 extern const unsigned int _mmu_pageshift;
348 extern const unsigned long _mmu_pageoffset;
349 extern const unsigned long _mmu_pagemask;
350 extern const uintptr_t _argsbase;
351 extern const unsigned long _defaultstksz;
352 extern const unsigned int _nbpg;
353 extern const int _ncpu;
354 extern const int _clsize;
355 #endif	/* defined(_KERNEL) && !defined(_ASM) */
356 
357 #define	PAGESIZE	_pagesize
358 #define	PAGESHIFT	_pageshift
359 #define	PAGEOFFSET	_pageoffset
360 #define	PAGEMASK	_pagemask
361 #define	MMU_PAGESIZE	_mmu_pagesize
362 #define	MMU_PAGESHIFT	_mmu_pageshift
363 #define	MMU_PAGEOFFSET	_mmu_pageoffset
364 #define	MMU_PAGEMASK	_mmu_pagemask
365 
366 #define	KERNELBASE	_kernelbase
367 #define	USERLIMIT	_userlimit
368 #define	USERLIMIT32	_userlimit32
369 #define	ARGSBASE	_argsbase
370 #define	DEFAULTSTKSZ	_defaultstksz
371 #define	NCPU		_ncpu
372 
373 #endif	/* defined(_MACHDEP) */
374 
375 /*
376  * Some random macros for units conversion.
377  *
378  * These are machine independent but contain constants (*PAGESHIFT) which
379  * are only defined in the machine dependent file.
380  */
381 
382 /*
383  * MMU pages to bytes, and back (with and without rounding)
384  */
385 #define	mmu_ptob(x)	((x) << MMU_PAGESHIFT)
386 #define	mmu_btop(x)	(((x)) >> MMU_PAGESHIFT)
387 #define	mmu_btopr(x)	((((x) + MMU_PAGEOFFSET) >> MMU_PAGESHIFT))
388 
389 /*
390  * 2 versions of pages to disk blocks
391  */
392 #define	mmu_ptod(x)	((x) << (MMU_PAGESHIFT - DEV_BSHIFT))
393 #define	ptod(x)		((x) << (PAGESHIFT - DEV_BSHIFT))
394 
395 /*
396  * pages to bytes, and back (with and without rounding)
397  * Large Files: The explicit cast of x to unsigned int is deliberately
398  * removed as part of large files work. We pass longlong values to
399  * theses macros.
400  *
401  * Cast the input to ptob() to be a page count. This enforces 64-bit
402  * math on 64-bit kernels. For 32-bit kernels, callers must explicitly
403  * cast the input to be a 64-bit type if values greater than 4GB/PAGESIZE
404  * are possible.
405  */
406 
407 #ifdef _LP64
408 #define	ptob(x)		(((pgcnt_t)(x)) << PAGESHIFT)
409 #else
410 #define	ptob(x)		((x) << PAGESHIFT)
411 #endif /* _LP64 */
412 #define	btop(x)		(((x) >> PAGESHIFT))
413 #define	btopr(x)	((((x) + PAGEOFFSET) >> PAGESHIFT))
414 
415 /*
416  * disk blocks to pages, rounded and truncated
417  */
418 #define	NDPP		(PAGESIZE/DEV_BSIZE)	/* # of disk blocks per page */
419 #define	dtop(DD)	(((DD) + NDPP - 1) >> (PAGESHIFT - DEV_BSHIFT))
420 #define	dtopt(DD)	((DD) >> (PAGESHIFT - DEV_BSHIFT))
421 
422 /*
423  * POSIX.4 related configuration parameters
424  */
425 #define	_AIO_LISTIO_MAX		(4096)
426 #define	_AIO_MAX		(-1)
427 #define	_MQ_OPEN_MAX		(-1)
428 #define	_MQ_PRIO_MAX		(32)
429 #define	_SEM_NSEMS_MAX		INT_MAX
430 #define	_SEM_VALUE_MAX		INT_MAX
431 
432 #ifdef	__cplusplus
433 }
434 #endif
435 
436 #else	/* (defined(_KERNEL) || defined(_KMEMUSER)) */
437 
438 /*
439  * The following are assorted machine dependent values which can be
440  * obtained in a machine independent manner through sysconf(2) or
441  * sysinfo(2). In order to guarantee that these provide the expected
442  * value at all times, the System Private interface (leading underscore)
443  * is used.
444  */
445 
446 #include <sys/unistd.h>
447 
448 #ifdef	__cplusplus
449 extern "C" {
450 #endif
451 
452 #if !defined(_ASM)
453 extern long _sysconf(int);	/* System Private interface to sysconf() */
454 #endif	/* !defined(_ASM) */
455 
456 #define	HZ		((clock_t)_sysconf(_SC_CLK_TCK))
457 #define	TICK		(1000000000/((clock_t)_sysconf(_SC_CLK_TCK)))
458 #define	PAGESIZE	(_sysconf(_SC_PAGESIZE))
459 #define	PAGEOFFSET	(PAGESIZE - 1)
460 #define	PAGEMASK	(~PAGEOFFSET)
461 #define	MAXPID		((pid_t)_sysconf(_SC_MAXPID))
462 
463 #ifdef	__cplusplus
464 }
465 #endif
466 
467 #endif	/* (defined(_KERNEL) || defined(_KMEMUSER)) &&  defined(_MACHDEP) */
468 
469 #endif	/* _SYS_PARAM_H */
470