xref: /illumos-gate/usr/src/uts/common/sys/param.h (revision 71d45228ba245d505c3beae1d756e775616f6d5a)
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 
49 #ifdef	__cplusplus
50 extern "C" {
51 #endif
52 
53 /*
54  * Fundamental variables; don't change too often.
55  */
56 
57 /*
58  * _POSIX_VDISABLE has historically been defined in <sys/param.h> since
59  * an early merge with AT&T source.  It has also historically been defined
60  * in <sys/termios.h>. The POSIX standard, IEEE Std. 1003.1-1988 initially
61  * required the existence of _POSIX_VDISABLE in <sys/termios.h>.
62  * Subsequent versions of the IEEE Standard as well as the X/Open
63  * specifications required that _POSIX_VDISABLE be defined in <unistd.h>
64  * while still allowing for it's existence in other headers.  With the
65  * introduction of XPG6, _POSIX_VDISABLE can only be defined in <unistd.h>.
66  */
67 #if !defined(_XPG6) || defined(__EXTENSIONS__)
68 #ifndef	_POSIX_VDISABLE
69 #define	_POSIX_VDISABLE 0	/* Disable special character functions */
70 #endif
71 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
72 
73 #ifndef	MAX_INPUT
74 #define	MAX_INPUT	512	/* Maximum bytes stored in the input queue */
75 #endif
76 
77 #ifndef	MAX_CANON
78 #define	MAX_CANON	256	/* Maximum bytes for canonical processing */
79 #endif
80 
81 #define	UID_NOBODY	60001	/* user ID no body */
82 #define	GID_NOBODY	UID_NOBODY
83 #define	UID_UNKNOWN	96
84 #define	GID_UNKNOWN	UID_UNKNOWN
85 #define	UID_DLADM	15
86 #define	UID_NETADM	16
87 #define	GID_NETADM	65
88 #define	UID_NOACCESS	60002	/* user ID no access */
89 
90 #ifdef _KERNEL
91 #define	MAX_TASKID	999999
92 #define	MAX_MAXPID	999999
93 #define	MAXEPHUID	0xfffffffcu	/* max ephemeral user id */
94 
95 #define	FAMOUS_PID_SCHED	0
96 #define	FAMOUS_PID_INIT		1
97 #define	FAMOUS_PID_PAGEOUT	2
98 #define	FAMOUS_PID_FSFLUSH	3
99 #define	FAMOUS_PIDS		4
100 #endif
101 
102 #ifdef DEBUG
103 #define	DEFAULT_MAXPID	999999
104 #define	DEFAULT_JUMPPID	100000
105 #else
106 #define	DEFAULT_MAXPID	30000
107 #define	DEFAULT_JUMPPID	0
108 #endif
109 
110 #define	MAXUID		2147483647	/* max user id */
111 
112 #define	MAXPROJID	MAXUID		/* max project id */
113 #define	MAXLINK		32767	/* max links */
114 
115 #define	MINEPHUID	0x80000000u	/* min ephemeral user id */
116 
117 #define	NMOUNT		40	/* est. of # mountable fs for quota calc */
118 
119 #define	CANBSIZ		256	/* max size of typewriter line	*/
120 
121 #define	NOFILE		20	/* this define is here for	*/
122 				/* compatibility purposes only	*/
123 				/* and will be removed in a	*/
124 				/* later release		*/
125 
126 /*
127  * These define the maximum and minimum allowable values of the
128  * configurable parameter NGROUPS_MAX.
129  */
130 #define	NGROUPS_UMIN	0
131 #define	NGROUPS_UMAX	1024
132 #define	NGROUPS_OLDMAX	32
133 
134 /*
135  * NGROUPS_MAX_DEFAULT: *MUST* match NGROUPS_MAX value in limits.h.
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 _ncpu_log2;
384 extern const int _ncpu_p2;
385 extern const int _clsize;
386 #endif	/* defined(_KERNEL) && !defined(_ASM) */
387 
388 /* Any additions to these #defines must be reflected in mdb_param.h+mdb_ks.c */
389 #define	PAGESIZE	_pagesize
390 #define	PAGESHIFT	_pageshift
391 #define	PAGEOFFSET	_pageoffset
392 #define	PAGEMASK	_pagemask
393 #define	MMU_PAGESIZE	_mmu_pagesize
394 #define	MMU_PAGESHIFT	_mmu_pageshift
395 #define	MMU_PAGEOFFSET	_mmu_pageoffset
396 #define	MMU_PAGEMASK	_mmu_pagemask
397 
398 #define	KERNELBASE	_kernelbase
399 #define	USERLIMIT	_userlimit
400 #define	USERLIMIT32	_userlimit32
401 #define	ARGSBASE	_argsbase
402 #define	DEFAULTSTKSZ	_defaultstksz
403 #define	NCPU		_ncpu
404 #define	NCPU_LOG2	_ncpu_log2
405 #define	NCPU_P2		_ncpu_p2
406 
407 #endif	/* defined(_MACHDEP) */
408 
409 /*
410  * Some random macros for units conversion.
411  *
412  * These are machine independent but contain constants (*PAGESHIFT) which
413  * are only defined in the machine dependent file.
414  */
415 
416 /*
417  * MMU pages to bytes, and back (with and without rounding)
418  */
419 #define	mmu_ptob(x)	((x) << MMU_PAGESHIFT)
420 #define	mmu_btop(x)	(((x)) >> MMU_PAGESHIFT)
421 #define	mmu_btopr(x)	((((x) + MMU_PAGEOFFSET) >> MMU_PAGESHIFT))
422 
423 /*
424  * 2 versions of pages to disk blocks
425  */
426 #define	mmu_ptod(x)	((x) << (MMU_PAGESHIFT - DEV_BSHIFT))
427 #define	ptod(x)		((x) << (PAGESHIFT - DEV_BSHIFT))
428 
429 /*
430  * pages to bytes, and back (with and without rounding)
431  * Large Files: The explicit cast of x to unsigned int is deliberately
432  * removed as part of large files work. We pass longlong values to
433  * theses macros.
434  *
435  * Cast the input to ptob() to be a page count. This enforces 64-bit
436  * math on 64-bit kernels. For 32-bit kernels, callers must explicitly
437  * cast the input to be a 64-bit type if values greater than 4GB/PAGESIZE
438  * are possible.
439  */
440 
441 #ifdef _LP64
442 #define	ptob(x)		(((pgcnt_t)(x)) << PAGESHIFT)
443 #else
444 #define	ptob(x)		((x) << PAGESHIFT)
445 #endif /* _LP64 */
446 #define	btop(x)		(((x) >> PAGESHIFT))
447 #define	btopr(x)	((((x) + PAGEOFFSET) >> PAGESHIFT))
448 
449 /*
450  * disk blocks to pages, rounded and truncated
451  */
452 #define	NDPP		(PAGESIZE/DEV_BSIZE)	/* # of disk blocks per page */
453 #define	dtop(DD)	(((DD) + NDPP - 1) >> (PAGESHIFT - DEV_BSHIFT))
454 #define	dtopt(DD)	((DD) >> (PAGESHIFT - DEV_BSHIFT))
455 
456 /*
457  * kB to pages and back
458  */
459 #define	kbtop(x)	((x) >> (PAGESHIFT - 10))
460 #define	ptokb(x)	((x) << (PAGESHIFT - 10))
461 
462 /*
463  * POSIX.4 related configuration parameters
464  */
465 #define	_AIO_LISTIO_MAX		(4096)
466 #define	_AIO_MAX		(-1)
467 #define	_MQ_OPEN_MAX		(-1)
468 #define	_MQ_PRIO_MAX		(32)
469 #define	_SEM_NSEMS_MAX		INT_MAX
470 #define	_SEM_VALUE_MAX		INT_MAX
471 
472 #ifdef	__cplusplus
473 }
474 #endif
475 
476 #else	/* (defined(_KERNEL) || defined(_KMEMUSER)) */
477 
478 /*
479  * The following are assorted machine dependent values which can be
480  * obtained in a machine independent manner through sysconf(2) or
481  * sysinfo(2). In order to guarantee that these provide the expected
482  * value at all times, the System Private interface (leading underscore)
483  * is used.
484  */
485 
486 #include <sys/unistd.h>
487 
488 #ifdef	__cplusplus
489 extern "C" {
490 #endif
491 
492 #if !defined(_ASM)
493 extern long _sysconf(int);	/* System Private interface to sysconf() */
494 #endif	/* !defined(_ASM) */
495 
496 #define	HZ		((clock_t)_sysconf(_SC_CLK_TCK))
497 #define	TICK		(1000000000/((clock_t)_sysconf(_SC_CLK_TCK)))
498 #define	PAGESIZE	(_sysconf(_SC_PAGESIZE))
499 #define	PAGEOFFSET	(PAGESIZE - 1)
500 #define	PAGEMASK	(~PAGEOFFSET)
501 #define	MAXPID		((pid_t)_sysconf(_SC_MAXPID))
502 #define	MAXEPHUID	((uid_t)_sysconf(_SC_EPHID_MAX))
503 
504 #ifdef	__cplusplus
505 }
506 #endif
507 
508 #endif	/* (defined(_KERNEL) || defined(_KMEMUSER)) &&  defined(_MACHDEP) */
509 
510 #endif	/* _SYS_PARAM_H */
511