1204076Spjd/*
2204076Spjd * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3210886Spjd *
4204076Spjd * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5204076Spjd *
6204076Spjd * This file contains Original Code and/or Modifications of Original Code
7204076Spjd * as defined in and that are subject to the Apple Public Source License
8204076Spjd * Version 2.0 (the 'License'). You may not use this file except in
9204076Spjd * compliance with the License. The rights granted to you under the License
10204076Spjd * may not be used to create, or enable the creation or redistribution of,
11204076Spjd * unlawful or unlicensed copies of an Apple operating system, or to
12204076Spjd * circumvent, violate, or enable the circumvention or violation of, any
13204076Spjd * terms of an Apple operating system software license agreement.
14204076Spjd *
15204076Spjd * Please obtain a copy of the License at
16204076Spjd * http://www.opensource.apple.com/apsl/ and read it before using this file.
17204076Spjd *
18204076Spjd * The Original Code and all software distributed under the License are
19204076Spjd * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20204076Spjd * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21204076Spjd * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22204076Spjd * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23204076Spjd * Please see the License for the specific language governing rights and
24204076Spjd * limitations under the License.
25204076Spjd *
26204076Spjd * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27204076Spjd */
28204076Spjd/* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
29204076Spjd/*-
30204076Spjd * Copyright (c) 1982, 1986, 1989, 1993
31204076Spjd *	The Regents of the University of California.  All rights reserved.
32204076Spjd * (c) UNIX System Laboratories, Inc.
33204076Spjd * All or some portions of this file are derived from material licensed
34204076Spjd * to the University of California by American Telephone and Telegraph
35204076Spjd * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36204076Spjd * the permission of UNIX System Laboratories, Inc.
37204076Spjd *
38204076Spjd * Redistribution and use in source and binary forms, with or without
39204076Spjd * modification, are permitted provided that the following conditions
40204076Spjd * are met:
41204076Spjd * 1. Redistributions of source code must retain the above copyright
42204076Spjd *    notice, this list of conditions and the following disclaimer.
43204076Spjd * 2. Redistributions in binary form must reproduce the above copyright
44204076Spjd *    notice, this list of conditions and the following disclaimer in the
45204076Spjd *    documentation and/or other materials provided with the distribution.
46204076Spjd * 3. All advertising materials mentioning features or use of this software
47204076Spjd *    must display the following acknowledgement:
48204076Spjd *	This product includes software developed by the University of
49211982Spjd *	California, Berkeley and its contributors.
50204076Spjd * 4. Neither the name of the University nor the names of its contributors
51204076Spjd *    may be used to endorse or promote products derived from this software
52204076Spjd *    without specific prior written permission.
53204076Spjd *
54204076Spjd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55204076Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56204076Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57204076Spjd * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58204076Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59204076Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60204076Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61212038Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62204076Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63204076Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64204076Spjd * SUCH DAMAGE.
65211886Spjd *
66204076Spjd *	@(#)param.h	8.3 (Berkeley) 4/4/95
67204076Spjd */
68204076Spjd
69204076Spjd#ifndef	_SYS_PARAM_H_
70204076Spjd#define _SYS_PARAM_H_
71204076Spjd
72210886Spjd#define	BSD	199506		/* System version (year & month). */
73210886Spjd#define BSD4_3	1
74210886Spjd#define BSD4_4	1
75204076Spjd
76204076Spjd#define NeXTBSD	1995064		/* NeXTBSD version (year, month, release) */
77204076Spjd#define NeXTBSD4_0 0		/* NeXTBSD 4.0 */
78204076Spjd
79204076Spjd#include <sys/_types.h>
80204076Spjd
81204076Spjd#ifndef NULL
82204076Spjd#define	NULL	__DARWIN_NULL
83204076Spjd#endif /* ! NULL */
84204076Spjd
85204076Spjd#ifndef LOCORE
86204076Spjd#include <sys/types.h>
87204076Spjd#endif
88204076Spjd
89204076Spjd/*
90204076Spjd * Machine-independent constants (some used in following include files).
91204076Spjd * Redefined constants are from POSIX 1003.1 limits file.
92204076Spjd *
93204076Spjd * MAXCOMLEN should be >= sizeof(ac_comm) (see <acct.h>)
94204076Spjd * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>)
95204076Spjd */
96204076Spjd#include <sys/syslimits.h>
97204076Spjd
98204076Spjd#define	MAXCOMLEN	16		/* max command name remembered */
99204076Spjd#define	MAXINTERP	64		/* max interpreter file name length */
100204076Spjd#define	MAXLOGNAME	255		/* max login name length */
101204076Spjd#define	MAXUPRC		CHILD_MAX	/* max simultaneous processes */
102204076Spjd#define	NCARGS		ARG_MAX		/* max bytes for an exec function */
103204076Spjd#define	NGROUPS		NGROUPS_MAX	/* max number groups */
104204076Spjd#define	NOFILE		256		/* default max open files per process */
105204076Spjd#define	NOGROUP		65535		/* marker for empty group set member */
106204076Spjd#define MAXHOSTNAMELEN	256		/* max hostname size */
107204076Spjd#define MAXDOMNAMELEN	256		/* maximum domain name length */
108204076Spjd
109204076Spjd/* Machine type dependent parameters. */
110204076Spjd#include <machine/param.h>
111204076Spjd
112204076Spjd/* More types and definitions used throughout the kernel. */
113204076Spjd#ifdef KERNEL
114204076Spjd#include <machine/limits.h>
115204076Spjd#include <sys/cdefs.h>
116204076Spjd#include <sys/errno.h>
117204076Spjd#include <sys/time.h>
118204076Spjd#include <sys/resource.h>
119204076Spjd#include <sys/ucred.h>
120204076Spjd#include <sys/uio.h>
121204076Spjd#else
122204076Spjd#include <limits.h>
123204076Spjd#endif
124204076Spjd
125204076Spjd/* Signals. */
126204076Spjd#include <sys/signal.h>
127204076Spjd
128204076Spjd/*
129204076Spjd * Priorities.  Note that with 32 run queues, differences less than 4 are
130204076Spjd * insignificant.
131204076Spjd */
132204076Spjd#define	PSWP	0
133204076Spjd#define	PVM	4
134204076Spjd#define	PINOD	8
135204076Spjd#define	PRIBIO	16
136204076Spjd#define	PVFS	20
137204076Spjd#define	PZERO	22		/* No longer magic, shouldn't be here.  XXX */
138204076Spjd#define	PSOCK	24
139204076Spjd#define	PWAIT	32
140204076Spjd#define	PLOCK	36
141204076Spjd#define	PPAUSE	40
142204076Spjd#define	PUSER	50
143204076Spjd#define	MAXPRI	127		/* Priorities range from 0 through MAXPRI. */
144204076Spjd
145204076Spjd#define	PRIMASK	0x0ff
146204076Spjd#define	PCATCH	0x100		/* OR'd with pri for tsleep to check signals */
147204076Spjd#define PTTYBLOCK 0x200		/* for tty SIGTTOU and SIGTTIN blocking */
148204076Spjd#define PDROP	0x400		/* OR'd with pri to stop re-aquistion of mutex upon wakeup */
149204076Spjd#define PSPIN	0x800		/* OR'd with pri to require mutex in spin mode upon wakeup */
150204076Spjd
151204076Spjd#define	NBPW	sizeof(int)	/* number of bytes per word (integer) */
152204076Spjd
153204076Spjd#define	CMASK	022		/* default file mask: S_IWGRP|S_IWOTH */
154204076Spjd#define	NODEV	(dev_t)(-1)	/* non-existent device */
155211982Spjd
156204076Spjd/*
157211982Spjd * Clustering of hardware pages on machines with ridiculously small
158204076Spjd * page sizes is done here.  The paging subsystem deals with units of
159204076Spjd * CLSIZE pte's describing NBPG (from machine/param.h) pages each.
160204076Spjd */
161204076Spjd#define	CLBYTES		(CLSIZE*NBPG)
162204076Spjd#define	CLOFSET		(CLSIZE*NBPG-1)	/* for clusters, like PGOFSET */
163204076Spjd#define	claligned(x)	((((int)(x))&CLOFSET)==0)
164204076Spjd#define	CLOFF		CLOFSET
165204076Spjd#define	CLSHIFT		(PGSHIFT+CLSIZELOG2)
166204076Spjd
167204076Spjd#if CLSIZE==1
168204076Spjd#define	clbase(i)	(i)
169204076Spjd#define	clrnd(i)	(i)
170204076Spjd#else
171204076Spjd/* Give the base virtual address (first of CLSIZE). */
172204076Spjd#define	clbase(i)	((i) &~ (CLSIZE-1))
173204076Spjd/* Round a number of clicks up to a whole cluster. */
174204076Spjd#define	clrnd(i)	(((i) + (CLSIZE-1)) &~ (CLSIZE-1))
175204076Spjd#endif
176204076Spjd
177204076Spjd#define	CBLOCK	64		/* Clist block size, must be a power of 2. */
178204076Spjd#define CBQSIZE	(CBLOCK/NBBY)	/* Quote bytes/cblock - can do better. */
179204076Spjd				/* Data chars/clist. */
180204076Spjd#define	CBSIZE	(CBLOCK - sizeof(struct cblock *) - CBQSIZE)
181204076Spjd#define	CROUND	(CBLOCK - 1)	/* Clist rounding. */
182204076Spjd
183204076Spjd/*
184204076Spjd * File system parameters and macros.
185204076Spjd *
186204076Spjd * The file system is made out of blocks of at most MAXPHYS units, with
187204076Spjd * smaller units (fragments) only in the last direct block.  MAXBSIZE
188204076Spjd * primarily determines the size of buffers in the buffer pool.  It may be
189204076Spjd * made larger than MAXPHYS without any effect on existing file systems;
190204076Spjd * however making it smaller may make some file systems unmountable.
191204076Spjd * We set this to track the value of (MAX_UPL_TRANSFER*PAGE_SIZE) from
192204076Spjd * osfmk/mach/memory_object_types.h to bound it at the maximum UPL size.
193204076Spjd */
194204076Spjd#define	MAXBSIZE	(256 * 4096)
195204076Spjd#define MAXPHYSIO	MAXPHYS
196204076Spjd#define MAXFRAG 	8
197204076Spjd
198204076Spjd#define	MAXPHYSIO_WIRED	(16 * 1024 * 1024)
199204076Spjd
200204076Spjd/*
201204076Spjd * MAXPATHLEN defines the longest permissable path length after expanding
202204076Spjd * symbolic links. It is used to allocate a temporary buffer from the buffer
203209183Spjd * pool in which to do the name expansion, hence should be a power of two,
204209183Spjd * and must be less than or equal to MAXBSIZE.  MAXSYMLINKS defines the
205209183Spjd * maximum number of symbolic links that may be expanded in a path name.
206209183Spjd * It should be set high enough to allow all legitimate uses, but halt
207204076Spjd * infinite loops reasonably quickly.
208204076Spjd */
209204076Spjd#define	MAXPATHLEN	PATH_MAX
210204076Spjd#define MAXSYMLINKS	32
211204076Spjd
212204076Spjd/* Bit map related macros. */
213204076Spjd#define	setbit(a,i)	(((char *)(a))[(i)/NBBY] |= 1<<((i)%NBBY))
214204076Spjd#define	clrbit(a,i)	(((char *)(a))[(i)/NBBY] &= ~(1<<((i)%NBBY)))
215204076Spjd#define	isset(a,i)	(((char *)(a))[(i)/NBBY] & (1<<((i)%NBBY)))
216204076Spjd#define	isclr(a,i)	((((char *)(a))[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
217204076Spjd
218204076Spjd/* Macros for counting and rounding. */
219204076Spjd#ifndef howmany
220204076Spjd#define	howmany(x, y)	((((x) % (y)) == 0) ? ((x) / (y)) : (((x) / (y)) + 1))
221204076Spjd#endif
222204076Spjd#define	roundup(x, y)	((((x)+((y)-1))/(y))*(y))
223204076Spjd#define powerof2(x)	((((x)-1)&(x))==0)
224204076Spjd
225204076Spjd/* Macros for min/max. */
226204076Spjd#ifndef MIN
227204076Spjd#define	MIN(a,b) (((a)<(b))?(a):(b))
228204076Spjd#endif /* MIN */
229211982Spjd#ifndef MAX
230204076Spjd#define	MAX(a,b) (((a)>(b))?(a):(b))
231204076Spjd#endif	/* MAX */
232204076Spjd
233204076Spjd/*
234204076Spjd * Constants for setting the parameters of the kernel memory allocator.
235204076Spjd *
236204076Spjd * 2 ** MINBUCKET is the smallest unit of memory that will be
237204076Spjd * allocated. It must be at least large enough to hold a pointer.
238204076Spjd *
239204076Spjd * Units of memory less or equal to MAXALLOCSAVE will permanently
240204076Spjd * allocate physical memory; requests for these size pieces of
241213533Spjd * memory are quite fast. Allocations greater than MAXALLOCSAVE must
242204076Spjd * always allocate and free physical memory; requests for these
243204076Spjd * size allocations should be done infrequently as they will be slow.
244204076Spjd *
245204076Spjd * Constraints: CLBYTES <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and
246213531Spjd * MAXALLOCSIZE must be a power of two.
247213531Spjd */
248204076Spjd#define MINBUCKET	4		/* 4 => min allocation of 16 bytes */
249204076Spjd#define MAXALLOCSAVE	(2 * CLBYTES)
250204076Spjd
251204076Spjd/*
252204076Spjd * Scale factor for scaled integers used to count %cpu time and load avgs.
253204076Spjd *
254204076Spjd * The number of CPU `tick's that map to a unique `%age' can be expressed
255204076Spjd * by the formula (1 / (2 ^ (FSHIFT - 11))).  The maximum load average that
256204076Spjd * can be calculated (assuming 32 bits) can be closely approximated using
257212899Spjd * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15).
258204076Spjd *
259204076Spjd * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age',
260204076Spjd * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024.
261204076Spjd */
262204076Spjd#define	FSHIFT	11		/* bits to right of fixed binary point */
263204076Spjd#define FSCALE	(1<<FSHIFT)
264204076Spjd
265204076Spjd#endif	/* _SYS_PARAM_H_ */
266204076Spjd