pal_host.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. /*
  16. * pal_host.h
  17. *
  18. * This file contains definition of PAL host ABI.
  19. */
  20. #ifndef PAL_HOST_H
  21. #define PAL_HOST_H
  22. #ifndef IN_PAL
  23. # error "cannot be included outside PAL"
  24. #endif
  25. /* internal Mutex design, the structure has to align at integer boundary
  26. because it is required by futex call. If DEBUG_MUTEX is defined,
  27. mutex_handle will record the owner of mutex locking. */
  28. typedef struct mutex_handle {
  29. struct atomic_int value;
  30. #ifdef DEBUG_MUTEX
  31. int owner;
  32. #endif
  33. } PAL_LOCK;
  34. /* Initializer of Mutexes */
  35. #define MUTEX_HANDLE_INIT { .value = { .counter = 1 } }
  36. #define INIT_MUTEX_HANDLE(mut) \
  37. do { atomic_set(&(mut)->value, 1); } while (0)
  38. #define LOCK_INIT MUTEX_HANDLE_INIT
  39. #define INIT_LOCK(lock) INIT_MUTEX_HANDLE(lock);
  40. #define _DkInternalLock _DkMutexLock
  41. #define _DkInternalUnlock _DkMutexUnlock
  42. typedef union pal_handle
  43. {
  44. /* TSAI: Here we define the internal types of PAL_HANDLE
  45. * in PAL design, user has not to access the content inside the
  46. * handle, also there is no need to allocate the internal
  47. * handles, so we hide the type name of these handles on purpose.
  48. */
  49. struct {
  50. PAL_IDX type;
  51. PAL_FLG flags;
  52. PAL_REF ref;
  53. PAL_IDX fds[];
  54. } __in;
  55. struct {
  56. PAL_HDR __in;
  57. PAL_IDX fd;
  58. PAL_NUM offset;
  59. PAL_BOL append;
  60. PAL_BOL pass;
  61. PAL_STR realpath;
  62. } file;
  63. struct {
  64. PAL_HDR __in;
  65. PAL_IDX fd;
  66. PAL_NUM pipeid;
  67. PAL_BOL nonblocking;
  68. } pipe;
  69. struct {
  70. PAL_HDR __in;
  71. PAL_IDX fds[2];
  72. PAL_BOL nonblocking;
  73. } pipeprv;
  74. struct {
  75. PAL_HDR __in;
  76. PAL_IDX fd_in, fd_out;
  77. PAL_IDX dev_type;
  78. PAL_BOL destroy;
  79. PAL_STR realpath;
  80. } dev;
  81. struct {
  82. PAL_HDR __in;
  83. PAL_IDX fd;
  84. PAL_STR realpath;
  85. PAL_PTR buf;
  86. PAL_PTR ptr;
  87. PAL_PTR end;
  88. PAL_BOL endofstream;
  89. } dir;
  90. struct {
  91. PAL_HDR __in;
  92. PAL_IDX fd;
  93. PAL_NUM token;
  94. } gipc;
  95. struct {
  96. PAL_HDR __in;
  97. PAL_IDX fd;
  98. PAL_PTR bind;
  99. PAL_PTR conn;
  100. PAL_BOL nonblocking;
  101. PAL_BOL reuseaddr;
  102. PAL_NUM linger;
  103. PAL_NUM receivebuf;
  104. PAL_NUM sendbuf;
  105. PAL_NUM receivetimeout;
  106. PAL_NUM sendtimeout;
  107. PAL_BOL tcp_cork;
  108. PAL_BOL tcp_keepalive;
  109. PAL_BOL tcp_nodelay;
  110. } sock;
  111. struct {
  112. PAL_HDR __in;
  113. PAL_IDX stream_in, stream_out;
  114. PAL_IDX cargo;
  115. PAL_IDX pid;
  116. PAL_BOL nonblocking;
  117. } process;
  118. struct {
  119. PAL_HDR __in;
  120. PAL_IDX cli;
  121. PAL_IDX srv;
  122. PAL_IDX port;
  123. PAL_BOL nonblocking;
  124. } mcast;
  125. struct {
  126. PAL_HDR __in;
  127. PAL_IDX tid;
  128. } thread;
  129. struct {
  130. PAL_HDR __in;
  131. struct atomic_int nwaiters;
  132. PAL_NUM max_value;
  133. union {
  134. struct mutex_handle mut;
  135. struct atomic_int i;
  136. } value;
  137. } semaphore;
  138. struct {
  139. PAL_HDR __in;
  140. struct atomic_int signaled;
  141. struct atomic_int nwaiters;
  142. PAL_BOL isnotification;
  143. } event;
  144. } * PAL_HANDLE;
  145. #define RFD(n) (00001 << (n))
  146. #define WFD(n) (00010 << (n))
  147. #define WRITEABLE(n) (00100 << (n))
  148. #define ERROR(n) (01000 << (n))
  149. #define MAX_FDS (3)
  150. #define HAS_FDS (00077)
  151. #define HANDLE_TYPE(handle) ((handle)->__in.type)
  152. #endif /* PAL_HOST_H */