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