krillplayer-plugin 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/LICENSE +2 -1
  2. package/README.md +1 -0
  3. package/dist/cli.js +351 -73
  4. package/dist/crypto.js +37 -11
  5. package/dist/engine/engine.c +6 -3
  6. package/kernel/Sources/CQuickJS/include/kernel_qjs.h +8 -1
  7. package/kernel/Sources/CQuickJS/kernel_internal.h +54 -0
  8. package/kernel/Sources/CQuickJS/kernel_qjs.c +17 -29
  9. package/kernel/Sources/CQuickJS/kernel_wasm.c +1155 -0
  10. package/kernel/Sources/CWAMR/include/kernel_wamr.h +151 -0
  11. package/kernel/Sources/CWAMR/include/kernel_wamr_config.h +66 -0
  12. package/kernel/Sources/CWAMR/vendor/LICENSE +219 -0
  13. package/kernel/Sources/CWAMR/vendor/core/config.h +727 -0
  14. package/kernel/Sources/CWAMR/vendor/core/iwasm/aot/aot_runtime.h +899 -0
  15. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/arch/invokeNative_general.c +123 -0
  16. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_application.c +933 -0
  17. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_blocking_op.c +92 -0
  18. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_c_api.c +5391 -0
  19. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_c_api_internal.h +246 -0
  20. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_exec_env.c +336 -0
  21. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_exec_env.h +328 -0
  22. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_loader_common.c +242 -0
  23. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_loader_common.h +62 -0
  24. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_memory.c +1999 -0
  25. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_memory.h +154 -0
  26. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_native.c +1532 -0
  27. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_native.h +117 -0
  28. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_runtime_common.c +8070 -0
  29. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_runtime_common.h +1396 -0
  30. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_shared_memory.c +477 -0
  31. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_shared_memory.h +63 -0
  32. package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_suspend_flags.h +52 -0
  33. package/kernel/Sources/CWAMR/vendor/core/iwasm/compilation/aot.h +366 -0
  34. package/kernel/Sources/CWAMR/vendor/core/iwasm/include/lib_export.h +60 -0
  35. package/kernel/Sources/CWAMR/vendor/core/iwasm/include/wasm_c_api.h +910 -0
  36. package/kernel/Sources/CWAMR/vendor/core/iwasm/include/wasm_export.h +2440 -0
  37. package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm.h +1492 -0
  38. package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_interp.h +122 -0
  39. package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_interp_fast.c +7998 -0
  40. package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_loader.c +16909 -0
  41. package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_loader.h +80 -0
  42. package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_opcode.h +1043 -0
  43. package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_runtime.c +5174 -0
  44. package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_runtime.h +912 -0
  45. package/kernel/Sources/CWAMR/vendor/core/iwasm/libraries/thread-mgr/thread_manager.c +1569 -0
  46. package/kernel/Sources/CWAMR/vendor/core/iwasm/libraries/thread-mgr/thread_manager.h +256 -0
  47. package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/ems/ems_alloc.c +1169 -0
  48. package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/ems/ems_gc.c +497 -0
  49. package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/ems/ems_gc.h +350 -0
  50. package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/ems/ems_gc_internal.h +384 -0
  51. package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/ems/ems_hmu.c +95 -0
  52. package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/ems/ems_kfc.c +547 -0
  53. package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/mem_alloc.c +252 -0
  54. package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/mem_alloc.h +96 -0
  55. package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/memory/mremap.c +12 -0
  56. package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/posix/posix_blocking_op.c +70 -0
  57. package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/posix/posix_malloc.c +72 -0
  58. package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/posix/posix_memmap.c +302 -0
  59. package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/posix/posix_sleep.c +20 -0
  60. package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/posix/posix_thread.c +784 -0
  61. package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/posix/posix_time.c +28 -0
  62. package/kernel/Sources/CWAMR/vendor/core/shared/platform/darwin/platform_init.c +43 -0
  63. package/kernel/Sources/CWAMR/vendor/core/shared/platform/darwin/platform_internal.h +126 -0
  64. package/kernel/Sources/CWAMR/vendor/core/shared/platform/include/platform_api_extension.h +1676 -0
  65. package/kernel/Sources/CWAMR/vendor/core/shared/platform/include/platform_api_vmcore.h +192 -0
  66. package/kernel/Sources/CWAMR/vendor/core/shared/platform/include/platform_common.h +204 -0
  67. package/kernel/Sources/CWAMR/vendor/core/shared/platform/include/platform_wasi_types.h +610 -0
  68. package/kernel/Sources/CWAMR/vendor/core/shared/platform/linux/platform_init.c +43 -0
  69. package/kernel/Sources/CWAMR/vendor/core/shared/platform/linux/platform_internal.h +139 -0
  70. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_assert.c +25 -0
  71. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_assert.h +42 -0
  72. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_atomic.h +300 -0
  73. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_bitmap.c +27 -0
  74. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_bitmap.h +114 -0
  75. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_common.c +217 -0
  76. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_common.h +83 -0
  77. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_hashmap.c +339 -0
  78. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_hashmap.h +168 -0
  79. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_leb128.c +77 -0
  80. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_leb128.h +30 -0
  81. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_list.c +111 -0
  82. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_list.h +109 -0
  83. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_log.c +111 -0
  84. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_log.h +94 -0
  85. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_platform.h +38 -0
  86. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_queue.c +256 -0
  87. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_queue.h +80 -0
  88. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_vector.c +279 -0
  89. package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_vector.h +126 -0
  90. package/kernel/Sources/CWAMR/vendor/core/shared/utils/gnuc.h +14 -0
  91. package/kernel/Sources/CWAMR/vendor/core/shared/utils/runtime_timer.c +469 -0
  92. package/kernel/Sources/CWAMR/vendor/core/shared/utils/runtime_timer.h +51 -0
  93. package/kernel/Sources/CWAMR/vendor/core/version.h +24 -0
  94. package/kernel/Sources/CWAMR/wamr_bh_assert.c +98 -0
  95. package/kernel/Sources/CWAMR/wamr_bh_bitmap.c +98 -0
  96. package/kernel/Sources/CWAMR/wamr_bh_common.c +98 -0
  97. package/kernel/Sources/CWAMR/wamr_bh_hashmap.c +98 -0
  98. package/kernel/Sources/CWAMR/wamr_bh_leb128.c +98 -0
  99. package/kernel/Sources/CWAMR/wamr_bh_list.c +98 -0
  100. package/kernel/Sources/CWAMR/wamr_bh_log.c +98 -0
  101. package/kernel/Sources/CWAMR/wamr_bh_queue.c +98 -0
  102. package/kernel/Sources/CWAMR/wamr_bh_vector.c +98 -0
  103. package/kernel/Sources/CWAMR/wamr_ems_alloc.c +98 -0
  104. package/kernel/Sources/CWAMR/wamr_ems_gc.c +98 -0
  105. package/kernel/Sources/CWAMR/wamr_ems_hmu.c +98 -0
  106. package/kernel/Sources/CWAMR/wamr_ems_kfc.c +98 -0
  107. package/kernel/Sources/CWAMR/wamr_invokeNative_general.c +98 -0
  108. package/kernel/Sources/CWAMR/wamr_mem_alloc.c +98 -0
  109. package/kernel/Sources/CWAMR/wamr_mremap.c +98 -0
  110. package/kernel/Sources/CWAMR/wamr_platform_init_darwin.c +100 -0
  111. package/kernel/Sources/CWAMR/wamr_platform_init_linux.c +100 -0
  112. package/kernel/Sources/CWAMR/wamr_posix_blocking_op.c +98 -0
  113. package/kernel/Sources/CWAMR/wamr_posix_malloc.c +98 -0
  114. package/kernel/Sources/CWAMR/wamr_posix_memmap.c +98 -0
  115. package/kernel/Sources/CWAMR/wamr_posix_sleep.c +98 -0
  116. package/kernel/Sources/CWAMR/wamr_posix_thread.c +98 -0
  117. package/kernel/Sources/CWAMR/wamr_posix_time.c +98 -0
  118. package/kernel/Sources/CWAMR/wamr_runtime_timer.c +98 -0
  119. package/kernel/Sources/CWAMR/wamr_thread_manager.c +98 -0
  120. package/kernel/Sources/CWAMR/wamr_wasm_application.c +98 -0
  121. package/kernel/Sources/CWAMR/wamr_wasm_blocking_op.c +98 -0
  122. package/kernel/Sources/CWAMR/wamr_wasm_c_api.c +98 -0
  123. package/kernel/Sources/CWAMR/wamr_wasm_exec_env.c +98 -0
  124. package/kernel/Sources/CWAMR/wamr_wasm_interp_fast.c +98 -0
  125. package/kernel/Sources/CWAMR/wamr_wasm_loader.c +98 -0
  126. package/kernel/Sources/CWAMR/wamr_wasm_loader_common.c +98 -0
  127. package/kernel/Sources/CWAMR/wamr_wasm_memory.c +98 -0
  128. package/kernel/Sources/CWAMR/wamr_wasm_native.c +98 -0
  129. package/kernel/Sources/CWAMR/wamr_wasm_runtime.c +98 -0
  130. package/kernel/Sources/CWAMR/wamr_wasm_runtime_common.c +98 -0
  131. package/kernel/Sources/CWAMR/wamr_wasm_shared_memory.c +98 -0
  132. package/kernel/Sources/Kernel/PluginPrelude.js +5 -2
  133. package/kernel/Tests/KernelTests/CasePins.js +50 -0
  134. package/package.json +2 -2
  135. package/skill/krillplayer-plugin/SKILL.md +2 -0
  136. package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-content-rejected.json +8 -4
  137. package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-login-expired.json +8 -4
  138. package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-muted.json +8 -4
  139. package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-other.json +8 -4
  140. package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-rate-limited.json +8 -4
  141. package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-sent.json +8 -4
  142. package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live-logged-in.json +39 -0
  143. package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live-selected-backup-line.json +8 -0
  144. package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live-selected-line-gone.json +8 -0
  145. package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live.json +8 -0
  146. package/skill/krillplayer-plugin/assets/samples/live-video-platform/plugin.ts +26 -9
  147. package/skill/krillplayer-plugin/references/cases.md +19 -1
  148. package/skill/krillplayer-plugin/references/contract.d.ts +104 -11
  149. package/skill/krillplayer-plugin/references/crypto-tools.md +104 -0
  150. package/skill/krillplayer-plugin/references/errors-and-fixes.md +5 -1
