param.h 7.6 KB

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