syscall_defs.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * System call related declarations
  3. *
  4. * Copyright (c) 2013-15 Stacey D. Son (sson at FreeBSD)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef SYSCALL_DEFS_H
  20. #define SYSCALL_DEFS_H
  21. #include <sys/syscall.h>
  22. #include <sys/resource.h>
  23. #include "errno_defs.h"
  24. #include "freebsd/syscall_nr.h"
  25. #include "netbsd/syscall_nr.h"
  26. #include "openbsd/syscall_nr.h"
  27. /*
  28. * machine/_types.h
  29. * or x86/_types.h
  30. */
  31. /*
  32. * time_t seems to be very inconsistly defined for the different *BSD's...
  33. *
  34. * FreeBSD uses a 64bits time_t except on i386
  35. * so we have to add a special case here.
  36. *
  37. * On NetBSD time_t is always defined as an int64_t. On OpenBSD time_t
  38. * is always defined as an int.
  39. *
  40. */
  41. #if (!defined(TARGET_I386))
  42. typedef int64_t target_freebsd_time_t;
  43. #else
  44. typedef int32_t target_freebsd_time_t;
  45. #endif
  46. struct target_iovec {
  47. abi_long iov_base; /* Starting address */
  48. abi_long iov_len; /* Number of bytes */
  49. };
  50. /*
  51. * sys/mman.h
  52. */
  53. #define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplemented */
  54. /* MAP_INHERIT */
  55. #define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemented */
  56. /* MAP_NOEXTEND */
  57. #define TARGET_FREEBSD_MAP_STACK 0x0400 /* region grows down, like a */
  58. /* stack */
  59. #define TARGET_FREEBSD_MAP_NOSYNC 0x0800 /* page to but do not sync */
  60. /* underlying file */
  61. #define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7
  62. #define TARGET_NETBSD_MAP_INHERIT 0x0080 /* region is retained after */
  63. /* exec */
  64. #define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, even */
  65. /* within break */
  66. #define TARGET_NETBSD_MAP_WIRED 0x0800 /* mlock() mapping when it is */
  67. /* established */
  68. #define TARGET_NETBSD_MAP_STACK 0x2000 /* allocated from memory, */
  69. /* swap space (stack) */
  70. #define TARGET_NETBSD_MAP_FLAGMASK 0x3ff7
  71. #define TARGET_OPENBSD_MAP_INHERIT 0x0080 /* region is retained after */
  72. /* exec */
  73. #define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change */
  74. /* file size */
  75. #define TARGET_OPENBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, */
  76. /* even within heap */
  77. #define TARGET_OPENBSD_MAP_FLAGMASK 0x17f7
  78. /* XXX */
  79. #define TARGET_BSD_MAP_FLAGMASK 0x3ff7
  80. /*
  81. * sys/time.h
  82. * sys/timex.h
  83. */
  84. typedef abi_long target_freebsd_suseconds_t;
  85. /* compare to sys/timespec.h */
  86. struct target_freebsd_timespec {
  87. target_freebsd_time_t tv_sec; /* seconds */
  88. abi_long tv_nsec; /* and nanoseconds */
  89. #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
  90. abi_long _pad;
  91. #endif
  92. };
  93. #define TARGET_CPUCLOCK_WHICH_PID 0
  94. #define TARGET_CPUCLOCK_WHICH_TID 1
  95. /* sys/umtx.h */
  96. struct target_freebsd__umtx_time {
  97. struct target_freebsd_timespec _timeout;
  98. uint32_t _flags;
  99. uint32_t _clockid;
  100. };
  101. struct target_freebsd_timeval {
  102. target_freebsd_time_t tv_sec; /* seconds */
  103. target_freebsd_suseconds_t tv_usec;/* and microseconds */
  104. #if !defined(TARGET_I386) && TARGET_ABI_BITS == 32
  105. abi_long _pad;
  106. #endif
  107. };
  108. /*
  109. * sys/resource.h
  110. */
  111. #if defined(__FreeBSD__)
  112. #define TARGET_RLIM_INFINITY RLIM_INFINITY
  113. #else
  114. #define TARGET_RLIM_INFINITY ((abi_ulong)-1)
  115. #endif
  116. #define TARGET_RLIMIT_CPU 0
  117. #define TARGET_RLIMIT_FSIZE 1
  118. #define TARGET_RLIMIT_DATA 2
  119. #define TARGET_RLIMIT_STACK 3
  120. #define TARGET_RLIMIT_CORE 4
  121. #define TARGET_RLIMIT_RSS 5
  122. #define TARGET_RLIMIT_MEMLOCK 6
  123. #define TARGET_RLIMIT_NPROC 7
  124. #define TARGET_RLIMIT_NOFILE 8
  125. #define TARGET_RLIMIT_SBSIZE 9
  126. #define TARGET_RLIMIT_AS 10
  127. #define TARGET_RLIMIT_NPTS 11
  128. #define TARGET_RLIMIT_SWAP 12
  129. struct target_rlimit {
  130. uint64_t rlim_cur;
  131. uint64_t rlim_max;
  132. };
  133. struct target_freebsd_rusage {
  134. struct target_freebsd_timeval ru_utime; /* user time used */
  135. struct target_freebsd_timeval ru_stime; /* system time used */
  136. abi_long ru_maxrss; /* maximum resident set size */
  137. abi_long ru_ixrss; /* integral shared memory size */
  138. abi_long ru_idrss; /* integral unshared data size */
  139. abi_long ru_isrss; /* integral unshared stack size */
  140. abi_long ru_minflt; /* page reclaims */
  141. abi_long ru_majflt; /* page faults */
  142. abi_long ru_nswap; /* swaps */
  143. abi_long ru_inblock; /* block input operations */
  144. abi_long ru_oublock; /* block output operations */
  145. abi_long ru_msgsnd; /* messages sent */
  146. abi_long ru_msgrcv; /* messages received */
  147. abi_long ru_nsignals; /* signals received */
  148. abi_long ru_nvcsw; /* voluntary context switches */
  149. abi_long ru_nivcsw; /* involuntary context switches */
  150. };
  151. struct target_freebsd__wrusage {
  152. struct target_freebsd_rusage wru_self;
  153. struct target_freebsd_rusage wru_children;
  154. };
  155. #define safe_syscall0(type, name) \
  156. type safe_##name(void) \
  157. { \
  158. return safe_syscall(SYS_##name); \
  159. }
  160. #define safe_syscall1(type, name, type1, arg1) \
  161. type safe_##name(type1 arg1) \
  162. { \
  163. return safe_syscall(SYS_##name, arg1); \
  164. }
  165. #define safe_syscall2(type, name, type1, arg1, type2, arg2) \
  166. type safe_##name(type1 arg1, type2 arg2) \
  167. { \
  168. return safe_syscall(SYS_##name, arg1, arg2); \
  169. }
  170. #define safe_syscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
  171. type safe_##name(type1 arg1, type2 arg2, type3 arg3) \
  172. { \
  173. return safe_syscall(SYS_##name, arg1, arg2, arg3); \
  174. }
  175. #define safe_syscall4(type, name, type1, arg1, type2, arg2, type3, arg3, \
  176. type4, arg4) \
  177. type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
  178. { \
  179. return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4); \
  180. }
  181. #define safe_syscall5(type, name, type1, arg1, type2, arg2, type3, arg3, \
  182. type4, arg4, type5, arg5) \
  183. type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  184. type5 arg5) \
  185. { \
  186. return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5); \
  187. }
  188. #define safe_syscall6(type, name, type1, arg1, type2, arg2, type3, arg3, \
  189. type4, arg4, type5, arg5, type6, arg6) \
  190. type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
  191. type5 arg5, type6 arg6) \
  192. { \
  193. return safe_syscall(SYS_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
  194. }
  195. /* So far all target and host bitmasks are the same */
  196. #define target_to_host_bitmask(x, tbl) (x)
  197. #define host_to_target_bitmask(x, tbl) (x)
  198. #endif /* SYSCALL_DEFS_H */