xref: /xnu-11215.81.4/bsd/sys/param.h (revision d4514f0bc1d3f944c22d92e68b646ac3fb40d452)
1*d4514f0bSApple OSS Distributions /*
2*d4514f0bSApple OSS Distributions  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3*d4514f0bSApple OSS Distributions  *
4*d4514f0bSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*d4514f0bSApple OSS Distributions  *
6*d4514f0bSApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*d4514f0bSApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*d4514f0bSApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*d4514f0bSApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*d4514f0bSApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*d4514f0bSApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*d4514f0bSApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*d4514f0bSApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*d4514f0bSApple OSS Distributions  *
15*d4514f0bSApple OSS Distributions  * Please obtain a copy of the License at
16*d4514f0bSApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*d4514f0bSApple OSS Distributions  *
18*d4514f0bSApple OSS Distributions  * The Original Code and all software distributed under the License are
19*d4514f0bSApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*d4514f0bSApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*d4514f0bSApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*d4514f0bSApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*d4514f0bSApple OSS Distributions  * Please see the License for the specific language governing rights and
24*d4514f0bSApple OSS Distributions  * limitations under the License.
25*d4514f0bSApple OSS Distributions  *
26*d4514f0bSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*d4514f0bSApple OSS Distributions  */
28*d4514f0bSApple OSS Distributions /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
29*d4514f0bSApple OSS Distributions /*-
30*d4514f0bSApple OSS Distributions  * Copyright (c) 1982, 1986, 1989, 1993
31*d4514f0bSApple OSS Distributions  *	The Regents of the University of California.  All rights reserved.
32*d4514f0bSApple OSS Distributions  * (c) UNIX System Laboratories, Inc.
33*d4514f0bSApple OSS Distributions  * All or some portions of this file are derived from material licensed
34*d4514f0bSApple OSS Distributions  * to the University of California by American Telephone and Telegraph
35*d4514f0bSApple OSS Distributions  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36*d4514f0bSApple OSS Distributions  * the permission of UNIX System Laboratories, Inc.
37*d4514f0bSApple OSS Distributions  *
38*d4514f0bSApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
39*d4514f0bSApple OSS Distributions  * modification, are permitted provided that the following conditions
40*d4514f0bSApple OSS Distributions  * are met:
41*d4514f0bSApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
42*d4514f0bSApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
43*d4514f0bSApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
44*d4514f0bSApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
45*d4514f0bSApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
46*d4514f0bSApple OSS Distributions  * 3. All advertising materials mentioning features or use of this software
47*d4514f0bSApple OSS Distributions  *    must display the following acknowledgement:
48*d4514f0bSApple OSS Distributions  *	This product includes software developed by the University of
49*d4514f0bSApple OSS Distributions  *	California, Berkeley and its contributors.
50*d4514f0bSApple OSS Distributions  * 4. Neither the name of the University nor the names of its contributors
51*d4514f0bSApple OSS Distributions  *    may be used to endorse or promote products derived from this software
52*d4514f0bSApple OSS Distributions  *    without specific prior written permission.
53*d4514f0bSApple OSS Distributions  *
54*d4514f0bSApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55*d4514f0bSApple OSS Distributions  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56*d4514f0bSApple OSS Distributions  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57*d4514f0bSApple OSS Distributions  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58*d4514f0bSApple OSS Distributions  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59*d4514f0bSApple OSS Distributions  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60*d4514f0bSApple OSS Distributions  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61*d4514f0bSApple OSS Distributions  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62*d4514f0bSApple OSS Distributions  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63*d4514f0bSApple OSS Distributions  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64*d4514f0bSApple OSS Distributions  * SUCH DAMAGE.
65*d4514f0bSApple OSS Distributions  *
66*d4514f0bSApple OSS Distributions  *	@(#)param.h	8.3 (Berkeley) 4/4/95
67*d4514f0bSApple OSS Distributions  */
68*d4514f0bSApple OSS Distributions 
69*d4514f0bSApple OSS Distributions #ifndef _SYS_PARAM_H_
70*d4514f0bSApple OSS Distributions #define _SYS_PARAM_H_
71*d4514f0bSApple OSS Distributions 
72*d4514f0bSApple OSS Distributions #define BSD     199506          /* System version (year & month). */
73*d4514f0bSApple OSS Distributions #define BSD4_3  1
74*d4514f0bSApple OSS Distributions #define BSD4_4  1
75*d4514f0bSApple OSS Distributions 
76*d4514f0bSApple OSS Distributions #define NeXTBSD 1995064         /* NeXTBSD version (year, month, release) */
77*d4514f0bSApple OSS Distributions #define NeXTBSD4_0 0            /* NeXTBSD 4.0 */
78*d4514f0bSApple OSS Distributions 
79*d4514f0bSApple OSS Distributions #include <sys/_types.h>
80*d4514f0bSApple OSS Distributions #include <sys/_types/_null.h>
81*d4514f0bSApple OSS Distributions 
82*d4514f0bSApple OSS Distributions #ifndef LOCORE
83*d4514f0bSApple OSS Distributions #include <sys/types.h>
84*d4514f0bSApple OSS Distributions #endif
85*d4514f0bSApple OSS Distributions 
86*d4514f0bSApple OSS Distributions /*
87*d4514f0bSApple OSS Distributions  * Machine-independent constants (some used in following include files).
88*d4514f0bSApple OSS Distributions  * Redefined constants are from POSIX 1003.1 limits file.
89*d4514f0bSApple OSS Distributions  *
90*d4514f0bSApple OSS Distributions  * MAXCOMLEN should be >= sizeof(ac_comm) (see <acct.h>)
91*d4514f0bSApple OSS Distributions  * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>)
92*d4514f0bSApple OSS Distributions  */
93*d4514f0bSApple OSS Distributions #include <sys/syslimits.h>
94*d4514f0bSApple OSS Distributions 
95*d4514f0bSApple OSS Distributions #define MAXCOMLEN       16              /* max command name remembered */
96*d4514f0bSApple OSS Distributions #define MAXINTERP       64              /* max interpreter file name length */
97*d4514f0bSApple OSS Distributions #define MAXLOGNAME      255             /* max login name length */
98*d4514f0bSApple OSS Distributions #define MAXUPRC         CHILD_MAX       /* max simultaneous processes */
99*d4514f0bSApple OSS Distributions #define NCARGS          ARG_MAX         /* max bytes for an exec function */
100*d4514f0bSApple OSS Distributions #define NGROUPS         NGROUPS_MAX     /* max number groups */
101*d4514f0bSApple OSS Distributions #define NOFILE          256             /* default max open files per process */
102*d4514f0bSApple OSS Distributions #define NOGROUP         65535           /* marker for empty group set member */
103*d4514f0bSApple OSS Distributions #define MAXHOSTNAMELEN  256             /* max hostname size */
104*d4514f0bSApple OSS Distributions #define MAXDOMNAMELEN   256             /* maximum domain name length */
105*d4514f0bSApple OSS Distributions 
106*d4514f0bSApple OSS Distributions /* Machine type dependent parameters. */
107*d4514f0bSApple OSS Distributions #include <machine/param.h>
108*d4514f0bSApple OSS Distributions 
109*d4514f0bSApple OSS Distributions /* More types and definitions used throughout the kernel. */
110*d4514f0bSApple OSS Distributions #ifdef KERNEL
111*d4514f0bSApple OSS Distributions #include <machine/limits.h>
112*d4514f0bSApple OSS Distributions #include <sys/cdefs.h>
113*d4514f0bSApple OSS Distributions #include <sys/errno.h>
114*d4514f0bSApple OSS Distributions #include <sys/time.h>
115*d4514f0bSApple OSS Distributions #include <sys/resource.h>
116*d4514f0bSApple OSS Distributions #include <sys/ucred.h>
117*d4514f0bSApple OSS Distributions #include <sys/uio.h>
118*d4514f0bSApple OSS Distributions #else
119*d4514f0bSApple OSS Distributions #include <limits.h>
120*d4514f0bSApple OSS Distributions #endif
121*d4514f0bSApple OSS Distributions 
122*d4514f0bSApple OSS Distributions /* Signals. */
123*d4514f0bSApple OSS Distributions #include <sys/signal.h>
124*d4514f0bSApple OSS Distributions 
125*d4514f0bSApple OSS Distributions /*
126*d4514f0bSApple OSS Distributions  * Priorities.  Note that with 32 run queues, differences less than 4 are
127*d4514f0bSApple OSS Distributions  * insignificant.
128*d4514f0bSApple OSS Distributions  */
129*d4514f0bSApple OSS Distributions #define PSWP    0
130*d4514f0bSApple OSS Distributions #define PVM     4
131*d4514f0bSApple OSS Distributions #define PINOD   8
132*d4514f0bSApple OSS Distributions #define PRIBIO  16
133*d4514f0bSApple OSS Distributions #define PVFS    20
134*d4514f0bSApple OSS Distributions #define PZERO   22              /* No longer magic, shouldn't be here.  XXX */
135*d4514f0bSApple OSS Distributions #define PSOCK   24
136*d4514f0bSApple OSS Distributions #define PWAIT   32
137*d4514f0bSApple OSS Distributions #define PLOCK   36
138*d4514f0bSApple OSS Distributions #define PPAUSE  40
139*d4514f0bSApple OSS Distributions #define PUSER   50
140*d4514f0bSApple OSS Distributions #define MAXPRI  127             /* Priorities range from 0 through MAXPRI. */
141*d4514f0bSApple OSS Distributions 
142*d4514f0bSApple OSS Distributions #define PRIMASK 0x0ff
143*d4514f0bSApple OSS Distributions #define PCATCH  0x100           /* OR'd with pri for tsleep to check signals */
144*d4514f0bSApple OSS Distributions #define PTTYBLOCK 0x200         /* for tty SIGTTOU and SIGTTIN blocking */
145*d4514f0bSApple OSS Distributions #define PDROP   0x400           /* OR'd with pri to stop re-aquistion of mutex upon wakeup */
146*d4514f0bSApple OSS Distributions #define PSPIN   0x800           /* OR'd with pri to require mutex in spin mode upon wakeup */
147*d4514f0bSApple OSS Distributions 
148*d4514f0bSApple OSS Distributions #define NBPW    sizeof(int)     /* number of bytes per word (integer) */
149*d4514f0bSApple OSS Distributions 
150*d4514f0bSApple OSS Distributions #define CMASK   022             /* default file mask: S_IWGRP|S_IWOTH */
151*d4514f0bSApple OSS Distributions #define NODEV   (dev_t)(-1)     /* non-existent device */
152*d4514f0bSApple OSS Distributions 
153*d4514f0bSApple OSS Distributions /*
154*d4514f0bSApple OSS Distributions  * Clustering of hardware pages on machines with ridiculously small
155*d4514f0bSApple OSS Distributions  * page sizes is done here.  The paging subsystem deals with units of
156*d4514f0bSApple OSS Distributions  * CLSIZE pte's describing NBPG (from machine/param.h) pages each.
157*d4514f0bSApple OSS Distributions  */
158*d4514f0bSApple OSS Distributions #define CLBYTES         (CLSIZE*NBPG)
159*d4514f0bSApple OSS Distributions #define CLOFSET         (CLSIZE*NBPG-1) /* for clusters, like PGOFSET */
160*d4514f0bSApple OSS Distributions #define claligned(x)    ((((int)(x))&CLOFSET)==0)
161*d4514f0bSApple OSS Distributions #define CLOFF           CLOFSET
162*d4514f0bSApple OSS Distributions #define CLSHIFT         (PGSHIFT+CLSIZELOG2)
163*d4514f0bSApple OSS Distributions 
164*d4514f0bSApple OSS Distributions #if CLSIZE == 1
165*d4514f0bSApple OSS Distributions #define clbase(i)       (i)
166*d4514f0bSApple OSS Distributions #define clrnd(i)        (i)
167*d4514f0bSApple OSS Distributions #else
168*d4514f0bSApple OSS Distributions /* Give the base virtual address (first of CLSIZE). */
169*d4514f0bSApple OSS Distributions #define clbase(i)       ((i) &~ (CLSIZE-1))
170*d4514f0bSApple OSS Distributions /* Round a number of clicks up to a whole cluster. */
171*d4514f0bSApple OSS Distributions #define clrnd(i)        (((i) + (CLSIZE-1)) &~ (CLSIZE-1))
172*d4514f0bSApple OSS Distributions #endif
173*d4514f0bSApple OSS Distributions 
174*d4514f0bSApple OSS Distributions #define CBLOCK  64              /* Clist block size, must be a power of 2. */
175*d4514f0bSApple OSS Distributions #define CBQSIZE (CBLOCK/NBBY)   /* Quote bytes/cblock - can do better. */
176*d4514f0bSApple OSS Distributions                                 /* Data chars/clist. */
177*d4514f0bSApple OSS Distributions #define CBSIZE  (CBLOCK - sizeof(struct cblock *) - CBQSIZE)
178*d4514f0bSApple OSS Distributions #define CROUND  (CBLOCK - 1)    /* Clist rounding. */
179*d4514f0bSApple OSS Distributions 
180*d4514f0bSApple OSS Distributions /*
181*d4514f0bSApple OSS Distributions  * File system parameters and macros.
182*d4514f0bSApple OSS Distributions  *
183*d4514f0bSApple OSS Distributions  * The file system is made out of blocks of at most MAXPHYS units, with
184*d4514f0bSApple OSS Distributions  * smaller units (fragments) only in the last direct block.  MAXBSIZE
185*d4514f0bSApple OSS Distributions  * primarily determines the size of buffers in the buffer pool.  It may be
186*d4514f0bSApple OSS Distributions  * made larger than MAXPHYS without any effect on existing file systems;
187*d4514f0bSApple OSS Distributions  * however making it smaller may make some file systems unmountable.
188*d4514f0bSApple OSS Distributions  * We set this to track the value of MAX_UPL_TRANSFER_BYTES from
189*d4514f0bSApple OSS Distributions  * osfmk/mach/memory_object_types.h to bound it at the maximum UPL size.
190*d4514f0bSApple OSS Distributions  */
191*d4514f0bSApple OSS Distributions #define MAXBSIZE        (256 * 4096)
192*d4514f0bSApple OSS Distributions #define MAXPHYSIO       MAXPHYS
193*d4514f0bSApple OSS Distributions #define MAXFRAG         8
194*d4514f0bSApple OSS Distributions 
195*d4514f0bSApple OSS Distributions #define MAXPHYSIO_WIRED (16 * 1024 * 1024)
196*d4514f0bSApple OSS Distributions 
197*d4514f0bSApple OSS Distributions /*
198*d4514f0bSApple OSS Distributions  * MAXPATHLEN defines the longest permissable path length after expanding
199*d4514f0bSApple OSS Distributions  * symbolic links. It is used to allocate a temporary buffer from the buffer
200*d4514f0bSApple OSS Distributions  * pool in which to do the name expansion, hence should be a power of two,
201*d4514f0bSApple OSS Distributions  * and must be less than or equal to MAXBSIZE.  MAXSYMLINKS defines the
202*d4514f0bSApple OSS Distributions  * maximum number of symbolic links that may be expanded in a path name.
203*d4514f0bSApple OSS Distributions  * It should be set high enough to allow all legitimate uses, but halt
204*d4514f0bSApple OSS Distributions  * infinite loops reasonably quickly.
205*d4514f0bSApple OSS Distributions  */
206*d4514f0bSApple OSS Distributions #define MAXPATHLEN      PATH_MAX
207*d4514f0bSApple OSS Distributions #define MAXSYMLINKS     32
208*d4514f0bSApple OSS Distributions 
209*d4514f0bSApple OSS Distributions /* Bit map related macros. */
210*d4514f0bSApple OSS Distributions #define setbit(a, i)     (((unsigned char *)(a))[(i)/NBBY] |= 1u<<((i)%NBBY))
211*d4514f0bSApple OSS Distributions #define clrbit(a, i)     (((unsigned char *)(a))[(i)/NBBY] &= ~(1u<<((i)%NBBY)))
212*d4514f0bSApple OSS Distributions #define isset(a, i)      (((unsigned char *)(a))[(i)/NBBY] & (1u<<((i)%NBBY)))
213*d4514f0bSApple OSS Distributions #define isclr(a, i)      ((((unsigned char *)(a))[(i)/NBBY] & (1u<<((i)%NBBY))) == 0)
214*d4514f0bSApple OSS Distributions 
215*d4514f0bSApple OSS Distributions /* Macros for counting and rounding. */
216*d4514f0bSApple OSS Distributions #ifndef howmany
217*d4514f0bSApple OSS Distributions #define howmany(x, y)   ((((x) % (y)) == 0) ? ((x) / (y)) : (((x) / (y)) + 1))
218*d4514f0bSApple OSS Distributions #endif
219*d4514f0bSApple OSS Distributions #define roundup(x, y)   ((((x) % (y)) == 0) ? \
220*d4514f0bSApple OSS Distributions 	                (x) : ((x) + ((y) - ((x) % (y)))))
221*d4514f0bSApple OSS Distributions #define powerof2(x)     ((((x)-1)&(x))==0)
222*d4514f0bSApple OSS Distributions 
223*d4514f0bSApple OSS Distributions /* Macros for min/max. */
224*d4514f0bSApple OSS Distributions #ifndef MIN
225*d4514f0bSApple OSS Distributions #define MIN(a, b) (((a)<(b))?(a):(b))
226*d4514f0bSApple OSS Distributions #endif /* MIN */
227*d4514f0bSApple OSS Distributions #ifndef MAX
228*d4514f0bSApple OSS Distributions #define MAX(a, b) (((a)>(b))?(a):(b))
229*d4514f0bSApple OSS Distributions #endif  /* MAX */
230*d4514f0bSApple OSS Distributions 
231*d4514f0bSApple OSS Distributions /*
232*d4514f0bSApple OSS Distributions  * Scale factor for scaled integers used to count %cpu time and load avgs.
233*d4514f0bSApple OSS Distributions  *
234*d4514f0bSApple OSS Distributions  * The number of CPU `tick's that map to a unique `%age' can be expressed
235*d4514f0bSApple OSS Distributions  * by the formula (1 / (2 ^ (FSHIFT - 11))).  The maximum load average that
236*d4514f0bSApple OSS Distributions  * can be calculated (assuming 32 bits) can be closely approximated using
237*d4514f0bSApple OSS Distributions  * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15).
238*d4514f0bSApple OSS Distributions  *
239*d4514f0bSApple OSS Distributions  * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age',
240*d4514f0bSApple OSS Distributions  * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024.
241*d4514f0bSApple OSS Distributions  */
242*d4514f0bSApple OSS Distributions #define FSHIFT  11              /* bits to right of fixed binary point */
243*d4514f0bSApple OSS Distributions #define FSCALE  (1<<FSHIFT)
244*d4514f0bSApple OSS Distributions 
245*d4514f0bSApple OSS Distributions #endif  /* _SYS_PARAM_H_ */
246