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