wasm_c_api_internal.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_C_API_INTERNAL_H
  6. #define _WASM_C_API_INTERNAL_H
  7. #include "../include/wasm_c_api.h"
  8. #include "wasm_runtime_common.h"
  9. #ifndef own
  10. #define own
  11. #endif
  12. /* Vectors */
  13. /* we will malloc resource for the vector's data field */
  14. /* we will release resource of data */
  15. /* caller needs to take care resource for the vector itself */
  16. #define DEFAULT_VECTOR_INIT_LENGTH (64)
  17. WASM_DECLARE_VEC(instance, *)
  18. WASM_DECLARE_VEC(module, *)
  19. WASM_DECLARE_VEC(store, *)
  20. /* Runtime Environment */
  21. struct wasm_engine_t {
  22. uint32 ref_count;
  23. /* list of wasm_module_ex_t */
  24. Vector modules;
  25. /* list of stores which are classified according to tids */
  26. Vector stores_by_tid;
  27. };
  28. struct wasm_store_t {
  29. /* maybe should remove the list */
  30. wasm_module_vec_t *modules;
  31. wasm_instance_vec_t *instances;
  32. Vector *foreigns;
  33. };
  34. /* Type Representations */
  35. struct wasm_valtype_t {
  36. wasm_valkind_t kind;
  37. };
  38. struct wasm_functype_t {
  39. uint32 extern_kind;
  40. /* gona to new and delete own */
  41. wasm_valtype_vec_t *params;
  42. wasm_valtype_vec_t *results;
  43. };
  44. struct wasm_globaltype_t {
  45. uint32 extern_kind;
  46. /* gona to new and delete own */
  47. wasm_valtype_t *val_type;
  48. wasm_mutability_t mutability;
  49. };
  50. struct wasm_tabletype_t {
  51. uint32 extern_kind;
  52. wasm_valtype_t *val_type;
  53. wasm_limits_t limits;
  54. };
  55. struct wasm_memorytype_t {
  56. uint32 extern_kind;
  57. wasm_limits_t limits;
  58. };
  59. struct wasm_externtype_t {
  60. uint32 extern_kind;
  61. /* reserved space */
  62. uint8 data[1];
  63. };
  64. struct wasm_importtype_t {
  65. wasm_name_t *module_name;
  66. wasm_name_t *name;
  67. wasm_externtype_t *extern_type;
  68. };
  69. struct wasm_exporttype_t {
  70. wasm_name_t *name;
  71. wasm_externtype_t *extern_type;
  72. };
  73. /* Runtime Objects */
  74. enum wasm_reference_kind {
  75. WASM_REF_foreign,
  76. WASM_REF_func,
  77. WASM_REF_global,
  78. WASM_REF_memory,
  79. WASM_REF_table,
  80. };
  81. struct wasm_host_info {
  82. void *info;
  83. void (*finalizer)(void *);
  84. };
  85. struct wasm_ref_t {
  86. wasm_store_t *store;
  87. enum wasm_reference_kind kind;
  88. struct wasm_host_info host_info;
  89. uint32 ref_idx_rt;
  90. WASMModuleInstanceCommon *inst_comm_rt;
  91. };
  92. struct wasm_trap_t {
  93. wasm_byte_vec_t *message;
  94. Vector *frames;
  95. };
  96. struct wasm_foreign_t {
  97. wasm_store_t *store;
  98. enum wasm_reference_kind kind;
  99. struct wasm_host_info host_info;
  100. int32 ref_cnt;
  101. uint32 foreign_idx_rt;
  102. WASMModuleInstanceCommon *inst_comm_rt;
  103. };
  104. struct wasm_func_t {
  105. wasm_store_t *store;
  106. wasm_name_t *module_name;
  107. wasm_name_t *name;
  108. uint16 kind;
  109. struct wasm_host_info host_info;
  110. wasm_functype_t *type;
  111. uint16 param_count;
  112. uint16 result_count;
  113. bool with_env;
  114. union {
  115. wasm_func_callback_t cb;
  116. struct callback_ext {
  117. void *env;
  118. wasm_func_callback_with_env_t cb;
  119. void (*finalizer)(void *);
  120. } cb_env;
  121. } u;
  122. /*
  123. * an index in both functions runtime instance lists
  124. * of interpreter mode and aot mode
  125. */
  126. uint16 func_idx_rt;
  127. WASMModuleInstanceCommon *inst_comm_rt;
  128. WASMFunctionInstanceCommon *func_comm_rt;
  129. };
  130. struct wasm_global_t {
  131. wasm_store_t *store;
  132. wasm_name_t *module_name;
  133. wasm_name_t *name;
  134. uint16 kind;
  135. struct wasm_host_info host_info;
  136. wasm_globaltype_t *type;
  137. wasm_val_t *init;
  138. /*
  139. * an index in both global runtime instance lists
  140. * of interpreter mode and aot mode
  141. */
  142. uint16 global_idx_rt;
  143. WASMModuleInstanceCommon *inst_comm_rt;
  144. };
  145. struct wasm_memory_t {
  146. wasm_store_t *store;
  147. wasm_name_t *module_name;
  148. wasm_name_t *name;
  149. uint16 kind;
  150. struct wasm_host_info host_info;
  151. wasm_memorytype_t *type;
  152. /*
  153. * an index in both memory runtime instance lists
  154. * of interpreter mode and aot mode
  155. */
  156. uint16 memory_idx_rt;
  157. WASMModuleInstanceCommon *inst_comm_rt;
  158. };
  159. struct wasm_table_t {
  160. wasm_store_t *store;
  161. wasm_name_t *module_name;
  162. wasm_name_t *name;
  163. uint16 kind;
  164. struct wasm_host_info host_info;
  165. wasm_tabletype_t *type;
  166. /*
  167. * an index in both table runtime instance lists
  168. * of interpreter mode and aot mode
  169. */
  170. uint16 table_idx_rt;
  171. WASMModuleInstanceCommon *inst_comm_rt;
  172. };
  173. struct wasm_extern_t {
  174. wasm_store_t *store;
  175. wasm_name_t *module_name;
  176. wasm_name_t *name;
  177. wasm_externkind_t kind;
  178. /* reserved space */
  179. uint8 data[1];
  180. };
  181. struct wasm_instance_t {
  182. wasm_store_t *store;
  183. wasm_extern_vec_t *exports;
  184. struct wasm_host_info host_info;
  185. WASMModuleInstanceCommon *inst_comm_rt;
  186. };
  187. wasm_ref_t *
  188. wasm_ref_new_internal(wasm_store_t *store, enum wasm_reference_kind kind,
  189. uint32 obj_idx_rt,
  190. WASMModuleInstanceCommon *inst_comm_rt);
  191. wasm_foreign_t *
  192. wasm_foreign_new_internal(wasm_store_t *store, uint32 foreign_idx_rt,
  193. WASMModuleInstanceCommon *inst_comm_rt);
  194. wasm_func_t *
  195. wasm_func_new_internal(wasm_store_t *store, uint16 func_idx_rt,
  196. WASMModuleInstanceCommon *inst_comm_rt);
  197. wasm_global_t *
  198. wasm_global_new_internal(wasm_store_t *store, uint16 global_idx_rt,
  199. WASMModuleInstanceCommon *inst_comm_rt);
  200. wasm_memory_t *
  201. wasm_memory_new_internal(wasm_store_t *store, uint16 memory_idx_rt,
  202. WASMModuleInstanceCommon *inst_comm_rt);
  203. wasm_table_t *
  204. wasm_table_new_internal(wasm_store_t *store, uint16 table_idx_rt,
  205. WASMModuleInstanceCommon *inst_comm_rt);
  206. void
  207. wasm_frame_vec_clone_internal(Vector *src, Vector *out);
  208. #endif /* _WASM_C_API_INTERNAL_H */