1 /* $OpenBSD: param.h,v 1.122 2016/05/11 18:01:33 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 #define OpenBSD 201609 /* OpenBSD version (year & month). */ 45 #define OpenBSD6_0 1 /* OpenBSD 6.0 */ 46 47 #ifndef NULL 48 #ifdef __GNUG__ 49 #define NULL __null 50 #else 51 #define NULL ((void *)0) 52 #endif 53 #endif 54 55 #ifndef _LOCORE 56 #include <sys/types.h> 57 #endif 58 59 /* 60 * Machine-independent constants (some used in following include files). 61 * Redefined constants are from POSIX 1003.1 limits file. 62 * 63 * MAXCOMLEN should be >= sizeof(ac_comm) (see <acct.h>) 64 * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>) 65 */ 66 #include <sys/syslimits.h> 67 68 #define MAXCOMLEN 16 /* max command name remembered */ 69 #define MAXINTERP 128 /* max interpreter file name length */ 70 #define MAXLOGNAME LOGIN_NAME_MAX /* max login name length w/ NUL */ 71 #define MAXUPRC CHILD_MAX /* max simultaneous processes */ 72 #define NCARGS ARG_MAX /* max bytes for an exec function */ 73 #define NGROUPS NGROUPS_MAX /* max number groups */ 74 #define NOFILE OPEN_MAX /* max open files per process (soft) */ 75 #define NOFILE_MAX 1024 /* max open files per process (hard) */ 76 #define NOGROUP 65535 /* marker for empty group set member */ 77 #define MAXHOSTNAMELEN 256 /* max hostname length w/ NUL */ 78 79 /* More types and definitions used throughout the kernel. */ 80 #ifdef _KERNEL 81 #include <sys/errno.h> 82 #include <sys/time.h> 83 #include <sys/resource.h> 84 #include <sys/ucred.h> 85 #include <sys/uio.h> 86 #include <sys/srp.h> 87 #endif 88 89 /* Signals. */ 90 #include <sys/signal.h> 91 92 /* Machine type dependent parameters. */ 93 #include <sys/limits.h> 94 #include <machine/param.h> 95 96 #ifdef _KERNEL 97 /* 98 * Priorities. Note that with 32 run queues, differences less than 4 are 99 * insignificant. 100 */ 101 #define PSWP 0 102 #define PVM 4 103 #define PINOD 8 104 #define PRIBIO 16 105 #define PVFS 20 106 #endif /* _KERNEL */ 107 #define PZERO 22 /* No longer magic, shouldn't be here. XXX */ 108 #ifdef _KERNEL 109 #define PSOCK 24 110 #define PWAIT 32 111 #define PLOCK 36 112 #define PPAUSE 40 113 #define PUSER 50 114 #define MAXPRI 127 /* Priorities range from 0 through MAXPRI. */ 115 116 #define PRIMASK 0x0ff 117 #define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */ 118 #define PNORELOCK 0x200 /* OR'd with pri for msleep to not reaquire 119 the mutex */ 120 #endif /* _KERNEL */ 121 122 #define NODEV (dev_t)(-1) /* non-existent device */ 123 124 #define ALIGNBYTES _ALIGNBYTES 125 #define ALIGN(p) _ALIGN(p) 126 #define ALIGNED_POINTER(p,t) _ALIGNED_POINTER(p,t) 127 128 /* 129 * File system parameters and macros. 130 * 131 * The file system is made out of blocks of at most MAXBSIZE units, with 132 * smaller units (fragments) only in the last direct block. MAXBSIZE 133 * primarily determines the size of buffers in the buffer pool. It may be 134 * made larger without any effect on existing file systems; however making 135 * it smaller makes some file systems unmountable. 136 */ 137 #ifdef _KERNEL 138 #define MAXPHYS (64 * 1024) /* max raw I/O transfer size */ 139 #endif /* _KERNEL */ 140 #define MAXBSIZE (64 * 1024) 141 142 #define _DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ 143 #define DEV_BSIZE (1 << _DEV_BSHIFT) 144 #ifdef _KERNEL 145 #define DEV_BSHIFT _DEV_BSHIFT 146 #define BLKDEV_IOSIZE PAGE_SIZE 147 #endif /* _KERNEL */ 148 149 /* pages to disk blocks */ 150 #ifndef ctod 151 #define ctod(x) ((x) << (PAGE_SHIFT - _DEV_BSHIFT)) 152 #endif 153 #ifndef dtoc 154 #define dtoc(x) ((x) >> (PAGE_SHIFT - _DEV_BSHIFT)) 155 #endif 156 157 /* bytes to disk blocks */ 158 #ifndef btodb 159 #define btodb(x) ((x) >> _DEV_BSHIFT) 160 #endif 161 #ifndef dbtob 162 #define dbtob(x) ((x) << _DEV_BSHIFT) 163 #endif 164 165 /* 166 * MAXPATHLEN defines the longest permissible path length after expanding 167 * symbolic links. It is used to allocate a temporary buffer from the buffer 168 * pool in which to do the name expansion, hence should be a power of two, 169 * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the 170 * maximum number of symbolic links that may be expanded in a path name. 171 * It should be set high enough to allow all legitimate uses, but halt 172 * infinite loops reasonably quickly. 173 */ 174 #define MAXPATHLEN PATH_MAX 175 #define MAXSYMLINKS SYMLOOP_MAX 176 177 /* Macros to set/clear/test flags. */ 178 #ifdef _KERNEL 179 #define SET(t, f) ((t) |= (f)) 180 #define CLR(t, f) ((t) &= ~(f)) 181 #define ISSET(t, f) ((t) & (f)) 182 #endif /* _KERNEL */ 183 184 /* Bit map related macros. */ 185 #define setbit(a,i) ((a)[(i)>>3] |= 1<<((i)&(NBBY-1))) 186 #define clrbit(a,i) ((a)[(i)>>3] &= ~(1<<((i)&(NBBY-1)))) 187 #define isset(a,i) ((a)[(i)>>3] & (1<<((i)&(NBBY-1)))) 188 #define isclr(a,i) (((a)[(i)>>3] & (1<<((i)&(NBBY-1)))) == 0) 189 190 /* Macros for counting and rounding. */ 191 #ifndef howmany 192 #define howmany(x, y) (((x)+((y)-1))/(y)) 193 #endif 194 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) 195 #define powerof2(x) ((((x)-1)&(x))==0) 196 197 /* Macros for min/max. */ 198 #define MIN(a,b) (((a)<(b))?(a):(b)) 199 #define MAX(a,b) (((a)>(b))?(a):(b)) 200 201 /* Macros for calculating the offset of a field */ 202 #if !defined(offsetof) && defined(_KERNEL) 203 #if __GNUC_PREREQ__(4, 0) 204 #define offsetof(s, e) __builtin_offsetof(s, e) 205 #else 206 #define offsetof(s, e) ((size_t)&((s *)0)->e) 207 #endif 208 #endif /* !defined(offsetof) && defined(_KERNEL) */ 209 210 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) 211 212 /* 213 * Scale factor for scaled integers used to count %cpu time and load avgs. 214 * 215 * The number of CPU `tick's that map to a unique `%age' can be expressed 216 * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that 217 * can be calculated (assuming 32 bits) can be closely approximated using 218 * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15). 219 * 220 * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age', 221 * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024. 222 */ 223 #define _FSHIFT 11 /* bits to right of fixed binary point */ 224 #ifdef _KERNEL 225 #define FSHIFT _FSHIFT 226 #endif 227 #define FSCALE (1<<_FSHIFT) 228 229 #endif /* !_SYS_PARAM_H_ */ 230