types.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
  3. * The President and Fellows of Harvard College.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef _TYPES_H_
  30. #define _TYPES_H_
  31. /*
  32. * Master kernel header file.
  33. *
  34. * The model for the include files in the kernel is as follows:
  35. *
  36. * - Every source file includes this file, <types.h>, first.
  37. *
  38. * - Every other header file may assume this file has been
  39. * included, but should explicitly include any other headers it
  40. * uses to compile.
  41. *
  42. * - Some exceptions to the previous rules exist among the headers
  43. * exported to userland; those files should be included in the
  44. * kernel only indirectly via other, non-exported, headers, as
  45. * described in comments therein.
  46. *
  47. * - Every source or header file should include each file it
  48. * directly uses, even if that header is included via some other
  49. * header. This helps to prevent build failures when unrelated
  50. * dependencies are changed around.
  51. *
  52. * - As a matter of convention, the ordering of include files in
  53. * the base system is in order of subsystem dependence. That is,
  54. * lower-level code like <spinlock.h> should come before
  55. * higher-level code like <addrspace.h> or <vfs.h>. This
  56. * convention helps one to keep keep track of (and learn) the
  57. * organization of the system.
  58. *
  59. * The general ordering is as follows:
  60. * 1. <types.h>
  61. * 2. Kernel ABI definitions, e.g. <kern/errno.h>.
  62. * 3. Support code: <lib.h>, arrays, queues, etc.
  63. * 4. Low-level code: locks, trapframes, etc.
  64. * 5. Kernel subsystems: threads, VM, VFS, etc.
  65. * 6. System call layer, e.g. <elf.h>, <syscall.h>.
  66. *
  67. * Subsystem-private headers (the only extant example is
  68. * switchframe.h) and then kernel option headers generated by
  69. * config come last.
  70. *
  71. * There is no one perfect ordering, because the kernel is not
  72. * composed of perfectly nested layers. But for the most part
  73. * this principle produces a workable result.
  74. */
  75. /* Get types visible to userland, both MI and MD. */
  76. #include <kern/types.h>
  77. /* Get machine-dependent types not visible to userland. */
  78. #include <machine/types.h>
  79. /*
  80. * Define userptr_t as a pointer to a one-byte struct, so it won't mix
  81. * with other pointers.
  82. */
  83. struct __userptr { char _dummy; };
  84. typedef struct __userptr *userptr_t;
  85. typedef const struct __userptr *const_userptr_t;
  86. /*
  87. * Proper (non-underscore) names for the types that are exposed to
  88. * userland.
  89. */
  90. /* machine-dependent from <kern/machine/types.h>... */
  91. typedef __i8 int8_t;
  92. typedef __i16 int16_t;
  93. typedef __i32 int32_t;
  94. typedef __i64 int64_t;
  95. typedef __u8 uint8_t;
  96. typedef __u16 uint16_t;
  97. typedef __u32 uint32_t;
  98. typedef __u64 uint64_t;
  99. typedef __size_t size_t;
  100. typedef __ssize_t ssize_t;
  101. typedef __intptr_t intptr_t;
  102. typedef __uintptr_t uintptr_t;
  103. typedef __ptrdiff_t ptrdiff_t;
  104. /* ...and machine-independent from <kern/types.h>. */
  105. typedef __blkcnt_t blkcnt_t;
  106. typedef __blksize_t blksize_t;
  107. typedef __daddr_t daddr_t;
  108. typedef __dev_t dev_t;
  109. typedef __fsid_t fsid_t;
  110. typedef __gid_t gid_t;
  111. typedef __in_addr_t in_addr_t;
  112. typedef __in_port_t in_port_t;
  113. typedef __ino_t ino_t;
  114. typedef __mode_t mode_t;
  115. typedef __nlink_t nlink_t;
  116. typedef __off_t off_t;
  117. typedef __pid_t pid_t;
  118. typedef __rlim_t rlim_t;
  119. typedef __sa_family_t sa_family_t;
  120. typedef __time_t time_t;
  121. typedef __uid_t uid_t;
  122. typedef __nfds_t nfds_t;
  123. typedef __socklen_t socklen_t;
  124. /*
  125. * Number of bits per byte.
  126. */
  127. #define CHAR_BIT __CHAR_BIT
  128. /*
  129. * Null pointer.
  130. */
  131. #define NULL ((void *)0)
  132. /*
  133. * Boolean.
  134. */
  135. typedef _Bool bool;
  136. #define true 1
  137. #define false 0
  138. #endif /* _TYPES_H_ */