pal_freebsd.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* Copyright (C) 2014 Stony Brook University
  4. This file is part of Graphene Library OS.
  5. Graphene Library OS is free software: you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation, either version 3 of the
  8. License, or (at your option) any later version.
  9. Graphene Library OS is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #ifndef PAL_FREEBSD_H
  16. #define PAL_FREEBSD_H
  17. #include "pal_defs.h"
  18. #include "pal_freebsd_defs.h"
  19. #include "pal.h"
  20. #include "pal_freebsd_error.h"
  21. typedef int __kernel_pid_t;
  22. #include <sigset.h>
  23. #include <sys/syscall.h>
  24. #include <unistd.h>
  25. #undef __htonl
  26. #undef __ntohl
  27. #undef __htons
  28. #undef __ntohs
  29. #ifdef __x86_64__
  30. # include "sysdep-x86_64.h"
  31. #endif
  32. #define PAL_LOADER XSTRINGIFY(PAL_LOADER_PATH)
  33. #define IS_ERR INTERNAL_SYSCALL_ERROR
  34. #define IS_ERR_P INTERNAL_SYSCALL_ERROR_P
  35. #define ERRNO INTERNAL_SYSCALL_ERRNO
  36. #define ERRNO_P INTERNAL_SYSCALL_ERRNO_P
  37. int getrand (void * buffer, int size);
  38. struct timespec;
  39. struct timeval;
  40. extern struct pal_bsd_state {
  41. /* state */
  42. unsigned long start_time;
  43. /* credentails */
  44. unsigned int pid;
  45. unsigned int uid, gid;
  46. /* currently enabled signals */
  47. _sigset_t sigset;
  48. unsigned long memory_quota;
  49. } bsd_state;
  50. #include <sys/mman.h>
  51. #ifdef INLINE_SYSCALL
  52. # ifdef __i386__
  53. # define ARCH_MMAP(addr, len, prot, flags, fd, offset) \
  54. ({ \
  55. struct mmap_arg_struct { \
  56. unsigned long addr; \
  57. unsigned long len; \
  58. unsigned long prot; \
  59. unsigned long flags; \
  60. unsigned long fd; \
  61. unsigned long offset; \
  62. } args = { .addr = (unsigned long) (addr), \
  63. .len = (unsigned long) (len), \
  64. .prot = (unsigned long) (prot), \
  65. .flags = (unsigned long) (flags), \
  66. .fd = (unsigned long) (fd), \
  67. .offset = (unsigned long) (offset), }; \
  68. INLINE_SYSCALL(mmap, 1, &args); \
  69. })
  70. # else
  71. # define ARCH_MMAP(addr, len, prot, flags, fd, offset) \
  72. INLINE_SYSCALL(mmap, 6, (addr), (len), (prot), (flags), (fd), (offset))
  73. # endif
  74. #else
  75. # error "INLINE_SYSCALL not supported"
  76. #endif
  77. #define PRESET_PAGESIZE (1 << 12)
  78. #define DEFAULT_BACKLOG 2048
  79. static inline int HOST_FLAGS (int alloc_type, int prot)
  80. {
  81. return ((alloc_type & PAL_ALLOC_RESERVE) ? MAP_NORESERVE : 0) |
  82. ((prot & PAL_PROT_WRITECOPY) ? MAP_PRIVATE : MAP_SHARED);
  83. }
  84. static inline int HOST_PROT (int prot)
  85. {
  86. return prot & (PAL_PROT_READ|PAL_PROT_WRITE|PAL_PROT_EXEC);
  87. }
  88. int __clone (int (*__fn) (void * __arg), void * __child_stack,
  89. int __flags, const void * __arg, ...);
  90. /* set/unset CLOEXEC flags of all fds in a handle */
  91. int handle_set_cloexec (PAL_HANDLE handle, bool enable);
  92. /* serialize/deserialize a handle into/from a malloc'ed buffer */
  93. int handle_serialize (PAL_HANDLE handle, void ** data);
  94. int handle_deserialize (PAL_HANDLE * handle, const void * data, int size);
  95. #define ACCESS_R 4
  96. #define ACCESS_W 2
  97. #define ACCESS_X 1
  98. struct stat;
  99. bool stataccess (struct stat * stats, int acc);
  100. #include <sys/fcntl.h>
  101. static inline int HOST_FILE_OPEN (int access_type, int create_type,
  102. int options)
  103. {
  104. return ((access_type)|
  105. (create_type & PAL_CREAT_TRY ? O_CREAT : 0) |
  106. (create_type & PAL_CREAT_ALWAYS ? O_EXCL : 0) |
  107. (options));
  108. }
  109. #include<sys/stat.h>
  110. static inline int HOST_PERM (int share_type)
  111. {
  112. return((share_type & PAL_SHARE_GLOBAL_X ? S_IXUSR | S_IXGRP | S_IXOTH :
  113. 0)|
  114. (share_type & PAL_SHARE_GLOBAL_W ? S_IWUSR | S_IWGRP | S_IWOTH :
  115. 0)|
  116. (share_type & PAL_SHARE_GLOBAL_R ? S_IRUSR | S_IRGRP | S_IROTH :
  117. 0)|
  118. (share_type & PAL_SHARE_GROUP_X ? S_IXGRP : 0) |
  119. (share_type & PAL_SHARE_GROUP_W ? S_IWGRP : 0) |
  120. (share_type & PAL_SHARE_GROUP_R ? S_IRGRP : 0) |
  121. (share_type & PAL_SHARE_OWNER_X ? S_IXUSR : 0) |
  122. (share_type & PAL_SHARE_OWNER_W ? S_IWUSR : 0) |
  123. (share_type & PAL_SHARE_OWNER_R ? S_IRUSR : 0));
  124. }
  125. static inline int HOST_OPTIONS (int options)
  126. {
  127. return((options & PAL_OPTION_NONBLOCK ? O_NONBLOCK : 0 )
  128. );
  129. }
  130. #include <sys/socket.h>
  131. static inline int HOST_SOCKET_OPTIONS (int options)
  132. {
  133. return((options & PAL_OPTION_NONBLOCK ? SOCK_NONBLOCK : 0 )
  134. );
  135. }
  136. /* Locking and unlocking of Mutexes */
  137. int _DkMutexLock (struct mutex_handle * mut);
  138. int _DkMutexLockTimeout (struct mutex_handle * mut, int timeout);
  139. int _DkMutexUnlock (struct mutex_handle * mut);
  140. /*UMTX constants*/
  141. #define UMTX_OP_WAIT 2
  142. #define UMTX_OP_WAKE 3
  143. #define UMTX_OP_WAIT_UINT 11
  144. void init_child_process (PAL_HANDLE * parent, PAL_HANDLE * exec,
  145. PAL_HANDLE * manifest);
  146. void signal_setup (void);
  147. extern char __text_start, __text_end, __data_start, __data_end;
  148. #define TEXT_START (void *) (&__text_start)
  149. #define TEXT_END (void *) (&__text_end)
  150. #define DATA_START (void *) (&__text_start)
  151. #define DATA_END (void *) (&__text_end)
  152. #endif /* PAL_FREEBSD_H */