@@ -0,0 +1,1532 @@
1
+ /*
2
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
+ */
5
+
6
+ #include "wasm_native.h"
7
+ #include "wasm_runtime_common.h"
8
+ #include "bh_log.h"
9
+ #if WASM_ENABLE_INTERP != 0
10
+ #include "../interpreter/wasm_runtime.h"
11
+ #endif
12
+ #if WASM_ENABLE_AOT != 0
13
+ #include "../aot/aot_runtime.h"
14
+ #endif
15
+ #if WASM_ENABLE_THREAD_MGR != 0
16
+ #include "../libraries/thread-mgr/thread_manager.h"
17
+ #endif
18
+ #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
19
+ #include "wasi_nn_host.h"
20
+ #endif
21
+
22
+ static NativeSymbolsList g_native_symbols_list = NULL;
23
+
24
+ #if WASM_ENABLE_LIBC_WASI != 0
25
+ static void *g_wasi_context_key;
26
+ #endif /* WASM_ENABLE_LIBC_WASI */
27
+
28
+ uint32
29
+ get_libc_builtin_export_apis(NativeSymbol **p_libc_builtin_apis);
30
+
31
+ #if WASM_ENABLE_SPEC_TEST != 0
32
+ uint32
33
+ get_spectest_export_apis(NativeSymbol **p_libc_builtin_apis);
34
+ #endif
35
+
36
+ #if WASM_ENABLE_SHARED_HEAP != 0
37
+ uint32
38
+ get_lib_shared_heap_export_apis(NativeSymbol **p_shared_heap_apis);
39
+ #endif
40
+
41
+ uint32
42
+ get_libc_wasi_export_apis(NativeSymbol **p_libc_wasi_apis);
43
+
44
+ uint32
45
+ get_base_lib_export_apis(NativeSymbol **p_base_lib_apis);
46
+
47
+ uint32
48
+ get_ext_lib_export_apis(NativeSymbol **p_ext_lib_apis);
49
+
50
+ #if WASM_ENABLE_LIB_PTHREAD != 0
51
+ bool
52
+ lib_pthread_init();
53
+
54
+ void
55
+ lib_pthread_destroy();
56
+
57
+ uint32
58
+ get_lib_pthread_export_apis(NativeSymbol **p_lib_pthread_apis);
59
+ #endif
60
+
61
+ #if WASM_ENABLE_LIB_WASI_THREADS != 0
62
+ bool
63
+ lib_wasi_threads_init(void);
64
+
65
+ void
66
+ lib_wasi_threads_destroy(void);
67
+
68
+ uint32
69
+ get_lib_wasi_threads_export_apis(NativeSymbol **p_lib_wasi_threads_apis);
70
+ #endif
71
+
72
+ uint32
73
+ get_libc_emcc_export_apis(NativeSymbol **p_libc_emcc_apis);
74
+
75
+ uint32
76
+ get_lib_rats_export_apis(NativeSymbol **p_lib_rats_apis);
77
+
78
+ static bool
79
+ compare_type_with_signature(uint8 type, const char signature)
80
+ {
81
+ const char num_sig_map[] = { 'F', 'f', 'I', 'i' };
82
+
83
+ if (VALUE_TYPE_F64 <= type && type <= VALUE_TYPE_I32
84
+ && signature == num_sig_map[type - VALUE_TYPE_F64]) {
85
+ return true;
86
+ }
87
+
88
+ #if WASM_ENABLE_REF_TYPES != 0
89
+ if ('r' == signature
90
+ #if WASM_ENABLE_GC != 0
91
+ #if WASM_ENABLE_STRINGREF != 0
92
+ && (type >= REF_TYPE_STRINGVIEWITER && type <= REF_TYPE_NULLFUNCREF)
93
+ #else
94
+ && (type >= REF_TYPE_HT_NULLABLE && type <= REF_TYPE_NULLFUNCREF)
95
+ #endif
96
+ #else
97
+ && type == VALUE_TYPE_EXTERNREF
98
+ #endif
99
+ )
100
+ return true;
101
+ #endif
102
+
103
+ /* TODO: a v128 parameter */
104
+ return false;
105
+ }
106
+
107
+ static bool
108
+ check_symbol_signature(const WASMFuncType *type, const char *signature)
109
+ {
110
+ const char *p = signature, *p_end;
111
+ char sig;
112
+ uint32 i = 0;
113
+
114
+ if (!p || strlen(p) < 2)
115
+ return false;
116
+
117
+ p_end = p + strlen(signature);
118
+
119
+ if (*p++ != '(')
120
+ return false;
121
+
122
+ if ((uint32)(p_end - p) < (uint32)(type->param_count + 1))
123
+ /* signatures of parameters, and ')' */
124
+ return false;
125
+
126
+ for (i = 0; i < type->param_count; i++) {
127
+ sig = *p++;
128
+
129
+ /* a f64/f32/i64/i32/externref parameter */
130
+ if (compare_type_with_signature(type->types[i], sig))
131
+ continue;
132
+
133
+ /* a pointer/string parameter */
134
+ if (type->types[i] != VALUE_TYPE_I32)
135
+ /* pointer and string must be i32 type */
136
+ return false;
137
+
138
+ if (sig == '*') {
139
+ /* it is a pointer */
140
+ if (i + 1 < type->param_count
141
+ && type->types[i + 1] == VALUE_TYPE_I32 && *p == '~') {
142
+ /* pointer length followed */
143
+ i++;
144
+ p++;
145
+ }
146
+ }
147
+ else if (sig == '$') {
148
+ /* it is a string */
149
+ }
150
+ else {
151
+ /* invalid signature */
152
+ return false;
153
+ }
154
+ }
155
+
156
+ if (*p++ != ')')
157
+ return false;
158
+
159
+ if (type->result_count) {
160
+ if (p >= p_end)
161
+ return false;
162
+
163
+ /* result types includes: f64,f32,i64,i32,externref */
164
+ if (!compare_type_with_signature(type->types[i], *p))
165
+ return false;
166
+
167
+ p++;
168
+ }
169
+
170
+ if (*p != '\0')
171
+ return false;
172
+
173
+ return true;
174
+ }
175
+
176
+ static int
177
+ native_symbol_cmp(const void *native_symbol1, const void *native_symbol2)
178
+ {
179
+ return strcmp(((const NativeSymbol *)native_symbol1)->symbol,
180
+ ((const NativeSymbol *)native_symbol2)->symbol);
181
+ }
182
+
183
+ static void *
184
+ lookup_symbol(NativeSymbol *native_symbols, uint32 n_native_symbols,
185
+ const char *symbol, const char **p_signature, void **p_attachment)
186
+ {
187
+ NativeSymbol *native_symbol, key = { 0 };
188
+
189
+ key.symbol = symbol;
190
+
191
+ if ((native_symbol = bsearch(&key, native_symbols, n_native_symbols,
192
+ sizeof(NativeSymbol), native_symbol_cmp))) {
193
+ *p_signature = native_symbol->signature;
194
+ *p_attachment = native_symbol->attachment;
195
+ return native_symbol->func_ptr;
196
+ }
197
+
198
+ return NULL;
199
+ }
200
+
201
+ /**
202
+ * allow func_type and all outputs, like p_signature, p_attachment and
203
+ * p_call_conv_raw to be NULL
204
+ */
205
+ void *
206
+ wasm_native_resolve_symbol(const char *module_name, const char *field_name,
207
+ const WASMFuncType *func_type,
208
+ const char **p_signature, void **p_attachment,
209
+ bool *p_call_conv_raw)
210
+ {
211
+ NativeSymbolsNode *node, *node_next;
212
+ const char *signature = NULL;
213
+ void *func_ptr = NULL, *attachment = NULL;
214
+
215
+ node = g_native_symbols_list;
216
+ while (node) {
217
+ node_next = node->next;
218
+ if (!strcmp(node->module_name, module_name)) {
219
+ if ((func_ptr =
220
+ lookup_symbol(node->native_symbols, node->n_native_symbols,
221
+ field_name, &signature, &attachment))
222
+ || (field_name[0] == '_'
223
+ && (func_ptr = lookup_symbol(
224
+ node->native_symbols, node->n_native_symbols,
225
+ field_name + 1, &signature, &attachment))))
226
+ break;
227
+ }
228
+ node = node_next;
229
+ }
230
+
231
+ if (!p_signature || !p_attachment || !p_call_conv_raw)
232
+ return func_ptr;
233
+
234
+ if (func_ptr) {
235
+ if (signature && signature[0] != '\0') {
236
+ /* signature is not empty, check its format */
237
+ if (!func_type || !check_symbol_signature(func_type, signature)) {
238
+ #if WASM_ENABLE_WAMR_COMPILER == 0
239
+ /* Output warning except running aot compiler */
240
+ LOG_WARNING("failed to check signature '%s' and resolve "
241
+ "pointer params for import function (%s, %s)\n",
242
+ signature, module_name, field_name);
243
+ #endif
244
+ return NULL;
245
+ }
246
+ else
247
+ /* Save signature for runtime to do pointer check and
248
+ address conversion */
249
+ *p_signature = signature;
250
+ }
251
+ else
252
+ /* signature is empty */
253
+ *p_signature = NULL;
254
+
255
+ *p_attachment = attachment;
256
+ *p_call_conv_raw = node->call_conv_raw;
257
+ }
258
+
259
+ return func_ptr;
260
+ }
261
+
262
+ static bool
263
+ register_natives(const char *module_name, NativeSymbol *native_symbols,
264
+ uint32 n_native_symbols, bool call_conv_raw)
265
+ {
266
+ NativeSymbolsNode *node;
267
+
268
+ if (!(node = wasm_runtime_malloc(sizeof(NativeSymbolsNode))))
269
+ return false;
270
+ #if WASM_ENABLE_MEMORY_TRACING != 0
271
+ os_printf("Register native, size: %u\n", sizeof(NativeSymbolsNode));
272
+ #endif
273
+
274
+ node->module_name = module_name;
275
+ node->native_symbols = native_symbols;
276
+ node->n_native_symbols = n_native_symbols;
277
+ node->call_conv_raw = call_conv_raw;
278
+
279
+ /* Add to list head */
280
+ node->next = g_native_symbols_list;
281
+ g_native_symbols_list = node;
282
+
283
+ qsort(native_symbols, n_native_symbols, sizeof(NativeSymbol),
284
+ native_symbol_cmp);
285
+
286
+ return true;
287
+ }
288
+
289
+ bool
290
+ wasm_native_register_natives(const char *module_name,
291
+ NativeSymbol *native_symbols,
292
+ uint32 n_native_symbols)
293
+ {
294
+ return register_natives(module_name, native_symbols, n_native_symbols,
295
+ false);
296
+ }
297
+
298
+ bool
299
+ wasm_native_register_natives_raw(const char *module_name,
300
+ NativeSymbol *native_symbols,
301
+ uint32 n_native_symbols)
302
+ {
303
+ return register_natives(module_name, native_symbols, n_native_symbols,
304
+ true);
305
+ }
306
+
307
+ bool
308
+ wasm_native_unregister_natives(const char *module_name,
309
+ NativeSymbol *native_symbols)
310
+ {
311
+ NativeSymbolsNode **prevp;
312
+ NativeSymbolsNode *node;
313
+
314
+ prevp = &g_native_symbols_list;
315
+ while ((node = *prevp) != NULL) {
316
+ if (node->native_symbols == native_symbols
317
+ && !strcmp(node->module_name, module_name)) {
318
+ *prevp = node->next;
319
+ wasm_runtime_free(node);
320
+ return true;
321
+ }
322
+ prevp = &node->next;
323
+ }
324
+ return false;
325
+ }
326
+
327
+ #if WASM_ENABLE_MODULE_INST_CONTEXT != 0
328
+ static uint32
329
+ context_key_to_idx(void *key)
330
+ {
331
+ bh_assert(key != NULL);
332
+ uint32 idx = (uint32)(uintptr_t)key;
333
+ bh_assert(idx > 0);
334
+ bh_assert(idx <= WASM_MAX_INSTANCE_CONTEXTS);
335
+ return idx - 1;
336
+ }
337
+
338
+ static void *
339
+ context_idx_to_key(uint32 idx)
340
+ {
341
+ bh_assert(idx < WASM_MAX_INSTANCE_CONTEXTS);
342
+ return (void *)(uintptr_t)(idx + 1);
343
+ }
344
+
345
+ typedef void (*dtor_t)(WASMModuleInstanceCommon *, void *);
346
+ static dtor_t g_context_dtors[WASM_MAX_INSTANCE_CONTEXTS];
347
+
348
+ static void
349
+ dtor_noop(WASMModuleInstanceCommon *inst, void *ctx)
350
+ {}
351
+
352
+ void *
353
+ wasm_native_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst,
354
+ void *ctx))
355
+ {
356
+ uint32 i;
357
+ for (i = 0; i < WASM_MAX_INSTANCE_CONTEXTS; i++) {
358
+ if (g_context_dtors[i] == NULL) {
359
+ if (dtor == NULL) {
360
+ dtor = dtor_noop;
361
+ }
362
+ g_context_dtors[i] = dtor;
363
+ return context_idx_to_key(i);
364
+ }
365
+ }
366
+ LOG_ERROR("failed to allocate instance context key");
367
+ return NULL;
368
+ }
369
+
370
+ void
371
+ wasm_native_destroy_context_key(void *key)
372
+ {
373
+ uint32 idx = context_key_to_idx(key);
374
+ bh_assert(g_context_dtors[idx] != NULL);
375
+ g_context_dtors[idx] = NULL;
376
+ }
377
+
378
+ static WASMModuleInstanceExtraCommon *
379
+ wasm_module_inst_extra_common(WASMModuleInstanceCommon *inst)
380
+ {
381
+ #if WASM_ENABLE_INTERP != 0
382
+ if (inst->module_type == Wasm_Module_Bytecode) {
383
+ return &((WASMModuleInstance *)inst)->e->common;
384
+ }
385
+ #endif
386
+ #if WASM_ENABLE_AOT != 0
387
+ if (inst->module_type == Wasm_Module_AoT) {
388
+ return &((AOTModuleInstanceExtra *)((AOTModuleInstance *)inst)->e)
389
+ ->common;
390
+ }
391
+ #endif
392
+ bh_assert(false);
393
+ return NULL;
394
+ }
395
+
396
+ void
397
+ wasm_native_set_context(WASMModuleInstanceCommon *inst, void *key, void *ctx)
398
+ {
399
+ uint32 idx = context_key_to_idx(key);
400
+ WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst);
401
+ common->contexts[idx] = ctx;
402
+ }
403
+
404
+ void
405
+ wasm_native_set_context_spread(WASMModuleInstanceCommon *inst, void *key,
406
+ void *ctx)
407
+ {
408
+ #if WASM_ENABLE_THREAD_MGR != 0
409
+ wasm_cluster_set_context(inst, key, ctx);
410
+ #else
411
+ wasm_native_set_context(inst, key, ctx);
412
+ #endif
413
+ }
414
+
415
+ void *
416
+ wasm_native_get_context(WASMModuleInstanceCommon *inst, void *key)
417
+ {
418
+ uint32 idx = context_key_to_idx(key);
419
+ WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst);
420
+ return common->contexts[idx];
421
+ }
422
+
423
+ void
424
+ wasm_native_call_context_dtors(WASMModuleInstanceCommon *inst)
425
+ {
426
+ WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst);
427
+ uint32 i;
428
+ for (i = 0; i < WASM_MAX_INSTANCE_CONTEXTS; i++) {
429
+ dtor_t dtor = g_context_dtors[i];
430
+ if (dtor != NULL) {
431
+ dtor(inst, common->contexts[i]);
432
+ }
433
+ }
434
+ }
435
+
436
+ void
437
+ wasm_native_inherit_contexts(WASMModuleInstanceCommon *child,
438
+ WASMModuleInstanceCommon *parent)
439
+ {
440
+ WASMModuleInstanceExtraCommon *parent_common =
441
+ wasm_module_inst_extra_common(parent);
442
+ WASMModuleInstanceExtraCommon *child_common =
443
+ wasm_module_inst_extra_common(child);
444
+ bh_memcpy_s(child_common->contexts,
445
+ sizeof(*child_common->contexts) * WASM_MAX_INSTANCE_CONTEXTS,
446
+ parent_common->contexts,
447
+ sizeof(*parent_common->contexts) * WASM_MAX_INSTANCE_CONTEXTS);
448
+ }
449
+ #endif /* WASM_ENABLE_MODULE_INST_CONTEXT != 0 */
450
+
451
+ #if WASM_ENABLE_LIBC_WASI != 0
452
+ WASIContext *
453
+ wasm_runtime_get_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm)
454
+ {
455
+ return wasm_native_get_context(module_inst_comm, g_wasi_context_key);
456
+ }
457
+
458
+ void
459
+ wasm_runtime_set_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm,
460
+ WASIContext *wasi_ctx)
461
+ {
462
+ wasm_native_set_context(module_inst_comm, g_wasi_context_key, wasi_ctx);
463
+ }
464
+
465
+ static void
466
+ wasi_context_dtor(WASMModuleInstanceCommon *inst, void *ctx)
467
+ {
468
+ if (ctx == NULL) {
469
+ return;
470
+ }
471
+ wasm_runtime_destroy_wasi(inst);
472
+ }
473
+ #endif /* end of WASM_ENABLE_LIBC_WASI */
474
+
475
+ #if WASM_ENABLE_QUICK_AOT_ENTRY != 0
476
+ static bool
477
+ quick_aot_entry_init(void);
478
+ #endif
479
+
480
+ bool
481
+ wasm_native_init()
482
+ {
483
+ #if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
484
+ || WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
485
+ || WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
486
+ || WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
487
+ || WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0 \
488
+ || WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
489
+ NativeSymbol *native_symbols;
490
+ uint32 n_native_symbols;
491
+ #endif
492
+
493
+ #if WASM_ENABLE_LIBC_BUILTIN != 0
494
+ n_native_symbols = get_libc_builtin_export_apis(&native_symbols);
495
+ if (!wasm_native_register_natives("env", native_symbols, n_native_symbols))
496
+ goto fail;
497
+ #endif /* WASM_ENABLE_LIBC_BUILTIN */
498
+
499
+ #if WASM_ENABLE_SPEC_TEST
500
+ n_native_symbols = get_spectest_export_apis(&native_symbols);
501
+ if (!wasm_native_register_natives("spectest", native_symbols,
502
+ n_native_symbols))
503
+ goto fail;
504
+ #endif /* WASM_ENABLE_SPEC_TEST */
505
+
506
+ #if WASM_ENABLE_LIBC_WASI != 0
507
+ g_wasi_context_key = wasm_native_create_context_key(wasi_context_dtor);
508
+ if (g_wasi_context_key == NULL) {
509
+ goto fail;
510
+ }
511
+ n_native_symbols = get_libc_wasi_export_apis(&native_symbols);
512
+ if (!wasm_native_register_natives("wasi_unstable", native_symbols,
513
+ n_native_symbols))
514
+ goto fail;
515
+ if (!wasm_native_register_natives("wasi_snapshot_preview1", native_symbols,
516
+ n_native_symbols))
517
+ goto fail;
518
+ #endif
519
+
520
+ #if WASM_ENABLE_SHARED_HEAP != 0
521
+ n_native_symbols = get_lib_shared_heap_export_apis(&native_symbols);
522
+ if (n_native_symbols > 0
523
+ && !wasm_native_register_natives("env", native_symbols,
524
+ n_native_symbols))
525
+ goto fail;
526
+ #endif
527
+
528
+ #if WASM_ENABLE_BASE_LIB != 0
529
+ n_native_symbols = get_base_lib_export_apis(&native_symbols);
530
+ if (n_native_symbols > 0
531
+ && !wasm_native_register_natives("env", native_symbols,
532
+ n_native_symbols))
533
+ goto fail;
534
+ #endif
535
+
536
+ #if WASM_ENABLE_APP_FRAMEWORK != 0
537
+ n_native_symbols = get_ext_lib_export_apis(&native_symbols);
538
+ if (n_native_symbols > 0
539
+ && !wasm_native_register_natives("env", native_symbols,
540
+ n_native_symbols))
541
+ goto fail;
542
+ #endif
543
+
544
+ #if WASM_ENABLE_LIB_PTHREAD != 0
545
+ if (!lib_pthread_init())
546
+ goto fail;
547
+
548
+ n_native_symbols = get_lib_pthread_export_apis(&native_symbols);
549
+ if (n_native_symbols > 0
550
+ && !wasm_native_register_natives("env", native_symbols,
551
+ n_native_symbols))
552
+ goto fail;
553
+ #endif
554
+
555
+ #if WASM_ENABLE_LIB_WASI_THREADS != 0
556
+ if (!lib_wasi_threads_init())
557
+ goto fail;
558
+
559
+ n_native_symbols = get_lib_wasi_threads_export_apis(&native_symbols);
560
+ if (n_native_symbols > 0
561
+ && !wasm_native_register_natives("wasi", native_symbols,
562
+ n_native_symbols))
563
+ goto fail;
564
+ #endif
565
+
566
+ #if WASM_ENABLE_LIBC_EMCC != 0
567
+ n_native_symbols = get_libc_emcc_export_apis(&native_symbols);
568
+ if (n_native_symbols > 0
569
+ && !wasm_native_register_natives("env", native_symbols,
570
+ n_native_symbols))
571
+ goto fail;
572
+ #endif /* WASM_ENABLE_LIBC_EMCC */
573
+
574
+ #if WASM_ENABLE_LIB_RATS != 0
575
+ n_native_symbols = get_lib_rats_export_apis(&native_symbols);
576
+ if (n_native_symbols > 0
577
+ && !wasm_native_register_natives("env", native_symbols,
578
+ n_native_symbols))
579
+ goto fail;
580
+ #endif /* WASM_ENABLE_LIB_RATS */
581
+
582
+ #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
583
+ if (!wasi_nn_initialize())
584
+ goto fail;
585
+
586
+ n_native_symbols = get_wasi_nn_export_apis(&native_symbols);
587
+ if (n_native_symbols > 0
588
+ && !wasm_native_register_natives(
589
+ #if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
590
+ "wasi_ephemeral_nn",
591
+ #else
592
+ "wasi_nn",
593
+ #endif /* WASM_ENABLE_WASI_EPHEMERAL_NN != 0 */
594
+ native_symbols, n_native_symbols))
595
+ goto fail;
596
+ #endif /* WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 */
597
+
598
+ #if WASM_ENABLE_QUICK_AOT_ENTRY != 0
599
+ if (!quick_aot_entry_init()) {
600
+ #if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
601
+ || WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
602
+ || WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
603
+ || WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
604
+ || WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0 \
605
+ || WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
606
+ goto fail;
607
+ #else
608
+ return false;
609
+ #endif
610
+ }
611
+ #endif
612
+
613
+ return true;
614
+ #if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
615
+ || WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
616
+ || WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
617
+ || WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
618
+ || WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0 \
619
+ || WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
620
+ fail:
621
+ wasm_native_destroy();
622
+ return false;
623
+ #endif
624
+ }
625
+
626
+ void
627
+ wasm_native_destroy()
628
+ {
629
+ NativeSymbolsNode *node, *node_next;
630
+
631
+ #if WASM_ENABLE_LIBC_WASI != 0
632
+ if (g_wasi_context_key != NULL) {
633
+ wasm_native_destroy_context_key(g_wasi_context_key);
634
+ g_wasi_context_key = NULL;
635
+ }
636
+ #endif
637
+
638
+ #if WASM_ENABLE_LIB_PTHREAD != 0
639
+ lib_pthread_destroy();
640
+ #endif
641
+
642
+ #if WASM_ENABLE_LIB_WASI_THREADS != 0
643
+ lib_wasi_threads_destroy();
644
+ #endif
645
+
646
+ #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
647
+ wasi_nn_destroy();
648
+ #endif
649
+
650
+ node = g_native_symbols_list;
651
+ while (node) {
652
+ node_next = node->next;
653
+ wasm_runtime_free(node);
654
+ node = node_next;
655
+ }
656
+
657
+ g_native_symbols_list = NULL;
658
+ }
659
+
660
+ #if WASM_ENABLE_QUICK_AOT_ENTRY != 0
661
+ static void
662
+ invoke_no_args_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
663
+ {
664
+ void (*native_code)(WASMExecEnv *) = func_ptr;
665
+ native_code(exec_env);
666
+ }
667
+ static void
668
+ invoke_no_args_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
669
+ {
670
+ int32 (*native_code)(WASMExecEnv *) = func_ptr;
671
+ argv_ret[0] = native_code(exec_env);
672
+ }
673
+ static void
674
+ invoke_no_args_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
675
+ {
676
+ int64 (*native_code)(WASMExecEnv *) = func_ptr;
677
+ int64 ret = native_code(exec_env);
678
+ PUT_I64_TO_ADDR(argv_ret, ret);
679
+ }
680
+
681
+ static void
682
+ invoke_i_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
683
+ {
684
+ void (*native_code)(WASMExecEnv *, int32) = func_ptr;
685
+ native_code(exec_env, argv[0]);
686
+ }
687
+ static void
688
+ invoke_i_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
689
+ {
690
+ int32 (*native_code)(WASMExecEnv *, int32) = func_ptr;
691
+ argv_ret[0] = native_code(exec_env, argv[0]);
692
+ }
693
+ static void
694
+ invoke_i_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
695
+ {
696
+ int64 (*native_code)(WASMExecEnv *, int32) = func_ptr;
697
+ int64 ret = native_code(exec_env, argv[0]);
698
+ PUT_I64_TO_ADDR(argv_ret, ret);
699
+ }
700
+
701
+ static void
702
+ invoke_I_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
703
+ {
704
+ void (*native_code)(WASMExecEnv *, int64) = func_ptr;
705
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv));
706
+ }
707
+ static void
708
+ invoke_I_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
709
+ {
710
+ int32 (*native_code)(WASMExecEnv *, int64) = func_ptr;
711
+ argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv));
712
+ }
713
+ static void
714
+ invoke_I_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
715
+ {
716
+ int64 (*native_code)(WASMExecEnv *, int64) = func_ptr;
717
+ int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv));
718
+ PUT_I64_TO_ADDR(argv_ret, ret);
719
+ }
720
+
721
+ static void
722
+ invoke_ii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
723
+ {
724
+ void (*native_code)(WASMExecEnv *, int32, int32) = func_ptr;
725
+ native_code(exec_env, argv[0], argv[1]);
726
+ }
727
+ static void
728
+ invoke_ii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
729
+ {
730
+ int32 (*native_code)(WASMExecEnv *, int32, int32) = func_ptr;
731
+ argv_ret[0] = native_code(exec_env, argv[0], argv[1]);
732
+ }
733
+ static void
734
+ invoke_ii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
735
+ {
736
+ int64 (*native_code)(WASMExecEnv *, int32, int32) = func_ptr;
737
+ int64 ret = native_code(exec_env, argv[0], argv[1]);
738
+ PUT_I64_TO_ADDR(argv_ret, ret);
739
+ }
740
+
741
+ static void
742
+ invoke_iI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
743
+ {
744
+ void (*native_code)(WASMExecEnv *, int32, int64) = func_ptr;
745
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1));
746
+ }
747
+ static void
748
+ invoke_iI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
749
+ {
750
+ int32 (*native_code)(WASMExecEnv *, int32, int64) = func_ptr;
751
+ argv_ret[0] =
752
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1));
753
+ }
754
+ static void
755
+ invoke_iI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
756
+ {
757
+ int64 (*native_code)(WASMExecEnv *, int32, int64) = func_ptr;
758
+ int64 ret =
759
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1));
760
+ PUT_I64_TO_ADDR(argv_ret, ret);
761
+ }
762
+
763
+ static void
764
+ invoke_Ii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
765
+ {
766
+ void (*native_code)(WASMExecEnv *, int64, int32) = func_ptr;
767
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2]);
768
+ }
769
+ static void
770
+ invoke_Ii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
771
+ {
772
+ int32 (*native_code)(WASMExecEnv *, int64, int32) = func_ptr;
773
+ argv_ret[0] =
774
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2]);
775
+ }
776
+ static void
777
+ invoke_Ii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
778
+ {
779
+ int64 (*native_code)(WASMExecEnv *, int64, int32) = func_ptr;
780
+ int64 ret =
781
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2]);
782
+ PUT_I64_TO_ADDR(argv_ret, ret);
783
+ }
784
+
785
+ static void
786
+ invoke_II_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
787
+ {
788
+ void (*native_code)(WASMExecEnv *, int64, int64) = func_ptr;
789
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
790
+ GET_I64_FROM_ADDR((uint32 *)argv + 2));
791
+ }
792
+ static void
793
+ invoke_II_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
794
+ {
795
+ int32 (*native_code)(WASMExecEnv *, int64, int64) = func_ptr;
796
+ argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
797
+ GET_I64_FROM_ADDR((uint32 *)argv + 2));
798
+ }
799
+ static void
800
+ invoke_II_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
801
+ {
802
+ int64 (*native_code)(WASMExecEnv *, int64, int64) = func_ptr;
803
+ int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
804
+ GET_I64_FROM_ADDR((uint32 *)argv + 2));
805
+ PUT_I64_TO_ADDR(argv_ret, ret);
806
+ }
807
+
808
+ static void
809
+ invoke_iii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
810
+ {
811
+ void (*native_code)(WASMExecEnv *, int32, int32, int32) = func_ptr;
812
+ native_code(exec_env, argv[0], argv[1], argv[2]);
813
+ }
814
+ static void
815
+ invoke_iii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
816
+ {
817
+ int32 (*native_code)(WASMExecEnv *, int32, int32, int32) = func_ptr;
818
+ argv_ret[0] = native_code(exec_env, argv[0], argv[1], argv[2]);
819
+ }
820
+ static void
821
+ invoke_iii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
822
+ {
823
+ int64 (*native_code)(WASMExecEnv *, int32, int32, int32) = func_ptr;
824
+ int64 ret = native_code(exec_env, argv[0], argv[1], argv[2]);
825
+ PUT_I64_TO_ADDR(argv_ret, ret);
826
+ }
827
+
828
+ static void
829
+ invoke_iiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
830
+ {
831
+ void (*native_code)(WASMExecEnv *, int32, int32, int64) = func_ptr;
832
+ native_code(exec_env, argv[0], argv[1],
833
+ GET_I64_FROM_ADDR((uint32 *)argv + 2));
834
+ }
835
+ static void
836
+ invoke_iiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
837
+ {
838
+ int32 (*native_code)(WASMExecEnv *, int32, int32, int64) = func_ptr;
839
+ argv_ret[0] = native_code(exec_env, argv[0], argv[1],
840
+ GET_I64_FROM_ADDR((uint32 *)argv + 2));
841
+ }
842
+ static void
843
+ invoke_iiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
844
+ {
845
+ int64 (*native_code)(WASMExecEnv *, int32, int32, int64) = func_ptr;
846
+ int64 ret = native_code(exec_env, argv[0], argv[1],
847
+ GET_I64_FROM_ADDR((uint32 *)argv + 2));
848
+ PUT_I64_TO_ADDR(argv_ret, ret);
849
+ }
850
+
851
+ static void
852
+ invoke_iIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
853
+ {
854
+ void (*native_code)(WASMExecEnv *, int32, int64, int32) = func_ptr;
855
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
856
+ argv[3]);
857
+ }
858
+ static void
859
+ invoke_iIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
860
+ {
861
+ int32 (*native_code)(WASMExecEnv *, int32, int64, int32) = func_ptr;
862
+ argv_ret[0] = native_code(exec_env, argv[0],
863
+ GET_I64_FROM_ADDR((uint32 *)argv + 1), argv[3]);
864
+ }
865
+ static void
866
+ invoke_iIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
867
+ {
868
+ int64 (*native_code)(WASMExecEnv *, int32, int64, int32) = func_ptr;
869
+ int64 ret = native_code(exec_env, argv[0],
870
+ GET_I64_FROM_ADDR((uint32 *)argv + 1), argv[3]);
871
+ PUT_I64_TO_ADDR(argv_ret, ret);
872
+ }
873
+
874
+ static void
875
+ invoke_iII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
876
+ {
877
+ void (*native_code)(WASMExecEnv *, int32, int64, int64) = func_ptr;
878
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
879
+ GET_I64_FROM_ADDR((uint32 *)argv + 3));
880
+ }
881
+ static void
882
+ invoke_iII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
883
+ {
884
+ int32 (*native_code)(WASMExecEnv *, int32, int64, int64) = func_ptr;
885
+ argv_ret[0] =
886
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
887
+ GET_I64_FROM_ADDR((uint32 *)argv + 3));
888
+ }
889
+ static void
890
+ invoke_iII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
891
+ {
892
+ int64 (*native_code)(WASMExecEnv *, int32, int64, int64) = func_ptr;
893
+ int64 ret =
894
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
895
+ GET_I64_FROM_ADDR((uint32 *)argv + 3));
896
+ PUT_I64_TO_ADDR(argv_ret, ret);
897
+ }
898
+
899
+ static void
900
+ invoke_Iii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
901
+ {
902
+ void (*native_code)(WASMExecEnv *, int64, int32, int32) = func_ptr;
903
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2], argv[3]);
904
+ }
905
+ static void
906
+ invoke_Iii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
907
+ {
908
+ int32 (*native_code)(WASMExecEnv *, int64, int32, int32) = func_ptr;
909
+ argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
910
+ argv[2], argv[3]);
911
+ }
912
+ static void
913
+ invoke_Iii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
914
+ {
915
+ int64 (*native_code)(WASMExecEnv *, int64, int32, int32) = func_ptr;
916
+ int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
917
+ argv[2], argv[3]);
918
+ PUT_I64_TO_ADDR(argv_ret, ret);
919
+ }
920
+
921
+ static void
922
+ invoke_IiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
923
+ {
924
+ void (*native_code)(WASMExecEnv *, int64, int32, int64) = func_ptr;
925
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
926
+ GET_I64_FROM_ADDR((uint32 *)argv + 3));
927
+ }
928
+ static void
929
+ invoke_IiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
930
+ {
931
+ int32 (*native_code)(WASMExecEnv *, int64, int32, int64) = func_ptr;
932
+ argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
933
+ argv[2], GET_I64_FROM_ADDR((uint32 *)argv + 3));
934
+ }
935
+ static void
936
+ invoke_IiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
937
+ {
938
+ int64 (*native_code)(WASMExecEnv *, int64, int32, int64) = func_ptr;
939
+ int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
940
+ argv[2], GET_I64_FROM_ADDR((uint32 *)argv + 3));
941
+ PUT_I64_TO_ADDR(argv_ret, ret);
942
+ }
943
+
944
+ static void
945
+ invoke_IIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
946
+ {
947
+ void (*native_code)(WASMExecEnv *, int64, int64, int32) = func_ptr;
948
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
949
+ GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
950
+ }
951
+ static void
952
+ invoke_IIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
953
+ {
954
+ int32 (*native_code)(WASMExecEnv *, int64, int64, int32) = func_ptr;
955
+ argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
956
+ GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
957
+ }
958
+ static void
959
+ invoke_IIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
960
+ {
961
+ int64 (*native_code)(WASMExecEnv *, int64, int64, int32) = func_ptr;
962
+ int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
963
+ GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
964
+ PUT_I64_TO_ADDR(argv_ret, ret);
965
+ }
966
+
967
+ static void
968
+ invoke_III_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
969
+ {
970
+ void (*native_code)(WASMExecEnv *, int64, int64, int64) = func_ptr;
971
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
972
+ GET_I64_FROM_ADDR((uint32 *)argv + 2),
973
+ GET_I64_FROM_ADDR((uint32 *)argv + 4));
974
+ }
975
+ static void
976
+ invoke_III_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
977
+ {
978
+ int32 (*native_code)(WASMExecEnv *, int64, int64, int64) = func_ptr;
979
+ argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
980
+ GET_I64_FROM_ADDR((uint32 *)argv + 2),
981
+ GET_I64_FROM_ADDR((uint32 *)argv + 4));
982
+ }
983
+ static void
984
+ invoke_III_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
985
+ {
986
+ int64 (*native_code)(WASMExecEnv *, int64, int64, int64) = func_ptr;
987
+ int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
988
+ GET_I64_FROM_ADDR((uint32 *)argv + 2),
989
+ GET_I64_FROM_ADDR((uint32 *)argv + 4));
990
+ PUT_I64_TO_ADDR(argv_ret, ret);
991
+ }
992
+
993
+ static void
994
+ invoke_iiii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
995
+ {
996
+ void (*native_code)(WASMExecEnv *, int32, int32, int32, int32) = func_ptr;
997
+ native_code(exec_env, argv[0], argv[1], argv[2], argv[3]);
998
+ }
999
+ static void
1000
+ invoke_iiii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1001
+ {
1002
+ int32 (*native_code)(WASMExecEnv *, int32, int32, int32, int32) = func_ptr;
1003
+ argv_ret[0] = native_code(exec_env, argv[0], argv[1], argv[2], argv[3]);
1004
+ }
1005
+ static void
1006
+ invoke_iiii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1007
+ {
1008
+ int64 (*native_code)(WASMExecEnv *, int32, int32, int32, int32) = func_ptr;
1009
+ int64 ret = native_code(exec_env, argv[0], argv[1], argv[2], argv[3]);
1010
+ PUT_I64_TO_ADDR(argv_ret, ret);
1011
+ }
1012
+
1013
+ static void
1014
+ invoke_iiiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1015
+ {
1016
+ void (*native_code)(WASMExecEnv *, int32, int32, int32, int64) = func_ptr;
1017
+ native_code(exec_env, argv[0], argv[1], argv[2],
1018
+ GET_I64_FROM_ADDR((uint32 *)argv + 3));
1019
+ }
1020
+ static void
1021
+ invoke_iiiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1022
+ {
1023
+ int32 (*native_code)(WASMExecEnv *, int32, int32, int32, int64) = func_ptr;
1024
+ argv_ret[0] = native_code(exec_env, argv[0], argv[1], argv[2],
1025
+ GET_I64_FROM_ADDR((uint32 *)argv + 3));
1026
+ }
1027
+ static void
1028
+ invoke_iiiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1029
+ {
1030
+ int64 (*native_code)(WASMExecEnv *, int32, int32, int32, int64) = func_ptr;
1031
+ int64 ret = native_code(exec_env, argv[0], argv[1], argv[2],
1032
+ GET_I64_FROM_ADDR((uint32 *)argv + 3));
1033
+ PUT_I64_TO_ADDR(argv_ret, ret);
1034
+ }
1035
+
1036
+ static void
1037
+ invoke_iiIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1038
+ {
1039
+ void (*native_code)(WASMExecEnv *, int32, int32, int64, int32) = func_ptr;
1040
+ native_code(exec_env, argv[0], argv[1],
1041
+ GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
1042
+ }
1043
+ static void
1044
+ invoke_iiIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1045
+ {
1046
+ int32 (*native_code)(WASMExecEnv *, int32, int32, int64, int32) = func_ptr;
1047
+ argv_ret[0] = native_code(exec_env, argv[0], argv[1],
1048
+ GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
1049
+ }
1050
+ static void
1051
+ invoke_iiIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1052
+ {
1053
+ int64 (*native_code)(WASMExecEnv *, int32, int32, int64, int32) = func_ptr;
1054
+ int64 ret = native_code(exec_env, argv[0], argv[1],
1055
+ GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
1056
+ PUT_I64_TO_ADDR(argv_ret, ret);
1057
+ }
1058
+
1059
+ static void
1060
+ invoke_iiII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1061
+ {
1062
+ void (*native_code)(WASMExecEnv *, int32, int32, int64, int64) = func_ptr;
1063
+ native_code(exec_env, argv[0], argv[1],
1064
+ GET_I64_FROM_ADDR((uint32 *)argv + 2),
1065
+ GET_I64_FROM_ADDR((uint32 *)argv + 4));
1066
+ }
1067
+ static void
1068
+ invoke_iiII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1069
+ {
1070
+ int32 (*native_code)(WASMExecEnv *, int32, int32, int64, int64) = func_ptr;
1071
+ argv_ret[0] = native_code(exec_env, argv[0], argv[1],
1072
+ GET_I64_FROM_ADDR((uint32 *)argv + 2),
1073
+ GET_I64_FROM_ADDR((uint32 *)argv + 4));
1074
+ }
1075
+ static void
1076
+ invoke_iiII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1077
+ {
1078
+ int64 (*native_code)(WASMExecEnv *, int32, int32, int64, int64) = func_ptr;
1079
+ int64 ret = native_code(exec_env, argv[0], argv[1],
1080
+ GET_I64_FROM_ADDR((uint32 *)argv + 2),
1081
+ GET_I64_FROM_ADDR((uint32 *)argv + 4));
1082
+ PUT_I64_TO_ADDR(argv_ret, ret);
1083
+ }
1084
+
1085
+ static void
1086
+ invoke_iIii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1087
+ {
1088
+ void (*native_code)(WASMExecEnv *, int32, int64, int32, int32) = func_ptr;
1089
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
1090
+ argv[3], argv[4]);
1091
+ }
1092
+ static void
1093
+ invoke_iIii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1094
+ {
1095
+ int32 (*native_code)(WASMExecEnv *, int32, int64, int32, int32) = func_ptr;
1096
+ argv_ret[0] =
1097
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
1098
+ argv[3], argv[4]);
1099
+ }
1100
+ static void
1101
+ invoke_iIii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1102
+ {
1103
+ int64 (*native_code)(WASMExecEnv *, int32, int64, int32, int32) = func_ptr;
1104
+ int64 ret =
1105
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
1106
+ argv[3], argv[4]);
1107
+ PUT_I64_TO_ADDR(argv_ret, ret);
1108
+ }
1109
+
1110
+ static void
1111
+ invoke_iIiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1112
+ {
1113
+ void (*native_code)(WASMExecEnv *, int32, int64, int32, int64) = func_ptr;
1114
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
1115
+ argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
1116
+ }
1117
+ static void
1118
+ invoke_iIiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1119
+ {
1120
+ int32 (*native_code)(WASMExecEnv *, int32, int64, int32, int64) = func_ptr;
1121
+ argv_ret[0] =
1122
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
1123
+ argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
1124
+ }
1125
+ static void
1126
+ invoke_iIiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1127
+ {
1128
+ int64 (*native_code)(WASMExecEnv *, int32, int64, int32, int64) = func_ptr;
1129
+ int64 ret =
1130
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
1131
+ argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
1132
+ PUT_I64_TO_ADDR(argv_ret, ret);
1133
+ }
1134
+
1135
+ static void
1136
+ invoke_iIIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1137
+ {
1138
+ void (*native_code)(WASMExecEnv *, int32, int64, int64, int32) = func_ptr;
1139
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
1140
+ GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
1141
+ }
1142
+ static void
1143
+ invoke_iIIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1144
+ {
1145
+ int32 (*native_code)(WASMExecEnv *, int32, int64, int64, int32) = func_ptr;
1146
+ argv_ret[0] =
1147
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
1148
+ GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
1149
+ }
1150
+ static void
1151
+ invoke_iIIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1152
+ {
1153
+ int64 (*native_code)(WASMExecEnv *, int32, int64, int64, int32) = func_ptr;
1154
+ int64 ret =
1155
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
1156
+ GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
1157
+ PUT_I64_TO_ADDR(argv_ret, ret);
1158
+ }
1159
+
1160
+ static void
1161
+ invoke_iIII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1162
+ {
1163
+ void (*native_code)(WASMExecEnv *, int32, int64, int64, int64) = func_ptr;
1164
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
1165
+ GET_I64_FROM_ADDR((uint32 *)argv + 3),
1166
+ GET_I64_FROM_ADDR((uint32 *)argv + 5));
1167
+ }
1168
+ static void
1169
+ invoke_iIII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1170
+ {
1171
+ int32 (*native_code)(WASMExecEnv *, int32, int64, int64, int64) = func_ptr;
1172
+ argv_ret[0] =
1173
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
1174
+ GET_I64_FROM_ADDR((uint32 *)argv + 3),
1175
+ GET_I64_FROM_ADDR((uint32 *)argv + 5));
1176
+ }
1177
+ static void
1178
+ invoke_iIII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1179
+ {
1180
+ int64 (*native_code)(WASMExecEnv *, int32, int64, int64, int64) = func_ptr;
1181
+ int64 ret =
1182
+ native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
1183
+ GET_I64_FROM_ADDR((uint32 *)argv + 3),
1184
+ GET_I64_FROM_ADDR((uint32 *)argv + 5));
1185
+ PUT_I64_TO_ADDR(argv_ret, ret);
1186
+ }
1187
+
1188
+ static void
1189
+ invoke_Iiii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1190
+ {
1191
+ void (*native_code)(WASMExecEnv *, int64, int32, int32, int32) = func_ptr;
1192
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2], argv[3],
1193
+ argv[4]);
1194
+ }
1195
+ static void
1196
+ invoke_Iiii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1197
+ {
1198
+ int32 (*native_code)(WASMExecEnv *, int64, int32, int32, int32) = func_ptr;
1199
+ argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1200
+ argv[2], argv[3], argv[4]);
1201
+ }
1202
+ static void
1203
+ invoke_Iiii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1204
+ {
1205
+ int64 (*native_code)(WASMExecEnv *, int64, int32, int32, int32) = func_ptr;
1206
+ int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1207
+ argv[2], argv[3], argv[4]);
1208
+ PUT_I64_TO_ADDR(argv_ret, ret);
1209
+ }
1210
+
1211
+ static void
1212
+ invoke_IiiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1213
+ {
1214
+ void (*native_code)(WASMExecEnv *, int64, int32, int32, int64) = func_ptr;
1215
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2], argv[3],
1216
+ GET_I64_FROM_ADDR((uint32 *)argv + 4));
1217
+ }
1218
+
1219
+ static void
1220
+ invoke_IiiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1221
+ {
1222
+ int32 (*native_code)(WASMExecEnv *, int64, int32, int32, int64) = func_ptr;
1223
+ argv_ret[0] =
1224
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
1225
+ argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
1226
+ }
1227
+
1228
+ static void
1229
+ invoke_IiiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1230
+ {
1231
+ int64 (*native_code)(WASMExecEnv *, int64, int32, int32, int64) = func_ptr;
1232
+ int64 ret =
1233
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
1234
+ argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
1235
+ PUT_I64_TO_ADDR(argv_ret, ret);
1236
+ }
1237
+
1238
+ static void
1239
+ invoke_IiIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1240
+ {
1241
+ void (*native_code)(WASMExecEnv *, int64, int32, int64, int32) = func_ptr;
1242
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
1243
+ GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
1244
+ }
1245
+ static void
1246
+ invoke_IiIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1247
+ {
1248
+ int32 (*native_code)(WASMExecEnv *, int64, int32, int64, int32) = func_ptr;
1249
+ argv_ret[0] =
1250
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
1251
+ GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
1252
+ }
1253
+ static void
1254
+ invoke_IiIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1255
+ {
1256
+ int64 (*native_code)(WASMExecEnv *, int64, int32, int64, int32) = func_ptr;
1257
+ int64 ret =
1258
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
1259
+ GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
1260
+ PUT_I64_TO_ADDR(argv_ret, ret);
1261
+ }
1262
+
1263
+ static void
1264
+ invoke_IiII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1265
+ {
1266
+ void (*native_code)(WASMExecEnv *, int64, int32, int64, int64) = func_ptr;
1267
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
1268
+ GET_I64_FROM_ADDR((uint32 *)argv + 3),
1269
+ GET_I64_FROM_ADDR((uint32 *)argv + 5));
1270
+ }
1271
+ static void
1272
+ invoke_IiII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1273
+ {
1274
+ int32 (*native_code)(WASMExecEnv *, int64, int32, int64, int64) = func_ptr;
1275
+ argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1276
+ argv[2], GET_I64_FROM_ADDR((uint32 *)argv + 3),
1277
+ GET_I64_FROM_ADDR((uint32 *)argv + 5));
1278
+ }
1279
+ static void
1280
+ invoke_IiII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1281
+ {
1282
+ int64 (*native_code)(WASMExecEnv *, int64, int32, int64, int64) = func_ptr;
1283
+ int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1284
+ argv[2], GET_I64_FROM_ADDR((uint32 *)argv + 3),
1285
+ GET_I64_FROM_ADDR((uint32 *)argv + 5));
1286
+ PUT_I64_TO_ADDR(argv_ret, ret);
1287
+ }
1288
+
1289
+ static void
1290
+ invoke_IIii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1291
+ {
1292
+ void (*native_code)(WASMExecEnv *, int64, int64, int32, int32) = func_ptr;
1293
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1294
+ GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4], argv[5]);
1295
+ }
1296
+ static void
1297
+ invoke_IIii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1298
+ {
1299
+ int32 (*native_code)(WASMExecEnv *, int64, int64, int32, int32) = func_ptr;
1300
+ argv_ret[0] =
1301
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1302
+ GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4], argv[5]);
1303
+ }
1304
+ static void
1305
+ invoke_IIii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1306
+ {
1307
+ int64 (*native_code)(WASMExecEnv *, int64, int64, int32, int32) = func_ptr;
1308
+ int64 ret =
1309
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1310
+ GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4], argv[5]);
1311
+ PUT_I64_TO_ADDR(argv_ret, ret);
1312
+ }
1313
+
1314
+ static void
1315
+ invoke_IIiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1316
+ {
1317
+ void (*native_code)(WASMExecEnv *, int64, int64, int32, int64) = func_ptr;
1318
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1319
+ GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4],
1320
+ GET_I64_FROM_ADDR((uint32 *)argv + 5));
1321
+ }
1322
+ static void
1323
+ invoke_IIiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1324
+ {
1325
+ int32 (*native_code)(WASMExecEnv *, int64, int64, int32, int64) = func_ptr;
1326
+ argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1327
+ GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4],
1328
+ GET_I64_FROM_ADDR((uint32 *)argv + 5));
1329
+ }
1330
+ static void
1331
+ invoke_IIiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1332
+ {
1333
+ int64 (*native_code)(WASMExecEnv *, int64, int64, int32, int64) = func_ptr;
1334
+ int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1335
+ GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4],
1336
+ GET_I64_FROM_ADDR((uint32 *)argv + 5));
1337
+ PUT_I64_TO_ADDR(argv_ret, ret);
1338
+ }
1339
+
1340
+ static void
1341
+ invoke_IIIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1342
+ {
1343
+ void (*native_code)(WASMExecEnv *, int64, int64, int64, int32) = func_ptr;
1344
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1345
+ GET_I64_FROM_ADDR((uint32 *)argv + 2),
1346
+ GET_I64_FROM_ADDR((uint32 *)argv + 4), argv[6]);
1347
+ }
1348
+ static void
1349
+ invoke_IIIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1350
+ {
1351
+ int32 (*native_code)(WASMExecEnv *, int64, int64, int64, int32) = func_ptr;
1352
+ argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1353
+ GET_I64_FROM_ADDR((uint32 *)argv + 2),
1354
+ GET_I64_FROM_ADDR((uint32 *)argv + 4), argv[6]);
1355
+ }
1356
+ static void
1357
+ invoke_IIIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1358
+ {
1359
+ int64 (*native_code)(WASMExecEnv *, int64, int64, int64, int32) = func_ptr;
1360
+ int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1361
+ GET_I64_FROM_ADDR((uint32 *)argv + 2),
1362
+ GET_I64_FROM_ADDR((uint32 *)argv + 4), argv[6]);
1363
+ PUT_I64_TO_ADDR(argv_ret, ret);
1364
+ }
1365
+
1366
+ static void
1367
+ invoke_IIII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1368
+ {
1369
+ void (*native_code)(WASMExecEnv *, int64, int64, int64, int64) = func_ptr;
1370
+ native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1371
+ GET_I64_FROM_ADDR((uint32 *)argv + 2),
1372
+ GET_I64_FROM_ADDR((uint32 *)argv + 4),
1373
+ GET_I64_FROM_ADDR((uint32 *)argv + 6));
1374
+ }
1375
+ static void
1376
+ invoke_IIII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1377
+ {
1378
+ int32 (*native_code)(WASMExecEnv *, int64, int64, int64, int64) = func_ptr;
1379
+ argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1380
+ GET_I64_FROM_ADDR((uint32 *)argv + 2),
1381
+ GET_I64_FROM_ADDR((uint32 *)argv + 4),
1382
+ GET_I64_FROM_ADDR((uint32 *)argv + 6));
1383
+ }
1384
+ static void
1385
+ invoke_IIII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1386
+ {
1387
+ int64 (*native_code)(WASMExecEnv *, int64, int64, int64, int64) = func_ptr;
1388
+ int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
1389
+ GET_I64_FROM_ADDR((uint32 *)argv + 2),
1390
+ GET_I64_FROM_ADDR((uint32 *)argv + 4),
1391
+ GET_I64_FROM_ADDR((uint32 *)argv + 6));
1392
+ PUT_I64_TO_ADDR(argv_ret, ret);
1393
+ }
1394
+
1395
+ static void
1396
+ invoke_iiiii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1397
+ {
1398
+ void (*native_code)(WASMExecEnv *, int32, int32, int32, int32, int32) =
1399
+ func_ptr;
1400
+ native_code(exec_env, argv[0], argv[1], argv[2], argv[3], argv[4]);
1401
+ }
1402
+ static void
1403
+ invoke_iiiii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1404
+ {
1405
+ int32 (*native_code)(WASMExecEnv *, int32, int32, int32, int32, int32) =
1406
+ func_ptr;
1407
+ argv_ret[0] =
1408
+ native_code(exec_env, argv[0], argv[1], argv[2], argv[3], argv[4]);
1409
+ }
1410
+ static void
1411
+ invoke_iiiii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
1412
+ {
1413
+ int64 (*native_code)(WASMExecEnv *, int32, int32, int32, int32, int32) =
1414
+ func_ptr;
1415
+ int64 ret =
1416
+ native_code(exec_env, argv[0], argv[1], argv[2], argv[3], argv[4]);
1417
+ PUT_I64_TO_ADDR(argv_ret, ret);
1418
+ }
1419
+
1420
+ typedef struct QuickAOTEntry {
1421
+ const char *signature;
1422
+ void *func_ptr;
1423
+ } QuickAOTEntry;
1424
+
1425
+ /* clang-format off */
1426
+ static QuickAOTEntry quick_aot_entries[] = {
1427
+ { "()v", invoke_no_args_v },
1428
+ { "()i", invoke_no_args_i },
1429
+ { "()I", invoke_no_args_I },
1430
+
1431
+ { "(i)v", invoke_i_v }, { "(i)i", invoke_i_i }, { "(i)I", invoke_i_I },
1432
+ { "(I)v", invoke_I_v }, { "(I)i", invoke_I_i }, { "(I)I", invoke_I_I },
1433
+
1434
+ { "(ii)v", invoke_ii_v }, { "(ii)i", invoke_ii_i }, { "(ii)I", invoke_ii_I },
1435
+ { "(iI)v", invoke_iI_v }, { "(iI)i", invoke_iI_i }, { "(iI)I", invoke_iI_I },
1436
+ { "(Ii)v", invoke_Ii_v }, { "(Ii)i", invoke_Ii_i }, { "(Ii)I", invoke_Ii_I },
1437
+ { "(II)v", invoke_II_v }, { "(II)i", invoke_II_i }, { "(II)I", invoke_II_I },
1438
+
1439
+ { "(iii)v", invoke_iii_v }, { "(iii)i", invoke_iii_i }, { "(iii)I", invoke_iii_I },
1440
+ { "(iiI)v", invoke_iiI_v }, { "(iiI)i", invoke_iiI_i }, { "(iiI)I", invoke_iiI_I },
1441
+ { "(iIi)v", invoke_iIi_v }, { "(iIi)i", invoke_iIi_i }, { "(iIi)I", invoke_iIi_I },
1442
+ { "(iII)v", invoke_iII_v }, { "(iII)i", invoke_iII_i }, { "(iII)I", invoke_iII_I },
1443
+ { "(Iii)v", invoke_Iii_v }, { "(Iii)i", invoke_Iii_i }, { "(Iii)I", invoke_Iii_I },
1444
+ { "(IiI)v", invoke_IiI_v }, { "(IiI)i", invoke_IiI_i }, { "(IiI)I", invoke_IiI_I },
1445
+ { "(IIi)v", invoke_IIi_v }, { "(IIi)i", invoke_IIi_i }, { "(IIi)I", invoke_IIi_I },
1446
+ { "(III)v", invoke_III_v }, { "(III)i", invoke_III_i }, { "(III)I", invoke_III_I },
1447
+
1448
+ { "(iiii)v", invoke_iiii_v }, { "(iiii)i", invoke_iiii_i }, { "(iiii)I", invoke_iiii_I },
1449
+ { "(iiiI)v", invoke_iiiI_v }, { "(iiiI)i", invoke_iiiI_i }, { "(iiiI)I", invoke_iiiI_I },
1450
+ { "(iiIi)v", invoke_iiIi_v }, { "(iiIi)i", invoke_iiIi_i }, { "(iiIi)I", invoke_iiIi_I },
1451
+ { "(iiII)v", invoke_iiII_v }, { "(iiII)i", invoke_iiII_i }, { "(iiII)I", invoke_iiII_I },
1452
+ { "(iIii)v", invoke_iIii_v }, { "(iIii)i", invoke_iIii_i }, { "(iIii)I", invoke_iIii_I },
1453
+ { "(iIiI)v", invoke_iIiI_v }, { "(iIiI)i", invoke_iIiI_i }, { "(iIiI)I", invoke_iIiI_I },
1454
+ { "(iIIi)v", invoke_iIIi_v }, { "(iIIi)i", invoke_iIIi_i }, { "(iIIi)I", invoke_iIIi_I },
1455
+ { "(iIII)v", invoke_iIII_v }, { "(iIII)i", invoke_iIII_i }, { "(iIII)I", invoke_iIII_I },
1456
+ { "(Iiii)v", invoke_Iiii_v }, { "(Iiii)i", invoke_Iiii_i }, { "(Iiii)I", invoke_Iiii_I },
1457
+ { "(IiiI)v", invoke_IiiI_v }, { "(IiiI)i", invoke_IiiI_i }, { "(IiiI)I", invoke_IiiI_I },
1458
+ { "(IiIi)v", invoke_IiIi_v }, { "(IiIi)i", invoke_IiIi_i }, { "(IiIi)I", invoke_IiIi_I },
1459
+ { "(IiII)v", invoke_IiII_v }, { "(IiII)i", invoke_IiII_i }, { "(IiII)I", invoke_IiII_I },
1460
+ { "(IIii)v", invoke_IIii_v }, { "(IIii)i", invoke_IIii_i }, { "(IIii)I", invoke_IIii_I },
1461
+ { "(IIiI)v", invoke_IIiI_v }, { "(IIiI)i", invoke_IIiI_i }, { "(IIiI)I", invoke_IIiI_I },
1462
+ { "(IIIi)v", invoke_IIIi_v }, { "(IIIi)i", invoke_IIIi_i }, { "(IIIi)I", invoke_IIIi_I },
1463
+ { "(IIII)v", invoke_IIII_v }, { "(IIII)i", invoke_IIII_i }, { "(IIII)I", invoke_IIII_I },
1464
+
1465
+ { "(iiiii)v", invoke_iiiii_v }, { "(iiiii)i", invoke_iiiii_i }, { "(iiiii)I", invoke_iiiii_I },
1466
+ };
1467
+ /* clang-format on */
1468
+
1469
+ static int
1470
+ quick_aot_entry_cmp(const void *quick_aot_entry1, const void *quick_aot_entry2)
1471
+ {
1472
+ return strcmp(((const QuickAOTEntry *)quick_aot_entry1)->signature,
1473
+ ((const QuickAOTEntry *)quick_aot_entry2)->signature);
1474
+ }
1475
+
1476
+ static bool
1477
+ quick_aot_entry_init(void)
1478
+ {
1479
+ qsort(quick_aot_entries, sizeof(quick_aot_entries) / sizeof(QuickAOTEntry),
1480
+ sizeof(QuickAOTEntry), quick_aot_entry_cmp);
1481
+
1482
+ return true;
1483
+ }
1484
+
1485
+ void *
1486
+ wasm_native_lookup_quick_aot_entry(const WASMFuncType *func_type)
1487
+ {
1488
+ char signature[16] = { 0 };
1489
+ uint32 param_count = func_type->param_count;
1490
+ uint32 result_count = func_type->result_count, i, j = 0;
1491
+ const uint8 *types = func_type->types;
1492
+ QuickAOTEntry *quick_aot_entry, key = { 0 };
1493
+
1494
+ if (param_count > 5 || result_count > 1)
1495
+ return NULL;
1496
+
1497
+ signature[j++] = '(';
1498
+
1499
+ for (i = 0; i < param_count; i++) {
1500
+ if (types[i] == VALUE_TYPE_I32)
1501
+ signature[j++] = 'i';
1502
+ else if (types[i] == VALUE_TYPE_I64)
1503
+ signature[j++] = 'I';
1504
+ else
1505
+ return NULL;
1506
+ }
1507
+
1508
+ signature[j++] = ')';
1509
+
1510
+ if (result_count == 0) {
1511
+ signature[j++] = 'v';
1512
+ }
1513
+ else {
1514
+ if (types[i] == VALUE_TYPE_I32)
1515
+ signature[j++] = 'i';
1516
+ else if (types[i] == VALUE_TYPE_I64)
1517
+ signature[j++] = 'I';
1518
+ else
1519
+ return NULL;
1520
+ }
1521
+
1522
+ key.signature = signature;
1523
+ if ((quick_aot_entry =
1524
+ bsearch(&key, quick_aot_entries,
1525
+ sizeof(quick_aot_entries) / sizeof(QuickAOTEntry),
1526
+ sizeof(QuickAOTEntry), quick_aot_entry_cmp))) {
1527
+ return quick_aot_entry->func_ptr;
1528
+ }
1529
+
1530
+ return NULL;
1531
+ }
1532
+ #endif /* end of WASM_ENABLE_QUICK_AOT_ENTRY != 0 */