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