wasm_c_api_internal.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. wasm_store_vec_t *stores;
  23. uint32 ref_count;
  24. /* list of wasm_module_ex_t */
  25. Vector modules;
  26. };
  27. struct wasm_store_t {
  28. /* maybe should remove the list */
  29. wasm_module_vec_t *modules;
  30. wasm_instance_vec_t *instances;
  31. Vector *foreigns;
  32. };
  33. /* Type Representations */
  34. struct wasm_valtype_t {
  35. wasm_valkind_t kind;
  36. };
  37. struct wasm_functype_t {
  38. uint32 extern_kind;
  39. /* gona to new and delete own */
  40. wasm_valtype_vec_t *params;
  41. wasm_valtype_vec_t *results;
  42. };
  43. struct wasm_globaltype_t {
  44. uint32 extern_kind;
  45. /* gona to new and delete own */
  46. wasm_valtype_t *val_type;
  47. wasm_mutability_t mutability;
  48. };
  49. struct wasm_tabletype_t {
  50. uint32 extern_kind;
  51. wasm_valtype_t *val_type;
  52. wasm_limits_t limits;
  53. };
  54. struct wasm_memorytype_t {
  55. uint32 extern_kind;
  56. wasm_limits_t limits;
  57. };
  58. struct wasm_externtype_t {
  59. uint32 extern_kind;
  60. /* reservered space */
  61. uint8 data[1];
  62. };
  63. struct wasm_importtype_t {
  64. wasm_name_t *module_name;
  65. wasm_name_t *name;
  66. wasm_externtype_t *extern_type;
  67. };
  68. struct wasm_exporttype_t {
  69. wasm_name_t *name;
  70. wasm_externtype_t *extern_type;
  71. };
  72. /* Runtime Objects */
  73. enum wasm_reference_kind {
  74. WASM_REF_foreign,
  75. WASM_REF_func,
  76. WASM_REF_global,
  77. WASM_REF_memory,
  78. WASM_REF_table,
  79. };
  80. struct wasm_host_info {
  81. void *info;
  82. void (*finalizer)(void *);
  83. };
  84. struct wasm_ref_t {
  85. wasm_store_t *store;
  86. enum wasm_reference_kind kind;
  87. struct wasm_host_info host_info;
  88. uint32 ref_idx_rt;
  89. WASMModuleInstanceCommon *inst_comm_rt;
  90. };
  91. struct wasm_trap_t {
  92. wasm_byte_vec_t *message;
  93. Vector *frames;
  94. };
  95. struct wasm_foreign_t {
  96. wasm_store_t *store;
  97. enum wasm_reference_kind kind;
  98. struct wasm_host_info host_info;
  99. int32 ref_cnt;
  100. uint32 foreign_idx_rt;
  101. WASMModuleInstanceCommon *inst_comm_rt;
  102. };
  103. struct wasm_func_t {
  104. wasm_store_t *store;
  105. wasm_name_t *module_name;
  106. wasm_name_t *name;
  107. uint16 kind;
  108. struct wasm_host_info host_info;
  109. wasm_functype_t *type;
  110. bool with_env;
  111. union {
  112. wasm_func_callback_t cb;
  113. struct callback_ext {
  114. void *env;
  115. wasm_func_callback_with_env_t cb;
  116. void (*finalizer)(void *);
  117. } cb_env;
  118. } u;
  119. /*
  120. * an index in both functions runtime instance lists
  121. * of interpreter mode and aot mode
  122. */
  123. uint16 func_idx_rt;
  124. WASMModuleInstanceCommon *inst_comm_rt;
  125. WASMFunctionInstanceCommon *func_comm_rt;
  126. };
  127. struct wasm_global_t {
  128. wasm_store_t *store;
  129. wasm_name_t *module_name;
  130. wasm_name_t *name;
  131. uint16 kind;
  132. struct wasm_host_info host_info;
  133. wasm_globaltype_t *type;
  134. wasm_val_t *init;
  135. /*
  136. * an index in both global runtime instance lists
  137. * of interpreter mode and aot mode
  138. */
  139. uint16 global_idx_rt;
  140. WASMModuleInstanceCommon *inst_comm_rt;
  141. };
  142. struct wasm_memory_t {
  143. wasm_store_t *store;
  144. wasm_name_t *module_name;
  145. wasm_name_t *name;
  146. uint16 kind;
  147. struct wasm_host_info host_info;
  148. wasm_memorytype_t *type;
  149. /*
  150. * an index in both memory runtime instance lists
  151. * of interpreter mode and aot mode
  152. */
  153. uint16 memory_idx_rt;
  154. WASMModuleInstanceCommon *inst_comm_rt;
  155. };
  156. struct wasm_table_t {
  157. wasm_store_t *store;
  158. wasm_name_t *module_name;
  159. wasm_name_t *name;
  160. uint16 kind;
  161. struct wasm_host_info host_info;
  162. wasm_tabletype_t *type;
  163. /*
  164. * an index in both table runtime instance lists
  165. * of interpreter mode and aot mode
  166. */
  167. uint16 table_idx_rt;
  168. WASMModuleInstanceCommon *inst_comm_rt;
  169. };
  170. struct wasm_extern_t {
  171. wasm_store_t *store;
  172. wasm_name_t *module_name;
  173. wasm_name_t *name;
  174. wasm_externkind_t kind;
  175. /* reservered space */
  176. uint8 data[1];
  177. };
  178. struct wasm_instance_t {
  179. wasm_store_t *store;
  180. wasm_extern_vec_t *exports;
  181. struct wasm_host_info host_info;
  182. WASMModuleInstanceCommon *inst_comm_rt;
  183. };
  184. wasm_ref_t *
  185. wasm_ref_new_internal(wasm_store_t *store, enum wasm_reference_kind kind,
  186. uint32 obj_idx_rt,
  187. WASMModuleInstanceCommon *inst_comm_rt);
  188. wasm_foreign_t *
  189. wasm_foreign_new_internal(wasm_store_t *store, uint32 foreign_idx_rt,
  190. WASMModuleInstanceCommon *inst_comm_rt);
  191. wasm_func_t *
  192. wasm_func_new_internal(wasm_store_t *store, uint16 func_idx_rt,
  193. WASMModuleInstanceCommon *inst_comm_rt);
  194. wasm_global_t *
  195. wasm_global_new_internal(wasm_store_t *store, uint16 global_idx_rt,
  196. WASMModuleInstanceCommon *inst_comm_rt);
  197. wasm_memory_t *
  198. wasm_memory_new_internal(wasm_store_t *store, uint16 memory_idx_rt,
  199. WASMModuleInstanceCommon *inst_comm_rt);
  200. wasm_table_t *
  201. wasm_table_new_internal(wasm_store_t *store, uint16 table_idx_rt,
  202. WASMModuleInstanceCommon *inst_comm_rt);
  203. #endif /* _WASM_C_API_INTERNAL_H */