gc_common.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "../wasm_runtime_common.h"
  6. #if WASM_ENABLE_INTERP != 0
  7. #include "../interpreter/wasm_runtime.h"
  8. #endif
  9. #if WASM_ENABLE_AOT != 0
  10. #include "../aot/aot_runtime.h"
  11. #endif
  12. uint32
  13. wasm_get_defined_type_count(WASMModuleCommon *const module)
  14. {
  15. /* TODO */
  16. return 0;
  17. }
  18. WASMType *
  19. wasm_get_defined_type(WASMModuleCommon *const module, uint32 index)
  20. {
  21. /* TODO */
  22. return NULL;
  23. }
  24. bool
  25. wasm_defined_type_is_func_type(WASMType *const def_type)
  26. {
  27. /* TODO */
  28. return false;
  29. }
  30. bool
  31. wasm_defined_type_is_struct_type(WASMType *const def_type)
  32. {
  33. /* TODO */
  34. return false;
  35. }
  36. bool
  37. wasm_defined_type_is_array_type(WASMType *const def_type)
  38. {
  39. /* TODO */
  40. return false;
  41. }
  42. uint32
  43. wasm_func_type_get_param_count(WASMFuncType *const func_type)
  44. {
  45. /* TODO */
  46. return 0;
  47. }
  48. wasm_ref_type_t
  49. wasm_func_type_get_param_type(WASMFuncType *const func_type, uint32 param_idx)
  50. {
  51. wasm_ref_type_t ref_type = { 0 };
  52. /* TODO */
  53. return ref_type;
  54. }
  55. uint32
  56. wasm_func_type_get_result_count(WASMFuncType *const func_type)
  57. {
  58. /* TODO */
  59. return 0;
  60. }
  61. wasm_ref_type_t
  62. wasm_func_type_get_result_type(WASMFuncType *const func_type, uint32 param_idx)
  63. {
  64. wasm_ref_type_t ref_type = { 0 };
  65. /* TODO */
  66. return ref_type;
  67. }
  68. uint32
  69. wasm_struct_type_get_field_count(WASMStructType *const struct_type)
  70. {
  71. /* TODO */
  72. return 0;
  73. }
  74. wasm_ref_type_t
  75. wasm_struct_type_get_field_type(WASMStructType *const struct_type,
  76. uint32 field_idx, bool *p_is_mutable)
  77. {
  78. wasm_ref_type_t ref_type = { 0 };
  79. /* TODO */
  80. return ref_type;
  81. }
  82. wasm_ref_type_t
  83. wasm_array_type_get_elem_type(WASMArrayType *const array_type,
  84. bool *p_is_mutable)
  85. {
  86. wasm_ref_type_t ref_type = { 0 };
  87. /* TODO */
  88. return ref_type;
  89. }
  90. bool
  91. wasm_defined_type_equal(WASMType *const def_type1, WASMType *const def_type2,
  92. WASMModuleCommon *const module)
  93. {
  94. /* TODO */
  95. return false;
  96. }
  97. bool
  98. wasm_defined_type_is_subtype_of(WASMType *const def_type1,
  99. WASMType *const def_type2,
  100. WASMModuleCommon *const module)
  101. {
  102. /* TODO */
  103. return false;
  104. }
  105. void
  106. wasm_ref_type_set_type_idx(wasm_ref_type_t *ref_type, bool nullable,
  107. int32 type_idx)
  108. {
  109. /* TODO */
  110. }
  111. void
  112. wasm_ref_type_set_heap_type(wasm_ref_type_t *ref_type, bool nullable,
  113. int32 heap_type)
  114. {
  115. /* TODO */
  116. }
  117. bool
  118. wasm_ref_type_equal(const wasm_ref_type_t *ref_type1,
  119. const wasm_ref_type_t *ref_type2,
  120. WASMModuleCommon *const module)
  121. {
  122. /* TODO */
  123. return false;
  124. }
  125. bool
  126. wasm_ref_type_is_subtype_of(const wasm_ref_type_t *ref_type1,
  127. const wasm_ref_type_t *ref_type2,
  128. WASMModuleCommon *const module)
  129. {
  130. /* TODO */
  131. return false;
  132. }
  133. WASMStructObjectRef
  134. wasm_struct_obj_new_with_typeidx(WASMExecEnv *exec_env, uint32 type_idx)
  135. {
  136. /* TODO */
  137. return NULL;
  138. }
  139. WASMStructObjectRef
  140. wasm_struct_obj_new_with_type(WASMExecEnv *exec_env, WASMStructType *type)
  141. {
  142. /* TODO */
  143. return NULL;
  144. }
  145. WASMArrayObjectRef
  146. wasm_array_obj_new_with_typeidx(WASMExecEnv *exec_env, uint32 type_idx)
  147. {
  148. /* TODO */
  149. return NULL;
  150. }
  151. WASMArrayObjectRef
  152. wasm_array_obj_new_with_type(WASMExecEnv *exec_env, WASMArrayType *type)
  153. {
  154. /* TODO */
  155. return NULL;
  156. }
  157. WASMFuncObjectRef
  158. wasm_func_obj_new_with_typeidx(WASMExecEnv *exec_env, uint32 type_idx)
  159. {
  160. /* TODO */
  161. return NULL;
  162. }
  163. WASMFuncObjectRef
  164. wasm_func_obj_new_with_type(WASMExecEnv *exec_env, WASMFuncType *type)
  165. {
  166. /* TODO */
  167. return NULL;
  168. }
  169. bool
  170. wasm_obj_is_instance_of_defined_type(WASMObjectRef obj, WASMType *defined_type,
  171. WASMModuleCommon *const module)
  172. {
  173. /* TODO */
  174. return false;
  175. }
  176. bool
  177. wasm_obj_is_instance_of_type_idx(WASMObjectRef obj, uint32 type_idx,
  178. WASMModuleCommon *const module)
  179. {
  180. /* TODO */
  181. return false;
  182. }
  183. bool
  184. wasm_obj_is_instance_of_ref_type(const WASMObjectRef obj,
  185. const wasm_ref_type_t *ref_type)
  186. {
  187. /* TODO */
  188. return false;
  189. }
  190. void
  191. wasm_runtime_push_local_object_ref(WASMExecEnv *exec_env,
  192. WASMLocalObjectRef *ref)
  193. {
  194. ref->val = NULL;
  195. ref->prev = exec_env->cur_local_object_ref;
  196. exec_env->cur_local_object_ref = ref;
  197. }
  198. WASMLocalObjectRef *
  199. wasm_runtime_pop_local_object_ref(WASMExecEnv *exec_env)
  200. {
  201. WASMLocalObjectRef *local_ref = exec_env->cur_local_object_ref;
  202. exec_env->cur_local_object_ref = exec_env->cur_local_object_ref->prev;
  203. return local_ref;
  204. }
  205. void
  206. wasm_runtime_pop_local_object_refs(WASMExecEnv *exec_env, uint32 n)
  207. {
  208. bh_assert(n > 0);
  209. do {
  210. exec_env->cur_local_object_ref = exec_env->cur_local_object_ref->prev;
  211. } while (--n > 0);
  212. }
  213. void
  214. wasm_runtime_gc_prepare(WASMExecEnv *exec_env)
  215. {
  216. #if 0
  217. /* TODO: implement wasm_runtime_gc_prepare for multi-thread */
  218. exec_env->is_gc_reclaiming = false;
  219. wasm_thread_suspend_all();
  220. exec_env->is_gc_reclaim = 1;
  221. exec_env->requesting_suspend = 0;
  222. #endif
  223. }
  224. void
  225. wasm_runtime_gc_finalize(WASMExecEnv *exec_env)
  226. {
  227. #if 0
  228. /* TODO: implement wasm_runtime_gc_finalize for multi-thread */
  229. wasm_thread_resume_all();
  230. exec_env->doing_gc_reclaim = 0;
  231. #endif
  232. }
  233. bool
  234. wasm_runtime_get_wasm_object_ref_list(WASMObjectRef obj,
  235. bool *p_is_compact_mode,
  236. uint32 *p_ref_num, uint16 **p_ref_list,
  237. uint32 *p_ref_start_offset)
  238. {
  239. return wasm_object_get_ref_list(obj, p_is_compact_mode, p_ref_num,
  240. p_ref_list, p_ref_start_offset);
  241. }
  242. bool
  243. wasm_runtime_traverse_gc_rootset(WASMExecEnv *exec_env, void *heap)
  244. {
  245. #if WASM_ENABLE_INTERP != 0
  246. if (exec_env->module_inst->module_type == Wasm_Module_Bytecode) {
  247. return wasm_traverse_gc_rootset(exec_env, heap);
  248. }
  249. #endif
  250. #if WASM_ENABLE_AOT != 0
  251. if (exec_env->module_inst->module_type == Wasm_Module_AoT) {
  252. /* TODO */
  253. /*return aot_traverse_gc_rootset(exec_env, heap);*/
  254. }
  255. #endif
  256. return false;
  257. }
  258. void
  259. wasm_runtime_set_gc_heap_handle(WASMModuleInstanceCommon *module_inst,
  260. void *gc_heap_handle)
  261. {
  262. #if WASM_ENABLE_INTERP != 0
  263. if (module_inst->module_type == Wasm_Module_Bytecode)
  264. ((WASMModuleInstance *)module_inst)->e->gc_heap_handle = gc_heap_handle;
  265. #endif
  266. #if WASM_ENABLE_AOT != 0
  267. if (module_inst->module_type == Wasm_Module_AoT) {
  268. /* TODO */
  269. /*
  270. ((AOTModuleInstance *)module_inst)->e->gc_heap_handle.ptr =
  271. gc_heap_handle;
  272. */
  273. }
  274. #endif
  275. }
  276. void *
  277. wasm_runtime_get_gc_heap_handle(WASMModuleInstanceCommon *module_inst)
  278. {
  279. #if WASM_ENABLE_INTERP != 0
  280. if (module_inst->module_type == Wasm_Module_Bytecode)
  281. return ((WASMModuleInstance *)module_inst)->e->gc_heap_handle;
  282. #endif
  283. #if WASM_ENABLE_AOT != 0
  284. if (module_inst->module_type == Wasm_Module_AoT) {
  285. /* TODO */
  286. /*
  287. return ((AOTModuleInstance *)module_inst)->e->gc_heap_handle.ptr;
  288. */
  289. }
  290. #endif
  291. return NULL;
  292. }