shim_ipc_ns.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * shim_ipc_ns.h
  15. *
  16. * Definitions of types and functions for IPC namespace bookkeeping.
  17. */
  18. #ifndef __SHIM_IPC_NS_H__
  19. #define __SHIM_IPC_NS_H__
  20. #include <shim_internal.h>
  21. #include <shim_types.h>
  22. #define IPC_NS_CALLBACKS(ns) \
  23. /* FINDNS */ &ipc_##ns##_findns_callback, /* TELLNS */ &ipc_##ns##_tellns_callback, \
  24. /* LEASE */ &ipc_##ns##_lease_callback, /* OFFER */ &ipc_##ns##_offer_callback, \
  25. /* RENEW */ &ipc_##ns##_renew_callback, /* SUBLEASE */ &ipc_##ns##_sublease_callback, \
  26. /* QUERY */ &ipc_##ns##_query_callback, /* QUERYALL */ &ipc_##ns##_queryall_callback, \
  27. /* ANSWER */ &ipc_##ns##_answer_callback,
  28. #define IPC_NS_KEY_CALLBACKS(ns) \
  29. /* FINDKEY */ &ipc_##ns##_findkey_callback, /* TELLKEY */ &ipc_##ns##_tellkey_callback,
  30. #define NS_PORT_CONSTS(n) n##CLT, n##LDR, n##CON, n##OWN,
  31. #define NS_PORT_TYPES(n) \
  32. IPC_PORT_##n##CLT = 1 << n##CLT, IPC_PORT_##n##LDR = 1 << n##LDR, \
  33. IPC_PORT_##n##CON = 1 << n##CON, IPC_PORT_##n##OWN = 1 << n##OWN,
  34. struct ipc_ns_offered {
  35. IDTYPE base, size;
  36. LEASETYPE lease;
  37. unsigned int owner_offset;
  38. } __attribute__((packed));
  39. struct ipc_ns_client {
  40. IDTYPE vmid;
  41. char uri[1];
  42. } __attribute__((packed));
  43. #endif /* __SHIM_IPC_NS_H__ */
  44. #define NS_SEND(t) CONCAT3(ipc, NS, t##_send)
  45. #define NS_CALLBACK(t) CONCAT3(ipc, NS, t##_callback)
  46. #define NS_CODE(t) CONCAT3(IPC, NS_CAP, t)
  47. #define NS_MSG_TYPE(t) struct CONCAT3(shim_ipc, NS, t)
  48. int CONCAT3(add, NS, range)(IDTYPE base, IDTYPE owner, const char* uri, LEASETYPE lease);
  49. int CONCAT3(del, NS, range)(IDTYPE idx);
  50. int CONCAT3(add, NS, subrange)(IDTYPE idx, IDTYPE owner, const char* uri, LEASETYPE* lease);
  51. int CONCAT3(del, NS, subrange)(IDTYPE idx);
  52. int CONCAT3(alloc, NS, range)(IDTYPE owner, const char* uri, IDTYPE* base, LEASETYPE* lease);
  53. struct CONCAT2(NS, range) {
  54. IDTYPE base, size;
  55. IDTYPE owner;
  56. struct shim_qstr uri;
  57. LEASETYPE lease;
  58. struct shim_ipc_port* port;
  59. };
  60. int CONCAT3(get, NS, range)(IDTYPE idx, struct CONCAT2(NS, range)* range,
  61. struct shim_ipc_info** pinfo);
  62. enum {
  63. NS_CODE(FINDNS) = CONCAT3(IPC, NS_CAP, BASE),
  64. NS_CODE(TELLNS),
  65. NS_CODE(LEASE),
  66. NS_CODE(OFFER),
  67. NS_CODE(RENEW),
  68. NS_CODE(SUBLEASE),
  69. NS_CODE(QUERY),
  70. NS_CODE(QUERYALL),
  71. NS_CODE(ANSWER),
  72. #ifdef NS_KEY
  73. NS_CODE(FINDKEY),
  74. NS_CODE(TELLKEY),
  75. #endif
  76. NS_CODE(TEMPLATE_BOUND),
  77. };
  78. /* FINDNS: find the channel of the namespace leader */
  79. int NS_SEND(findns)(bool block);
  80. int NS_CALLBACK(findns)(IPC_CALLBACK_ARGS);
  81. /* TELLNS: tell the channel of namespace leader */
  82. NS_MSG_TYPE(tellns) {
  83. IDTYPE vmid;
  84. char uri[1];
  85. }
  86. __attribute__((packed));
  87. int NS_SEND(tellns)(struct shim_ipc_port* port, IDTYPE dest, struct shim_ipc_info* leader,
  88. unsigned long seq);
  89. int NS_CALLBACK(tellns)(IPC_CALLBACK_ARGS);
  90. /* LEASE: lease a range of name */
  91. NS_MSG_TYPE(lease) {
  92. char uri[1];
  93. }
  94. __attribute__((packed));
  95. int NS_SEND(lease)(LEASETYPE* lease);
  96. int NS_CALLBACK(lease)(IPC_CALLBACK_ARGS);
  97. /* OFFER: offer a range of name */
  98. NS_MSG_TYPE(offer) {
  99. IDTYPE base, size;
  100. LEASETYPE lease;
  101. }
  102. __attribute__((packed));
  103. int NS_SEND(offer)(struct shim_ipc_port* port, IDTYPE dest, IDTYPE base, IDTYPE size,
  104. LEASETYPE lease, unsigned long seq);
  105. int NS_CALLBACK(offer)(IPC_CALLBACK_ARGS);
  106. /* RENEW: renew lease of a range of name */
  107. NS_MSG_TYPE(renew) {
  108. IDTYPE base, size;
  109. }
  110. __attribute__((packed));
  111. int NS_SEND(renew)(IDTYPE base, IDTYPE size);
  112. int NS_CALLBACK(renew)(IPC_CALLBACK_ARGS);
  113. /* SUBLEASE: lease a range of names */
  114. NS_MSG_TYPE(sublease) {
  115. IDTYPE tenant;
  116. IDTYPE idx;
  117. char uri[1];
  118. }
  119. __attribute__((packed));
  120. int NS_SEND(sublease)(IDTYPE tenant, IDTYPE idx, const char* uri, LEASETYPE* lease);
  121. int NS_CALLBACK(sublease)(IPC_CALLBACK_ARGS);
  122. /* QUERY: query the channel of certain name */
  123. NS_MSG_TYPE(query) {
  124. IDTYPE idx;
  125. }
  126. __attribute__((packed));
  127. int NS_SEND(query)(IDTYPE idx);
  128. int NS_CALLBACK(query)(IPC_CALLBACK_ARGS);
  129. /* QUERY: query the channel of all names */
  130. int NS_SEND(queryall)(void);
  131. int NS_CALLBACK(queryall)(IPC_CALLBACK_ARGS);
  132. /* ANSWER: answer the channel of certain names */
  133. NS_MSG_TYPE(answer) {
  134. int nanswers;
  135. struct ipc_ns_offered answers[];
  136. }
  137. __attribute__((packed));
  138. int NS_SEND(answer)(struct shim_ipc_port* port, IDTYPE dest, int nanswers,
  139. struct ipc_ns_offered* answers, int nowners, struct ipc_ns_client** ownerdata,
  140. int* ownerdatasz, unsigned long seq);
  141. int NS_CALLBACK(answer)(IPC_CALLBACK_ARGS);
  142. #ifdef NS_KEY
  143. int CONCAT2(NS, add_key)(NS_KEY* key, IDTYPE id);
  144. int CONCAT2(NS, get_key)(NS_KEY* key, bool delete);
  145. /* FINDKEY */
  146. NS_MSG_TYPE(findkey) {
  147. NS_KEY key;
  148. }
  149. __attribute__((packed));
  150. int NS_SEND(findkey)(NS_KEY* key);
  151. int NS_CALLBACK(findkey)(IPC_CALLBACK_ARGS);
  152. /* TELLKEY */
  153. NS_MSG_TYPE(tellkey) {
  154. NS_KEY key;
  155. IDTYPE id;
  156. }
  157. __attribute__((packed));
  158. int NS_SEND(tellkey)(struct shim_ipc_port* port, IDTYPE dest, NS_KEY* key, IDTYPE id,
  159. unsigned long seq);
  160. int NS_CALLBACK(tellkey)(IPC_CALLBACK_ARGS);
  161. #undef NS_KEY
  162. #endif
  163. IDTYPE CONCAT2(allocate, NS)(IDTYPE min, IDTYPE max);
  164. void CONCAT2(release, NS)(IDTYPE idx);
  165. int CONCAT3(prepare, NS, leader)(void);
  166. #undef NS_SEND
  167. #undef NS_CALLBACK
  168. #undef NS_CODE
  169. #undef NS_MSG_TYPE
  170. #undef NS
  171. #undef NS_CAP