1/* $OpenBSD: param.h,v 1.146 2026/03/11 02:27:20 deraadt Exp $ */
2
3/*-
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#ifndef _SYS_PARAM_H_
38#define _SYS_PARAM_H_
39
40#define BSD 199306 /* System version (year & month). */
41#define BSD4_3 1
42#define BSD4_4 1
43
44/* zig patch: ___OpenBSD and OpenBSDX_Y are defined by the compiler */
45#define OpenBSD ___OpenBSD
46
47#include <sys/_null.h>
48
49#ifndef _LOCORE
50#include <sys/types.h>
51#endif
52
53/*
54 * Machine-independent constants (some used in following include files).
55 * Redefined constants are from POSIX 1003.1 limits file.
56 *
57 * MAXCOMLEN should be >= sizeof(ac_comm) (see <acct.h>)
58 * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>)
59 */
60#include <sys/syslimits.h>
61
62#define MAXCOMLEN _MAXCOMLEN-1 /* max command name remembered, without NUL */
63#define MAXINTERP 128 /* max interpreter file name length */
64#define MAXLOGNAME LOGIN_NAME_MAX /* max login name length w/ NUL */
65#define MAXUPRC CHILD_MAX /* max simultaneous processes */
66#define NCARGS ARG_MAX /* max bytes for an exec function */
67#define NGROUPS NGROUPS_MAX /* max number groups */
68#define NOFILE OPEN_MAX /* max open files per process (soft) */
69#define NOFILE_MAX 1024 /* max open files per process (hard) */
70#define NOGROUP 65535 /* marker for empty group set member */
71#define MAXHOSTNAMELEN 256 /* max hostname length w/ NUL */
72
73/* More types and definitions used throughout the kernel. */
74#ifdef _KERNEL
75#include <sys/errno.h>
76#include <sys/time.h>
77#include <sys/resource.h>
78#include <sys/ucred.h>
79#include <sys/uio.h>
80#include <sys/srp.h>
81#endif
82
83/* Signals. */
84#include <sys/signal.h>
85
86/* Machine type dependent parameters. */
87#include <sys/limits.h>
88#include <machine/param.h>
89
90#ifdef _KERNEL
91/*
92 * Priorities. Note that with 32 run queues, differences less than 4 are
93 * insignificant.
94 */
95#define PSWP 0
96#define PVM 4
97#define PINOD 8
98#define PRIBIO 16
99#define PVFS 20
100#endif /* _KERNEL */
101#define PZERO 22 /* No longer magic, shouldn't be here. XXX */
102#ifdef _KERNEL
103#define PSOCK 24
104#define PWAIT 32
105#define PLOCK 36
106#define PPAUSE 40
107#define PUSER 50
108#define MAXPRI 127 /* Priorities range from 0 through MAXPRI. */
109
110#define PRIMASK 0x0ff
111#define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */
112#define PNORELOCK 0x200 /* OR'd with pri for msleep to not reacquire
113 the mutex */
114#endif /* _KERNEL */
115
116#define NODEV (dev_t)(-1) /* non-existent device */
117
118#define ALIGNBYTES _ALIGNBYTES
119#define ALIGN(p) _ALIGN(p)
120#define ALIGNED_POINTER(p,t) _ALIGNED_POINTER(p,t)
121
122/*
123 * File system parameters and macros.
124 *
125 * The file system is made out of blocks of at most MAXBSIZE units, with
126 * smaller units (fragments) only in the last direct block. MAXBSIZE
127 * primarily determines the size of buffers in the buffer pool. It may be
128 * made larger without any effect on existing file systems; however making
129 * it smaller makes some file systems unmountable.
130 */
131#ifdef _KERNEL
132#define MAXPHYS (64 * 1024) /* max raw I/O transfer size */
133#endif /* _KERNEL */
134#define MAXBSIZE (64 * 1024)
135
136#define _DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
137#define DEV_BSIZE (1 << _DEV_BSHIFT)
138#ifdef _KERNEL
139#define DEV_BSHIFT _DEV_BSHIFT
140#define BLKDEV_IOSIZE PAGE_SIZE
141#endif /* _KERNEL */
142
143/* pages to disk blocks */
144#ifndef ctod
145#define ctod(x) ((x) << (PAGE_SHIFT - _DEV_BSHIFT))
146#endif
147#ifndef dtoc
148#define dtoc(x) ((x) >> (PAGE_SHIFT - _DEV_BSHIFT))
149#endif
150
151/* bytes to disk blocks */
152#ifndef btodb
153#define btodb(x) ((x) >> _DEV_BSHIFT)
154#endif
155#ifndef dbtob
156#define dbtob(x) ((x) << _DEV_BSHIFT)
157#endif
158
159/*
160 * MAXPATHLEN defines the longest permissible path length after expanding
161 * symbolic links. It is used to allocate a temporary buffer from the buffer
162 * pool in which to do the name expansion, hence should be a power of two,
163 * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the
164 * maximum number of symbolic links that may be expanded in a path name.
165 * It should be set high enough to allow all legitimate uses, but halt
166 * infinite loops reasonably quickly.
167 */
168#define MAXPATHLEN PATH_MAX
169#define MAXSYMLINKS SYMLOOP_MAX
170
171/* Macros to set/clear/test flags. */
172#ifdef _KERNEL
173#define SET(t, f) ((t) |= (f))
174#define CLR(t, f) ((t) &= ~(f))
175#define ISSET(t, f) ((t) & (f))
176#endif /* _KERNEL */
177
178/* Bit map related macros. */
179#define setbit(a,i) ((a)[(i)>>3] |= 1<<((i)&(NBBY-1)))
180#define clrbit(a,i) ((a)[(i)>>3] &= ~(1<<((i)&(NBBY-1))))
181#define isset(a,i) ((a)[(i)>>3] & (1<<((i)&(NBBY-1))))
182#define isclr(a,i) (((a)[(i)>>3] & (1<<((i)&(NBBY-1)))) == 0)
183
184/* Macros for counting and rounding. */
185#ifndef howmany
186#define howmany(x, y) (((x)+((y)-1))/(y))
187#endif
188#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
189#define powerof2(x) ((((x)-1)&(x))==0)
190
191/* Macros for min/max. */
192#define MIN(a,b) (((a)<(b))?(a):(b))
193#define MAX(a,b) (((a)>(b))?(a):(b))
194
195/* Macros for calculating the offset of a field */
196#if !defined(offsetof) && defined(_KERNEL)
197#if __GNUC_PREREQ__(4, 0)
198#define offsetof(s, e) __builtin_offsetof(s, e)
199#else
200#define offsetof(s, e) ((size_t)&((s *)0)->e)
201#endif
202#endif /* !defined(offsetof) && defined(_KERNEL) */
203
204#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
205
206/*
207 * Scale factor for scaled integers used to count %cpu time and load avgs.
208 *
209 * The number of CPU `tick's that map to a unique `%age' can be expressed
210 * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that
211 * can be calculated (assuming 32 bits) can be closely approximated using
212 * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15).
213 *
214 * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age',
215 * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024.
216 */
217#define _FSHIFT 11 /* bits to right of fixed binary point */
218#ifdef _KERNEL
219#define FSHIFT _FSHIFT
220#endif
221#define FSCALE (1<<_FSHIFT)
222
223#endif /* !_SYS_PARAM_H_ */