xref: /titanic_50/usr/src/uts/common/sys/param.h (revision d6114e2d100d9ec3b45f9968d45ac2e3a0827af0)
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	GID_SYS		3
85 #define	UID_DLADM	15
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 _clsize;
383 #endif	/* defined(_KERNEL) && !defined(_ASM) */
384 
385 #define	PAGESIZE	_pagesize
386 #define	PAGESHIFT	_pageshift
387 #define	PAGEOFFSET	_pageoffset
388 #define	PAGEMASK	_pagemask
389 #define	MMU_PAGESIZE	_mmu_pagesize
390 #define	MMU_PAGESHIFT	_mmu_pageshift
391 #define	MMU_PAGEOFFSET	_mmu_pageoffset
392 #define	MMU_PAGEMASK	_mmu_pagemask
393 
394 #define	KERNELBASE	_kernelbase
395 #define	USERLIMIT	_userlimit
396 #define	USERLIMIT32	_userlimit32
397 #define	ARGSBASE	_argsbase
398 #define	DEFAULTSTKSZ	_defaultstksz
399 #define	NCPU		_ncpu
400 
401 #endif	/* defined(_MACHDEP) */
402 
403 /*
404  * Some random macros for units conversion.
405  *
406  * These are machine independent but contain constants (*PAGESHIFT) which
407  * are only defined in the machine dependent file.
408  */
409 
410 /*
411  * MMU pages to bytes, and back (with and without rounding)
412  */
413 #define	mmu_ptob(x)	((x) << MMU_PAGESHIFT)
414 #define	mmu_btop(x)	(((x)) >> MMU_PAGESHIFT)
415 #define	mmu_btopr(x)	((((x) + MMU_PAGEOFFSET) >> MMU_PAGESHIFT))
416 
417 /*
418  * 2 versions of pages to disk blocks
419  */
420 #define	mmu_ptod(x)	((x) << (MMU_PAGESHIFT - DEV_BSHIFT))
421 #define	ptod(x)		((x) << (PAGESHIFT - DEV_BSHIFT))
422 
423 /*
424  * pages to bytes, and back (with and without rounding)
425  * Large Files: The explicit cast of x to unsigned int is deliberately
426  * removed as part of large files work. We pass longlong values to
427  * theses macros.
428  *
429  * Cast the input to ptob() to be a page count. This enforces 64-bit
430  * math on 64-bit kernels. For 32-bit kernels, callers must explicitly
431  * cast the input to be a 64-bit type if values greater than 4GB/PAGESIZE
432  * are possible.
433  */
434 
435 #ifdef _LP64
436 #define	ptob(x)		(((pgcnt_t)(x)) << PAGESHIFT)
437 #else
438 #define	ptob(x)		((x) << PAGESHIFT)
439 #endif /* _LP64 */
440 #define	btop(x)		(((x) >> PAGESHIFT))
441 #define	btopr(x)	((((x) + PAGEOFFSET) >> PAGESHIFT))
442 
443 /*
444  * disk blocks to pages, rounded and truncated
445  */
446 #define	NDPP		(PAGESIZE/DEV_BSIZE)	/* # of disk blocks per page */
447 #define	dtop(DD)	(((DD) + NDPP - 1) >> (PAGESHIFT - DEV_BSHIFT))
448 #define	dtopt(DD)	((DD) >> (PAGESHIFT - DEV_BSHIFT))
449 
450 /*
451  * kB to pages and back
452  */
453 #define	kbtop(x)	((x) >> (PAGESHIFT - 10))
454 #define	ptokb(x)	((x) << (PAGESHIFT - 10))
455 
456 /*
457  * POSIX.4 related configuration parameters
458  */
459 #define	_AIO_LISTIO_MAX		(4096)
460 #define	_AIO_MAX		(-1)
461 #define	_MQ_OPEN_MAX		(-1)
462 #define	_MQ_PRIO_MAX		(32)
463 #define	_SEM_NSEMS_MAX		INT_MAX
464 #define	_SEM_VALUE_MAX		INT_MAX
465 
466 #ifdef	__cplusplus
467 }
468 #endif
469 
470 #else	/* (defined(_KERNEL) || defined(_KMEMUSER)) */
471 
472 /*
473  * The following are assorted machine dependent values which can be
474  * obtained in a machine independent manner through sysconf(2) or
475  * sysinfo(2). In order to guarantee that these provide the expected
476  * value at all times, the System Private interface (leading underscore)
477  * is used.
478  */
479 
480 #include <sys/unistd.h>
481 
482 #ifdef	__cplusplus
483 extern "C" {
484 #endif
485 
486 #if !defined(_ASM)
487 extern long _sysconf(int);	/* System Private interface to sysconf() */
488 #endif	/* !defined(_ASM) */
489 
490 #define	HZ		((clock_t)_sysconf(_SC_CLK_TCK))
491 #define	TICK		(1000000000/((clock_t)_sysconf(_SC_CLK_TCK)))
492 #define	PAGESIZE	(_sysconf(_SC_PAGESIZE))
493 #define	PAGEOFFSET	(PAGESIZE - 1)
494 #define	PAGEMASK	(~PAGEOFFSET)
495 #define	MAXPID		((pid_t)_sysconf(_SC_MAXPID))
496 #define	MAXEPHUID	((uid_t)_sysconf(_SC_EPHID_MAX))
497 
498 #ifdef	__cplusplus
499 }
500 #endif
501 
502 #endif	/* (defined(_KERNEL) || defined(_KMEMUSER)) &&  defined(_MACHDEP) */
503 
504 #endif	/* _SYS_PARAM_H */
505