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