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,910 @@
1
+ // WebAssembly C API
2
+
3
+ /**
4
+ * @file wasm_c_api.h
5
+ *
6
+ * @brief This file defines the WebAssembly C APIs
7
+ */
8
+
9
+ #ifndef _WASM_C_API_H_
10
+ #define _WASM_C_API_H_
11
+
12
+ #include <stddef.h>
13
+ #include <stdint.h>
14
+ #include <stdbool.h>
15
+ #include <string.h>
16
+ #include <assert.h>
17
+
18
+ #ifndef WASM_API_EXTERN
19
+ #if defined(_MSC_BUILD)
20
+ #if defined(COMPILING_WASM_RUNTIME_API)
21
+ #define WASM_API_EXTERN __declspec(dllexport)
22
+ #else
23
+ #define WASM_API_EXTERN __declspec(dllimport)
24
+ #endif
25
+ #else
26
+ #define WASM_API_EXTERN
27
+ #endif
28
+ #endif
29
+
30
+ #if defined(__GNUC__) || defined(__clang__)
31
+ #define WASM_API_DEPRECATED __attribute__((deprecated))
32
+ #elif defined(_MSC_VER)
33
+ #define WASM_API_DEPRECATED __declspec(deprecated)
34
+ #else
35
+ #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
36
+ #define WASM_API_DEPRECATED
37
+ #endif
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* clang-format off */
44
+
45
+ ///////////////////////////////////////////////////////////////////////////////
46
+ // Auxiliaries
47
+
48
+ // Machine types
49
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__) > 199901L
50
+ inline void assertions(void) {
51
+ static_assert(sizeof(float) == sizeof(uint32_t), "incompatible float type");
52
+ static_assert(sizeof(double) == sizeof(uint64_t), "incompatible double type");
53
+ static_assert(sizeof(intptr_t) == sizeof(uint32_t) ||
54
+ sizeof(intptr_t) == sizeof(uint64_t),
55
+ "incompatible pointer type");
56
+ }
57
+ #endif
58
+
59
+ typedef char byte_t;
60
+ typedef float float32_t;
61
+ typedef double float64_t;
62
+
63
+
64
+ // Ownership
65
+
66
+ #define own
67
+
68
+ // The qualifier `own` is used to indicate ownership of data in this API.
69
+ // It is intended to be interpreted similar to a `const` qualifier:
70
+ //
71
+ // - `own wasm_xxx_t*` owns the pointed-to data
72
+ // - `own wasm_xxx_t` distributes to all fields of a struct or union `xxx`
73
+ // - `own wasm_xxx_vec_t` owns the vector as well as its elements(!)
74
+ // - an `own` function parameter passes ownership from caller to callee
75
+ // - an `own` function result passes ownership from callee to caller
76
+ // - an exception are `own` pointer parameters named `out`, which are copy-back
77
+ // output parameters passing back ownership from callee to caller
78
+ //
79
+ // Own data is created by `wasm_xxx_new` functions and some others.
80
+ // It must be released with the corresponding `wasm_xxx_delete` function.
81
+ //
82
+ // Deleting a reference does not necessarily delete the underlying object,
83
+ // it merely indicates that this owner no longer uses it.
84
+ //
85
+ // For vectors, `const wasm_xxx_vec_t` is used informally to indicate that
86
+ // neither the vector nor its elements should be modified.
87
+ // TODO: introduce proper `wasm_xxx_const_vec_t`?
88
+
89
+
90
+ #define WASM_DECLARE_OWN(name) \
91
+ typedef struct wasm_##name##_t wasm_##name##_t; \
92
+ \
93
+ WASM_API_EXTERN void wasm_##name##_delete(own wasm_##name##_t*);
94
+
95
+
96
+ // Vectors
97
+ // size: capacity
98
+ // num_elems: current number of elements
99
+ // size_of_elem: size of one element
100
+ #define WASM_DECLARE_VEC(name, ptr_or_none) \
101
+ typedef struct wasm_##name##_vec_t { \
102
+ size_t size; \
103
+ wasm_##name##_t ptr_or_none* data; \
104
+ size_t num_elems; \
105
+ size_t size_of_elem; \
106
+ void *lock; \
107
+ } wasm_##name##_vec_t; \
108
+ \
109
+ WASM_API_EXTERN void wasm_##name##_vec_new_empty(own wasm_##name##_vec_t* out); \
110
+ WASM_API_EXTERN void wasm_##name##_vec_new_uninitialized( \
111
+ own wasm_##name##_vec_t* out, size_t); \
112
+ WASM_API_EXTERN void wasm_##name##_vec_new( \
113
+ own wasm_##name##_vec_t* out, \
114
+ size_t, own wasm_##name##_t ptr_or_none const[]); \
115
+ WASM_API_EXTERN void wasm_##name##_vec_copy( \
116
+ own wasm_##name##_vec_t* out, const wasm_##name##_vec_t*); \
117
+ WASM_API_EXTERN void wasm_##name##_vec_delete(own wasm_##name##_vec_t*);
118
+
119
+
120
+ // Byte vectors
121
+
122
+ typedef byte_t wasm_byte_t;
123
+ WASM_DECLARE_VEC(byte, )
124
+
125
+ typedef wasm_byte_vec_t wasm_name_t;
126
+
127
+ #define wasm_name wasm_byte_vec
128
+ #define wasm_name_new wasm_byte_vec_new
129
+ #define wasm_name_new_empty wasm_byte_vec_new_empty
130
+ #define wasm_name_new_new_uninitialized wasm_byte_vec_new_uninitialized
131
+ #define wasm_name_copy wasm_byte_vec_copy
132
+ #define wasm_name_delete wasm_byte_vec_delete
133
+
134
+ static inline void wasm_name_new_from_string(
135
+ own wasm_name_t* out, const char* s
136
+ ) {
137
+ wasm_name_new(out, strlen(s), s);
138
+ }
139
+
140
+ static inline void wasm_name_new_from_string_nt(
141
+ own wasm_name_t* out, const char* s
142
+ ) {
143
+ wasm_name_new(out, strlen(s) + 1, s);
144
+ }
145
+
146
+
147
+ ///////////////////////////////////////////////////////////////////////////////
148
+ // Runtime Environment
149
+
150
+ // Configuration
151
+
152
+ WASM_DECLARE_OWN(config)
153
+
154
+ #ifndef MEM_ALLOC_OPTION_DEFINED
155
+ #define MEM_ALLOC_OPTION_DEFINED
156
+ /* same definition from wasm_export.h */
157
+ /* Memory allocator type */
158
+ typedef enum {
159
+ /* pool mode, allocate memory from user defined heap buffer */
160
+ Alloc_With_Pool = 0,
161
+ /* user allocator mode, allocate memory from user defined
162
+ malloc function */
163
+ Alloc_With_Allocator,
164
+ /* system allocator mode, allocate memory from system allocator,
165
+ or, platform's os_malloc function */
166
+ Alloc_With_System_Allocator,
167
+ } mem_alloc_type_t;
168
+
169
+ /* Memory allocator option */
170
+ typedef union MemAllocOption {
171
+ struct {
172
+ void *heap_buf;
173
+ uint32_t heap_size;
174
+ } pool;
175
+ struct {
176
+ void *malloc_func;
177
+ void *realloc_func;
178
+ void *free_func;
179
+ /* allocator user data, only used when
180
+ WASM_MEM_ALLOC_WITH_USER_DATA is defined */
181
+ void *user_data;
182
+ } allocator;
183
+ } MemAllocOption;
184
+ #endif /* MEM_ALLOC_OPTION_DEFINED */
185
+
186
+ /* Runtime configuration */
187
+ struct wasm_config_t {
188
+ mem_alloc_type_t mem_alloc_type;
189
+ MemAllocOption mem_alloc_option;
190
+ uint32_t segue_flags;
191
+ bool enable_linux_perf;
192
+ /*TODO: wasi args*/
193
+ };
194
+
195
+ #ifndef INSTANTIATION_ARGS_OPTION_DEFINED
196
+ #define INSTANTIATION_ARGS_OPTION_DEFINED
197
+ /* WASM module instantiation arguments */
198
+ typedef struct InstantiationArgs {
199
+ uint32_t default_stack_size;
200
+ uint32_t host_managed_heap_size;
201
+ uint32_t max_memory_pages;
202
+ } InstantiationArgs;
203
+ #endif /* INSTANTIATION_ARGS_OPTION_DEFINED */
204
+
205
+ /*
206
+ * by default:
207
+ * - mem_alloc_type is Alloc_With_System_Allocator
208
+ * - mem_alloc_option is all 0
209
+ * - enable_linux_perf is false
210
+ */
211
+ WASM_API_EXTERN own wasm_config_t* wasm_config_new(void);
212
+
213
+ // Embedders may provide custom functions for manipulating configs.
214
+ WASM_API_EXTERN own wasm_config_t*
215
+ wasm_config_set_mem_alloc_opt(wasm_config_t *, mem_alloc_type_t, MemAllocOption *);
216
+
217
+ WASM_API_EXTERN own wasm_config_t*
218
+ wasm_config_set_linux_perf_opt(wasm_config_t *, bool);
219
+
220
+ /**
221
+ * Enable using GS register as the base address of linear memory in linux x86_64,
222
+ * which may speedup the linear memory access for LLVM AOT/JIT:
223
+ * bit0 to bit4 denotes i32.load, i64.load, f32.load, f64.load, v128.load
224
+ * bit8 to bit12 denotes i32.store, i64.store, f32.store, f64.store, v128.store
225
+ * For example, 0x01 enables i32.load, 0x0100 enables i32.store.
226
+ * To enable all load/store operations, use 0x1F1F
227
+ */
228
+ WASM_API_EXTERN wasm_config_t*
229
+ wasm_config_set_segue_flags(wasm_config_t *config, uint32_t segue_flags);
230
+
231
+ // Engine
232
+
233
+ WASM_DECLARE_OWN(engine)
234
+
235
+ /**
236
+ * Create a new engine
237
+ *
238
+ * Note: for the engine new/delete operations, including this,
239
+ * wasm_engine_new_with_config, wasm_engine_new_with_args, and
240
+ * wasm_engine_delete, if the platform has mutex initializer,
241
+ * then they are thread-safe: we use a global lock to lock the
242
+ * operations of the engine. Otherwise they are not thread-safe:
243
+ * when there are engine new/delete operations happening
244
+ * simultaneously in multiple threads, developer must create
245
+ * the lock by himself, and add the lock when calling these
246
+ * functions.
247
+ */
248
+ WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(void);
249
+ WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(wasm_config_t*);
250
+ WASM_API_DEPRECATED WASM_API_EXTERN own wasm_engine_t *
251
+ wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts);
252
+
253
+ // Store
254
+
255
+ WASM_DECLARE_OWN(store)
256
+
257
+ WASM_API_EXTERN own wasm_store_t* wasm_store_new(wasm_engine_t*);
258
+
259
+
260
+ ///////////////////////////////////////////////////////////////////////////////
261
+ // Type Representations
262
+
263
+ // Type attributes
264
+
265
+ typedef uint8_t wasm_mutability_t;
266
+ enum wasm_mutability_enum {
267
+ WASM_CONST,
268
+ WASM_VAR,
269
+ };
270
+
271
+ typedef struct wasm_limits_t {
272
+ uint32_t min;
273
+ uint32_t max;
274
+ } wasm_limits_t;
275
+
276
+ static const uint32_t wasm_limits_max_default = 0xffffffff;
277
+
278
+
279
+ // Generic
280
+
281
+ #define WASM_DECLARE_TYPE(name) \
282
+ WASM_DECLARE_OWN(name) \
283
+ WASM_DECLARE_VEC(name, *) \
284
+ \
285
+ WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*);
286
+
287
+
288
+ // Value Types
289
+
290
+ WASM_DECLARE_TYPE(valtype)
291
+
292
+ #ifndef WASM_VALKIND_T_DEFINED
293
+ #define WASM_VALKIND_T_DEFINED
294
+ typedef uint8_t wasm_valkind_t;
295
+ enum wasm_valkind_enum {
296
+ WASM_I32,
297
+ WASM_I64,
298
+ WASM_F32,
299
+ WASM_F64,
300
+ WASM_V128,
301
+ WASM_EXTERNREF = 128,
302
+ WASM_FUNCREF,
303
+ };
304
+ #endif
305
+
306
+ WASM_API_EXTERN own wasm_valtype_t* wasm_valtype_new(wasm_valkind_t);
307
+
308
+ WASM_API_EXTERN wasm_valkind_t wasm_valtype_kind(const wasm_valtype_t*);
309
+
310
+ static inline bool wasm_valkind_is_num(wasm_valkind_t k) {
311
+ return k < WASM_EXTERNREF;
312
+ }
313
+ static inline bool wasm_valkind_is_ref(wasm_valkind_t k) {
314
+ return k >= WASM_EXTERNREF;
315
+ }
316
+
317
+ static inline bool wasm_valtype_is_num(const wasm_valtype_t* t) {
318
+ return wasm_valkind_is_num(wasm_valtype_kind(t));
319
+ }
320
+ static inline bool wasm_valtype_is_ref(const wasm_valtype_t* t) {
321
+ return wasm_valkind_is_ref(wasm_valtype_kind(t));
322
+ }
323
+
324
+
325
+ // Function Types
326
+
327
+ WASM_DECLARE_TYPE(functype)
328
+
329
+ WASM_API_EXTERN own wasm_functype_t* wasm_functype_new(
330
+ own wasm_valtype_vec_t* params, own wasm_valtype_vec_t* results);
331
+
332
+ WASM_API_EXTERN const wasm_valtype_vec_t* wasm_functype_params(const wasm_functype_t*);
333
+ WASM_API_EXTERN const wasm_valtype_vec_t* wasm_functype_results(const wasm_functype_t*);
334
+
335
+
336
+ // Global Types
337
+
338
+ WASM_DECLARE_TYPE(globaltype)
339
+
340
+ WASM_API_EXTERN own wasm_globaltype_t* wasm_globaltype_new(
341
+ own wasm_valtype_t*, wasm_mutability_t);
342
+
343
+ WASM_API_EXTERN const wasm_valtype_t* wasm_globaltype_content(const wasm_globaltype_t*);
344
+ WASM_API_EXTERN wasm_mutability_t wasm_globaltype_mutability(const wasm_globaltype_t*);
345
+
346
+
347
+ // Table Types
348
+
349
+ WASM_DECLARE_TYPE(tabletype)
350
+
351
+ WASM_API_EXTERN own wasm_tabletype_t* wasm_tabletype_new(
352
+ own wasm_valtype_t*, const wasm_limits_t*);
353
+
354
+ WASM_API_EXTERN const wasm_valtype_t* wasm_tabletype_element(const wasm_tabletype_t*);
355
+ WASM_API_EXTERN const wasm_limits_t* wasm_tabletype_limits(const wasm_tabletype_t*);
356
+
357
+
358
+ // Memory Types
359
+
360
+ WASM_DECLARE_TYPE(memorytype)
361
+
362
+ WASM_API_EXTERN own wasm_memorytype_t* wasm_memorytype_new(const wasm_limits_t*);
363
+
364
+ WASM_API_EXTERN const wasm_limits_t* wasm_memorytype_limits(const wasm_memorytype_t*);
365
+
366
+
367
+ // Extern Types
368
+
369
+ WASM_DECLARE_TYPE(externtype)
370
+
371
+ typedef uint8_t wasm_externkind_t;
372
+ enum wasm_externkind_enum {
373
+ WASM_EXTERN_FUNC,
374
+ WASM_EXTERN_GLOBAL,
375
+ WASM_EXTERN_TABLE,
376
+ WASM_EXTERN_MEMORY,
377
+ };
378
+
379
+ WASM_API_EXTERN wasm_externkind_t wasm_externtype_kind(const wasm_externtype_t*);
380
+
381
+ WASM_API_EXTERN wasm_externtype_t* wasm_functype_as_externtype(wasm_functype_t*);
382
+ WASM_API_EXTERN wasm_externtype_t* wasm_globaltype_as_externtype(wasm_globaltype_t*);
383
+ WASM_API_EXTERN wasm_externtype_t* wasm_tabletype_as_externtype(wasm_tabletype_t*);
384
+ WASM_API_EXTERN wasm_externtype_t* wasm_memorytype_as_externtype(wasm_memorytype_t*);
385
+
386
+ WASM_API_EXTERN wasm_functype_t* wasm_externtype_as_functype(wasm_externtype_t*);
387
+ WASM_API_EXTERN wasm_globaltype_t* wasm_externtype_as_globaltype(wasm_externtype_t*);
388
+ WASM_API_EXTERN wasm_tabletype_t* wasm_externtype_as_tabletype(wasm_externtype_t*);
389
+ WASM_API_EXTERN wasm_memorytype_t* wasm_externtype_as_memorytype(wasm_externtype_t*);
390
+
391
+ WASM_API_EXTERN const wasm_externtype_t* wasm_functype_as_externtype_const(const wasm_functype_t*);
392
+ WASM_API_EXTERN const wasm_externtype_t* wasm_globaltype_as_externtype_const(const wasm_globaltype_t*);
393
+ WASM_API_EXTERN const wasm_externtype_t* wasm_tabletype_as_externtype_const(const wasm_tabletype_t*);
394
+ WASM_API_EXTERN const wasm_externtype_t* wasm_memorytype_as_externtype_const(const wasm_memorytype_t*);
395
+
396
+ WASM_API_EXTERN const wasm_functype_t* wasm_externtype_as_functype_const(const wasm_externtype_t*);
397
+ WASM_API_EXTERN const wasm_globaltype_t* wasm_externtype_as_globaltype_const(const wasm_externtype_t*);
398
+ WASM_API_EXTERN const wasm_tabletype_t* wasm_externtype_as_tabletype_const(const wasm_externtype_t*);
399
+ WASM_API_EXTERN const wasm_memorytype_t* wasm_externtype_as_memorytype_const(const wasm_externtype_t*);
400
+
401
+
402
+ // Import Types
403
+
404
+ WASM_DECLARE_TYPE(importtype)
405
+
406
+ WASM_API_EXTERN own wasm_importtype_t* wasm_importtype_new(
407
+ own wasm_name_t* module, own wasm_name_t* name, own wasm_externtype_t*);
408
+
409
+ WASM_API_EXTERN const wasm_name_t* wasm_importtype_module(const wasm_importtype_t*);
410
+ WASM_API_EXTERN const wasm_name_t* wasm_importtype_name(const wasm_importtype_t*);
411
+ WASM_API_EXTERN const wasm_externtype_t* wasm_importtype_type(const wasm_importtype_t*);
412
+ WASM_API_EXTERN bool wasm_importtype_is_linked(const wasm_importtype_t*);
413
+
414
+
415
+ // Export Types
416
+
417
+ WASM_DECLARE_TYPE(exporttype)
418
+
419
+ WASM_API_EXTERN own wasm_exporttype_t* wasm_exporttype_new(
420
+ own wasm_name_t*, own wasm_externtype_t*);
421
+
422
+ WASM_API_EXTERN const wasm_name_t* wasm_exporttype_name(const wasm_exporttype_t*);
423
+ WASM_API_EXTERN const wasm_externtype_t* wasm_exporttype_type(const wasm_exporttype_t*);
424
+
425
+
426
+ ///////////////////////////////////////////////////////////////////////////////
427
+ // Runtime Objects
428
+
429
+ // Values
430
+
431
+ #ifndef WASM_VAL_T_DEFINED
432
+ #define WASM_VAL_T_DEFINED
433
+ struct wasm_ref_t;
434
+
435
+ typedef struct wasm_val_t {
436
+ wasm_valkind_t kind;
437
+ uint8_t _paddings[7];
438
+ union {
439
+ int32_t i32;
440
+ int64_t i64;
441
+ float32_t f32;
442
+ float64_t f64;
443
+ struct wasm_ref_t* ref;
444
+ } of;
445
+ } wasm_val_t;
446
+ #endif
447
+
448
+ WASM_API_EXTERN void wasm_val_delete(own wasm_val_t* v);
449
+ WASM_API_EXTERN void wasm_val_copy(own wasm_val_t* out, const wasm_val_t*);
450
+
451
+ WASM_DECLARE_VEC(val, )
452
+
453
+
454
+ // References
455
+
456
+ #define WASM_DECLARE_REF_BASE(name) \
457
+ WASM_DECLARE_OWN(name) \
458
+ \
459
+ WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*); \
460
+ WASM_API_EXTERN bool wasm_##name##_same(const wasm_##name##_t*, const wasm_##name##_t*); \
461
+ \
462
+ WASM_API_EXTERN void* wasm_##name##_get_host_info(const wasm_##name##_t*); \
463
+ WASM_API_EXTERN void wasm_##name##_set_host_info(wasm_##name##_t*, void*); \
464
+ WASM_API_EXTERN void wasm_##name##_set_host_info_with_finalizer( \
465
+ wasm_##name##_t*, void*, void (*)(void*));
466
+
467
+ #define WASM_DECLARE_REF(name) \
468
+ WASM_DECLARE_REF_BASE(name) \
469
+ \
470
+ WASM_API_EXTERN wasm_ref_t* wasm_##name##_as_ref(wasm_##name##_t*); \
471
+ WASM_API_EXTERN wasm_##name##_t* wasm_ref_as_##name(wasm_ref_t*); \
472
+ WASM_API_EXTERN const wasm_ref_t* wasm_##name##_as_ref_const(const wasm_##name##_t*); \
473
+ WASM_API_EXTERN const wasm_##name##_t* wasm_ref_as_##name##_const(const wasm_ref_t*);
474
+
475
+ #define WASM_DECLARE_SHARABLE_REF(name) \
476
+ WASM_DECLARE_REF(name) \
477
+ WASM_DECLARE_OWN(shared_##name) \
478
+ \
479
+ WASM_API_EXTERN own wasm_shared_##name##_t* wasm_##name##_share(const wasm_##name##_t*); \
480
+ WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_obtain(wasm_store_t*, const wasm_shared_##name##_t*);
481
+
482
+
483
+ WASM_DECLARE_REF_BASE(ref)
484
+
485
+
486
+ // Frames
487
+
488
+ WASM_DECLARE_OWN(frame)
489
+ WASM_DECLARE_VEC(frame, *)
490
+ WASM_API_EXTERN own wasm_frame_t* wasm_frame_copy(const wasm_frame_t*);
491
+
492
+ WASM_API_EXTERN struct wasm_instance_t* wasm_frame_instance(const wasm_frame_t*);
493
+ WASM_API_EXTERN uint32_t wasm_frame_func_index(const wasm_frame_t*);
494
+ WASM_API_EXTERN size_t wasm_frame_func_offset(const wasm_frame_t*);
495
+ WASM_API_EXTERN size_t wasm_frame_module_offset(const wasm_frame_t*);
496
+
497
+
498
+ // Traps
499
+
500
+ typedef wasm_name_t wasm_message_t; // null terminated
501
+
502
+ WASM_DECLARE_REF(trap)
503
+
504
+ WASM_API_EXTERN own wasm_trap_t* wasm_trap_new(wasm_store_t* store, const wasm_message_t*);
505
+
506
+ WASM_API_EXTERN void wasm_trap_message(const wasm_trap_t*, own wasm_message_t* out);
507
+ WASM_API_EXTERN own wasm_frame_t* wasm_trap_origin(const wasm_trap_t*);
508
+ WASM_API_EXTERN void wasm_trap_trace(const wasm_trap_t*, own wasm_frame_vec_t* out);
509
+
510
+
511
+ // Foreign Objects
512
+
513
+ WASM_DECLARE_REF(foreign)
514
+
515
+ WASM_API_EXTERN own wasm_foreign_t* wasm_foreign_new(wasm_store_t*);
516
+
517
+
518
+ // Modules
519
+ // WASM_DECLARE_SHARABLE_REF(module)
520
+
521
+ #ifndef WASM_MODULE_T_DEFINED
522
+ #define WASM_MODULE_T_DEFINED
523
+ struct WASMModuleCommon;
524
+ typedef struct WASMModuleCommon *wasm_module_t;
525
+ #endif
526
+
527
+ #ifndef LOAD_ARGS_OPTION_DEFINED
528
+ #define LOAD_ARGS_OPTION_DEFINED
529
+ typedef struct LoadArgs {
530
+ char *name;
531
+ /* True by default, used by wasm-c-api only.
532
+ If false, the wasm input buffer (wasm_byte_vec_t) is referenced by the
533
+ module instead of being cloned. Hence, it can be freed after module loading. */
534
+ bool clone_wasm_binary;
535
+ /* This option is only used by the AOT/wasm loader (see wasm_export.h) */
536
+ bool wasm_binary_freeable;
537
+ /* false by default, if true, don't resolve the symbols yet. The
538
+ wasm_runtime_load_ex has to be followed by a wasm_runtime_resolve_symbols
539
+ call */
540
+ bool no_resolve;
541
+ /* TODO: more fields? */
542
+ } LoadArgs;
543
+ #endif /* LOAD_ARGS_OPTION_DEFINED */
544
+
545
+ WASM_API_EXTERN own wasm_module_t* wasm_module_new(
546
+ wasm_store_t*, const wasm_byte_vec_t* binary);
547
+
548
+ // please refer to wasm_runtime_load_ex(...) in core/iwasm/include/wasm_export.h
549
+ WASM_API_EXTERN own wasm_module_t* wasm_module_new_ex(
550
+ wasm_store_t*, wasm_byte_vec_t* binary, LoadArgs *args);
551
+
552
+ WASM_API_EXTERN void wasm_module_delete(own wasm_module_t*);
553
+
554
+ WASM_API_EXTERN bool wasm_module_validate(wasm_store_t*, const wasm_byte_vec_t* binary);
555
+
556
+ WASM_API_EXTERN void wasm_module_imports(const wasm_module_t*, own wasm_importtype_vec_t* out);
557
+ WASM_API_EXTERN void wasm_module_exports(const wasm_module_t*, own wasm_exporttype_vec_t* out);
558
+
559
+ WASM_API_EXTERN void wasm_module_serialize(wasm_module_t*, own wasm_byte_vec_t* out);
560
+ WASM_API_EXTERN own wasm_module_t* wasm_module_deserialize(wasm_store_t*, const wasm_byte_vec_t*);
561
+
562
+ typedef wasm_module_t wasm_shared_module_t;
563
+ WASM_API_EXTERN own wasm_shared_module_t* wasm_module_share(wasm_module_t*);
564
+ WASM_API_EXTERN own wasm_module_t* wasm_module_obtain(wasm_store_t*, wasm_shared_module_t*);
565
+ WASM_API_EXTERN void wasm_shared_module_delete(own wasm_shared_module_t*);
566
+
567
+ WASM_API_EXTERN bool wasm_module_set_name(wasm_module_t*, const char* name);
568
+ WASM_API_EXTERN const char *wasm_module_get_name(wasm_module_t*);
569
+
570
+ WASM_API_EXTERN bool wasm_module_is_underlying_binary_freeable(const wasm_module_t *module);
571
+
572
+
573
+ // Function Instances
574
+
575
+ WASM_DECLARE_REF(func)
576
+
577
+ typedef own wasm_trap_t* (*wasm_func_callback_t)(
578
+ const wasm_val_vec_t* args, own wasm_val_vec_t *results);
579
+ typedef own wasm_trap_t* (*wasm_func_callback_with_env_t)(
580
+ void* env, const wasm_val_vec_t *args, wasm_val_vec_t *results);
581
+
582
+ WASM_API_EXTERN own wasm_func_t* wasm_func_new(
583
+ wasm_store_t*, const wasm_functype_t*, wasm_func_callback_t);
584
+ WASM_API_EXTERN own wasm_func_t* wasm_func_new_with_env(
585
+ wasm_store_t*, const wasm_functype_t* type, wasm_func_callback_with_env_t,
586
+ void* env, void (*finalizer)(void*));
587
+
588
+ WASM_API_EXTERN own wasm_functype_t* wasm_func_type(const wasm_func_t*);
589
+ WASM_API_EXTERN size_t wasm_func_param_arity(const wasm_func_t*);
590
+ WASM_API_EXTERN size_t wasm_func_result_arity(const wasm_func_t*);
591
+
592
+ WASM_API_EXTERN own wasm_trap_t* wasm_func_call(
593
+ const wasm_func_t*, const wasm_val_vec_t* args, wasm_val_vec_t* results);
594
+
595
+
596
+ // Global Instances
597
+
598
+ WASM_DECLARE_REF(global)
599
+
600
+ WASM_API_EXTERN own wasm_global_t* wasm_global_new(
601
+ wasm_store_t*, const wasm_globaltype_t*, const wasm_val_t*);
602
+
603
+ WASM_API_EXTERN own wasm_globaltype_t* wasm_global_type(const wasm_global_t*);
604
+
605
+ WASM_API_EXTERN void wasm_global_get(const wasm_global_t*, own wasm_val_t* out);
606
+ WASM_API_EXTERN void wasm_global_set(wasm_global_t*, const wasm_val_t*);
607
+
608
+
609
+ // Table Instances
610
+
611
+ WASM_DECLARE_REF(table)
612
+
613
+ typedef uint32_t wasm_table_size_t;
614
+
615
+ WASM_API_EXTERN own wasm_table_t* wasm_table_new(
616
+ wasm_store_t*, const wasm_tabletype_t*, wasm_ref_t* init);
617
+
618
+ WASM_API_EXTERN own wasm_tabletype_t* wasm_table_type(const wasm_table_t*);
619
+
620
+ WASM_API_EXTERN own wasm_ref_t* wasm_table_get(const wasm_table_t*, wasm_table_size_t index);
621
+ WASM_API_EXTERN bool wasm_table_set(wasm_table_t*, wasm_table_size_t index, wasm_ref_t*);
622
+
623
+ WASM_API_EXTERN wasm_table_size_t wasm_table_size(const wasm_table_t*);
624
+ WASM_API_EXTERN bool wasm_table_grow(wasm_table_t*, wasm_table_size_t delta, wasm_ref_t* init);
625
+
626
+
627
+ // Memory Instances
628
+
629
+ WASM_DECLARE_REF(memory)
630
+
631
+ typedef uint32_t wasm_memory_pages_t;
632
+
633
+ static const size_t MEMORY_PAGE_SIZE = 0x10000;
634
+
635
+ WASM_API_EXTERN own wasm_memory_t* wasm_memory_new(wasm_store_t*, const wasm_memorytype_t*);
636
+
637
+ WASM_API_EXTERN own wasm_memorytype_t* wasm_memory_type(const wasm_memory_t*);
638
+
639
+ WASM_API_EXTERN byte_t* wasm_memory_data(wasm_memory_t*);
640
+ WASM_API_EXTERN size_t wasm_memory_data_size(const wasm_memory_t*);
641
+
642
+ WASM_API_EXTERN wasm_memory_pages_t wasm_memory_size(const wasm_memory_t*);
643
+ WASM_API_EXTERN bool wasm_memory_grow(wasm_memory_t*, wasm_memory_pages_t delta);
644
+
645
+
646
+ // Externals
647
+
648
+ WASM_DECLARE_REF(extern)
649
+ WASM_DECLARE_VEC(extern, *)
650
+
651
+ WASM_API_EXTERN wasm_externkind_t wasm_extern_kind(const wasm_extern_t*);
652
+ WASM_API_EXTERN own wasm_externtype_t* wasm_extern_type(const wasm_extern_t*);
653
+
654
+ WASM_API_EXTERN wasm_extern_t* wasm_func_as_extern(wasm_func_t*);
655
+ WASM_API_EXTERN wasm_extern_t* wasm_global_as_extern(wasm_global_t*);
656
+ WASM_API_EXTERN wasm_extern_t* wasm_table_as_extern(wasm_table_t*);
657
+ WASM_API_EXTERN wasm_extern_t* wasm_memory_as_extern(wasm_memory_t*);
658
+
659
+ WASM_API_EXTERN wasm_func_t* wasm_extern_as_func(wasm_extern_t*);
660
+ WASM_API_EXTERN wasm_global_t* wasm_extern_as_global(wasm_extern_t*);
661
+ WASM_API_EXTERN wasm_table_t* wasm_extern_as_table(wasm_extern_t*);
662
+ WASM_API_EXTERN wasm_memory_t* wasm_extern_as_memory(wasm_extern_t*);
663
+
664
+ WASM_API_EXTERN const wasm_extern_t* wasm_func_as_extern_const(const wasm_func_t*);
665
+ WASM_API_EXTERN const wasm_extern_t* wasm_global_as_extern_const(const wasm_global_t*);
666
+ WASM_API_EXTERN const wasm_extern_t* wasm_table_as_extern_const(const wasm_table_t*);
667
+ WASM_API_EXTERN const wasm_extern_t* wasm_memory_as_extern_const(const wasm_memory_t*);
668
+
669
+ WASM_API_EXTERN const wasm_func_t* wasm_extern_as_func_const(const wasm_extern_t*);
670
+ WASM_API_EXTERN const wasm_global_t* wasm_extern_as_global_const(const wasm_extern_t*);
671
+ WASM_API_EXTERN const wasm_table_t* wasm_extern_as_table_const(const wasm_extern_t*);
672
+ WASM_API_EXTERN const wasm_memory_t* wasm_extern_as_memory_const(const wasm_extern_t*);
673
+
674
+
675
+ // Module Instances
676
+
677
+ WASM_DECLARE_REF(instance)
678
+
679
+ WASM_API_EXTERN own wasm_instance_t* wasm_instance_new(
680
+ wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t *imports,
681
+ own wasm_trap_t** trap
682
+ );
683
+
684
+ // please refer to wasm_runtime_instantiate(...) in core/iwasm/include/wasm_export.h
685
+ WASM_API_EXTERN own wasm_instance_t* wasm_instance_new_with_args(
686
+ wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t *imports,
687
+ own wasm_trap_t** trap, const uint32_t stack_size, const uint32_t heap_size
688
+ );
689
+
690
+ // please refer to wasm_runtime_instantiate_ex(...) in core/iwasm/include/wasm_export.h
691
+ WASM_API_EXTERN own wasm_instance_t* wasm_instance_new_with_args_ex(
692
+ wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t *imports,
693
+ own wasm_trap_t** trap, const InstantiationArgs *inst_args
694
+ );
695
+
696
+ WASM_API_EXTERN void wasm_instance_exports(const wasm_instance_t*, own wasm_extern_vec_t* out);
697
+
698
+ // Return total wasm functions' execution time in ms
699
+ WASM_API_EXTERN double wasm_instance_sum_wasm_exec_time(const wasm_instance_t*);
700
+ // Return execution time in ms of a given wasm function with
701
+ // func_name. If the function is not found, return 0.
702
+ WASM_API_EXTERN double wasm_instance_get_wasm_func_exec_time(const wasm_instance_t*, const char *);
703
+
704
+ ///////////////////////////////////////////////////////////////////////////////
705
+ // Convenience
706
+
707
+ // Vectors
708
+
709
+ #define WASM_EMPTY_VEC {0, NULL, 0, 0, NULL}
710
+ #define WASM_ARRAY_VEC(array) {sizeof(array)/sizeof(*(array)), array, sizeof(array)/sizeof(*(array)), sizeof(*(array)), NULL}
711
+
712
+
713
+ // Value Type construction short-hands
714
+
715
+ static inline own wasm_valtype_t* wasm_valtype_new_i32(void) {
716
+ return wasm_valtype_new(WASM_I32);
717
+ }
718
+ static inline own wasm_valtype_t* wasm_valtype_new_i64(void) {
719
+ return wasm_valtype_new(WASM_I64);
720
+ }
721
+ static inline own wasm_valtype_t* wasm_valtype_new_f32(void) {
722
+ return wasm_valtype_new(WASM_F32);
723
+ }
724
+ static inline own wasm_valtype_t* wasm_valtype_new_f64(void) {
725
+ return wasm_valtype_new(WASM_F64);
726
+ }
727
+ static inline own wasm_valtype_t* wasm_valtype_new_v128(void) {
728
+ return wasm_valtype_new(WASM_V128);
729
+ }
730
+
731
+ static inline own wasm_valtype_t* wasm_valtype_new_anyref(void) {
732
+ return wasm_valtype_new(WASM_EXTERNREF);
733
+ }
734
+ static inline own wasm_valtype_t* wasm_valtype_new_funcref(void) {
735
+ return wasm_valtype_new(WASM_FUNCREF);
736
+ }
737
+
738
+
739
+ // Function Types construction short-hands
740
+
741
+ static inline own wasm_functype_t* wasm_functype_new_0_0(void) {
742
+ wasm_valtype_vec_t params, results;
743
+ wasm_valtype_vec_new_empty(&params);
744
+ wasm_valtype_vec_new_empty(&results);
745
+ return wasm_functype_new(&params, &results);
746
+ }
747
+
748
+ static inline own wasm_functype_t* wasm_functype_new_1_0(
749
+ own wasm_valtype_t* p
750
+ ) {
751
+ wasm_valtype_t* ps[1] = {p};
752
+ wasm_valtype_vec_t params, results;
753
+ wasm_valtype_vec_new(&params, 1, ps);
754
+ wasm_valtype_vec_new_empty(&results);
755
+ return wasm_functype_new(&params, &results);
756
+ }
757
+
758
+ static inline own wasm_functype_t* wasm_functype_new_2_0(
759
+ own wasm_valtype_t* p1, own wasm_valtype_t* p2
760
+ ) {
761
+ wasm_valtype_t* ps[2] = {p1, p2};
762
+ wasm_valtype_vec_t params, results;
763
+ wasm_valtype_vec_new(&params, 2, ps);
764
+ wasm_valtype_vec_new_empty(&results);
765
+ return wasm_functype_new(&params, &results);
766
+ }
767
+
768
+ static inline own wasm_functype_t* wasm_functype_new_3_0(
769
+ own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3
770
+ ) {
771
+ wasm_valtype_t* ps[3] = {p1, p2, p3};
772
+ wasm_valtype_vec_t params, results;
773
+ wasm_valtype_vec_new(&params, 3, ps);
774
+ wasm_valtype_vec_new_empty(&results);
775
+ return wasm_functype_new(&params, &results);
776
+ }
777
+
778
+ static inline own wasm_functype_t* wasm_functype_new_0_1(
779
+ own wasm_valtype_t* r
780
+ ) {
781
+ wasm_valtype_t* rs[1] = {r};
782
+ wasm_valtype_vec_t params, results;
783
+ wasm_valtype_vec_new_empty(&params);
784
+ wasm_valtype_vec_new(&results, 1, rs);
785
+ return wasm_functype_new(&params, &results);
786
+ }
787
+
788
+ static inline own wasm_functype_t* wasm_functype_new_1_1(
789
+ own wasm_valtype_t* p, own wasm_valtype_t* r
790
+ ) {
791
+ wasm_valtype_t* ps[1] = {p};
792
+ wasm_valtype_t* rs[1] = {r};
793
+ wasm_valtype_vec_t params, results;
794
+ wasm_valtype_vec_new(&params, 1, ps);
795
+ wasm_valtype_vec_new(&results, 1, rs);
796
+ return wasm_functype_new(&params, &results);
797
+ }
798
+
799
+ static inline own wasm_functype_t* wasm_functype_new_2_1(
800
+ own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* r
801
+ ) {
802
+ wasm_valtype_t* ps[2] = {p1, p2};
803
+ wasm_valtype_t* rs[1] = {r};
804
+ wasm_valtype_vec_t params, results;
805
+ wasm_valtype_vec_new(&params, 2, ps);
806
+ wasm_valtype_vec_new(&results, 1, rs);
807
+ return wasm_functype_new(&params, &results);
808
+ }
809
+
810
+ static inline own wasm_functype_t* wasm_functype_new_3_1(
811
+ own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3,
812
+ own wasm_valtype_t* r
813
+ ) {
814
+ wasm_valtype_t* ps[3] = {p1, p2, p3};
815
+ wasm_valtype_t* rs[1] = {r};
816
+ wasm_valtype_vec_t params, results;
817
+ wasm_valtype_vec_new(&params, 3, ps);
818
+ wasm_valtype_vec_new(&results, 1, rs);
819
+ return wasm_functype_new(&params, &results);
820
+ }
821
+
822
+ static inline own wasm_functype_t* wasm_functype_new_0_2(
823
+ own wasm_valtype_t* r1, own wasm_valtype_t* r2
824
+ ) {
825
+ wasm_valtype_t* rs[2] = {r1, r2};
826
+ wasm_valtype_vec_t params, results;
827
+ wasm_valtype_vec_new_empty(&params);
828
+ wasm_valtype_vec_new(&results, 2, rs);
829
+ return wasm_functype_new(&params, &results);
830
+ }
831
+
832
+ static inline own wasm_functype_t* wasm_functype_new_1_2(
833
+ own wasm_valtype_t* p, own wasm_valtype_t* r1, own wasm_valtype_t* r2
834
+ ) {
835
+ wasm_valtype_t* ps[1] = {p};
836
+ wasm_valtype_t* rs[2] = {r1, r2};
837
+ wasm_valtype_vec_t params, results;
838
+ wasm_valtype_vec_new(&params, 1, ps);
839
+ wasm_valtype_vec_new(&results, 2, rs);
840
+ return wasm_functype_new(&params, &results);
841
+ }
842
+
843
+ static inline own wasm_functype_t* wasm_functype_new_2_2(
844
+ own wasm_valtype_t* p1, own wasm_valtype_t* p2,
845
+ own wasm_valtype_t* r1, own wasm_valtype_t* r2
846
+ ) {
847
+ wasm_valtype_t* ps[2] = {p1, p2};
848
+ wasm_valtype_t* rs[2] = {r1, r2};
849
+ wasm_valtype_vec_t params, results;
850
+ wasm_valtype_vec_new(&params, 2, ps);
851
+ wasm_valtype_vec_new(&results, 2, rs);
852
+ return wasm_functype_new(&params, &results);
853
+ }
854
+
855
+ static inline own wasm_functype_t* wasm_functype_new_3_2(
856
+ own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3,
857
+ own wasm_valtype_t* r1, own wasm_valtype_t* r2
858
+ ) {
859
+ wasm_valtype_t* ps[3] = {p1, p2, p3};
860
+ wasm_valtype_t* rs[2] = {r1, r2};
861
+ wasm_valtype_vec_t params, results;
862
+ wasm_valtype_vec_new(&params, 3, ps);
863
+ wasm_valtype_vec_new(&results, 2, rs);
864
+ return wasm_functype_new(&params, &results);
865
+ }
866
+
867
+
868
+ // Value construction short-hands
869
+
870
+ static inline void wasm_val_init_ptr(own wasm_val_t* out, void* p) {
871
+ #if UINTPTR_MAX == UINT32_MAX
872
+ out->kind = WASM_I32;
873
+ out->of.i32 = (intptr_t)p;
874
+ #elif UINTPTR_MAX == UINT64_MAX
875
+ out->kind = WASM_I64;
876
+ out->of.i64 = (intptr_t)p;
877
+ #endif
878
+ }
879
+
880
+ static inline void* wasm_val_ptr(const wasm_val_t* val) {
881
+ #if UINTPTR_MAX == UINT32_MAX
882
+ return (void*)(intptr_t)val->of.i32;
883
+ #elif UINTPTR_MAX == UINT64_MAX
884
+ return (void*)(intptr_t)val->of.i64;
885
+ #endif
886
+ }
887
+
888
+ #define WASM_I32_VAL(i) {.kind = WASM_I32, ._paddings = {0}, .of = {.i32 = i}}
889
+ #define WASM_I64_VAL(i) {.kind = WASM_I64, ._paddings = {0}, .of = {.i64 = i}}
890
+ #define WASM_F32_VAL(z) {.kind = WASM_F32, ._paddings = {0}, .of = {.f32 = z}}
891
+ #define WASM_F64_VAL(z) {.kind = WASM_F64, ._paddings = {0}, .of = {.f64 = z}}
892
+ #define WASM_REF_VAL(r) {.kind = WASM_EXTERNREF, ._paddings = {0}, .of = {.ref = r}}
893
+ #define WASM_INIT_VAL {.kind = WASM_EXTERNREF, ._paddings = {0}, .of = {.ref = NULL}}
894
+
895
+ #define KILOBYTE(n) ((n) * 1024)
896
+
897
+ // Create placeholders filled in `wasm_externvec_t* imports` for `wasm_instance_new()`
898
+ WASM_API_EXTERN wasm_extern_t *wasm_extern_new_empty(wasm_store_t *, wasm_externkind_t);
899
+
900
+ ///////////////////////////////////////////////////////////////////////////////
901
+
902
+ #undef own
903
+
904
+ /* clang-format on */
905
+
906
+ #ifdef __cplusplus
907
+ } // extern "C"
908
+ #endif
909
+
910
+ #endif // #ifdef _WASM_C_API_H_