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