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