shim_ipc_ns.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. };
  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. int NS_SEND(offer)(struct shim_ipc_port* port, IDTYPE dest, IDTYPE base, IDTYPE size,
  103. LEASETYPE lease, unsigned long seq);
  104. int NS_CALLBACK(offer)(IPC_CALLBACK_ARGS);
  105. /* RENEW: renew lease of a range of name */
  106. NS_MSG_TYPE(renew) {
  107. IDTYPE base, size;
  108. }
  109. __attribute__((packed));
  110. int NS_SEND(renew)(IDTYPE base, IDTYPE size);
  111. int NS_CALLBACK(renew)(IPC_CALLBACK_ARGS);
  112. /* SUBLEASE: lease a range of names */
  113. NS_MSG_TYPE(sublease) {
  114. IDTYPE tenant;
  115. IDTYPE idx;
  116. char uri[1];
  117. }
  118. __attribute__((packed));
  119. int NS_SEND(sublease)(IDTYPE tenant, IDTYPE idx, const char* uri, LEASETYPE* lease);
  120. int NS_CALLBACK(sublease)(IPC_CALLBACK_ARGS);
  121. /* QUERY: query the channel of certain name */
  122. NS_MSG_TYPE(query) {
  123. IDTYPE idx;
  124. }
  125. __attribute__((packed));
  126. int NS_SEND(query)(IDTYPE idx);
  127. int NS_CALLBACK(query)(IPC_CALLBACK_ARGS);
  128. /* QUERY: query the channel of all names */
  129. int NS_SEND(queryall)(void);
  130. int NS_CALLBACK(queryall)(IPC_CALLBACK_ARGS);
  131. /* ANSWER: answer the channel of certain names */
  132. NS_MSG_TYPE(answer) {
  133. int nanswers;
  134. struct ipc_ns_offered answers[];
  135. };
  136. int NS_SEND(answer)(struct shim_ipc_port* port, IDTYPE dest, int nanswers,
  137. struct ipc_ns_offered* answers, int nowners, struct ipc_ns_client** ownerdata,
  138. int* ownerdatasz, unsigned long seq);
  139. int NS_CALLBACK(answer)(IPC_CALLBACK_ARGS);
  140. #ifdef NS_KEY
  141. int CONCAT2(NS, add_key)(NS_KEY* key, IDTYPE id);
  142. int CONCAT2(NS, get_key)(NS_KEY* key, bool delete);
  143. /* FINDKEY */
  144. NS_MSG_TYPE(findkey) {
  145. NS_KEY key;
  146. };
  147. int NS_SEND(findkey)(NS_KEY* key);
  148. int NS_CALLBACK(findkey)(IPC_CALLBACK_ARGS);
  149. /* TELLKEY */
  150. NS_MSG_TYPE(tellkey) {
  151. NS_KEY key;
  152. IDTYPE id;
  153. };
  154. int NS_SEND(tellkey)(struct shim_ipc_port* port, IDTYPE dest, NS_KEY* key, IDTYPE id,
  155. unsigned long seq);
  156. int NS_CALLBACK(tellkey)(IPC_CALLBACK_ARGS);
  157. #undef NS_KEY
  158. #endif
  159. IDTYPE CONCAT2(allocate, NS)(IDTYPE min, IDTYPE max);
  160. void CONCAT2(release, NS)(IDTYPE idx);
  161. int CONCAT3(prepare, NS, leader)(void);
  162. #undef NS_SEND
  163. #undef NS_CALLBACK
  164. #undef NS_CODE
  165. #undef NS_MSG_TYPE
  166. #undef NS
  167. #undef NS_CAP