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