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,328 @@
1
+ /*
2
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
+ */
5
+
6
+ #ifndef _WASM_EXEC_ENV_H
7
+ #define _WASM_EXEC_ENV_H
8
+
9
+ #include "bh_assert.h"
10
+ #include "wasm_suspend_flags.h"
11
+ #if WASM_ENABLE_INTERP != 0
12
+ #include "../interpreter/wasm.h"
13
+ #endif
14
+
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif
18
+
19
+ struct WASMModuleInstanceCommon;
20
+ struct WASMInterpFrame;
21
+
22
+ #if WASM_ENABLE_THREAD_MGR != 0
23
+ typedef struct WASMCluster WASMCluster;
24
+ #if WASM_ENABLE_DEBUG_INTERP != 0
25
+ typedef struct WASMCurrentEnvStatus WASMCurrentEnvStatus;
26
+ #endif
27
+ #endif
28
+
29
+ #ifdef OS_ENABLE_HW_BOUND_CHECK
30
+ typedef struct WASMJmpBuf {
31
+ struct WASMJmpBuf *prev;
32
+ korp_jmpbuf jmpbuf;
33
+ } WASMJmpBuf;
34
+ #endif
35
+
36
+ /* Execution environment */
37
+ typedef struct WASMExecEnv {
38
+ /* Next thread's exec env of a WASM module instance. */
39
+ struct WASMExecEnv *next;
40
+
41
+ /* Current interpreter/AOT frame of current thread */
42
+ struct WASMInterpFrame *cur_frame;
43
+
44
+ /* Note: field module_inst, argv_buf, native_stack_boundary,
45
+ suspend_flags, aux_stack_boundary, aux_stack_bottom, and
46
+ native_symbol are used by AOTed code, don't change the
47
+ places of them */
48
+
49
+ /* The WASM module instance of current thread */
50
+ struct WASMModuleInstanceCommon *module_inst;
51
+
52
+ #if WASM_ENABLE_AOT != 0
53
+ uint32 *argv_buf;
54
+ #endif
55
+
56
+ /* The boundary of native stack. When runtime detects that native
57
+ frame may overrun this boundary, it throws stack overflow
58
+ exception. */
59
+ uint8 *native_stack_boundary;
60
+
61
+ /* Used to terminate or suspend current thread */
62
+ WASMSuspendFlags suspend_flags;
63
+
64
+ /* Auxiliary stack boundary */
65
+ uintptr_t aux_stack_boundary;
66
+
67
+ /* Auxiliary stack bottom */
68
+ uintptr_t aux_stack_bottom;
69
+
70
+ #if WASM_ENABLE_AOT != 0
71
+ /* Native symbol list, reserved */
72
+ void **native_symbol;
73
+ #endif
74
+
75
+ /*
76
+ * The lowest stack pointer value observed.
77
+ * Assumption: native stack grows to the lower address.
78
+ */
79
+ uint8 *native_stack_top_min;
80
+
81
+ struct {
82
+ /* The top boundary of the stack. */
83
+ uint8 *top_boundary;
84
+ /* The top to of the wasm stack which is free. */
85
+ uint8 *top;
86
+ /* The bottom of the wasm stack. */
87
+ uint8 *bottom;
88
+ } wasm_stack;
89
+
90
+ #if WASM_ENABLE_INSTRUCTION_METERING != 0
91
+ /* instructions to execute */
92
+ int instructions_to_execute;
93
+ #endif
94
+
95
+ #if WASM_ENABLE_FAST_JIT != 0
96
+ /**
97
+ * Cache for
98
+ * - jit native operations in 32-bit target which hasn't 64-bit
99
+ * int/float registers, mainly for the operations of double and int64,
100
+ * such as F64TOI64, F32TOI64, I64 MUL/REM, and so on.
101
+ * - SSE instructions.
102
+ **/
103
+ uint64 jit_cache[2];
104
+ #endif
105
+
106
+ #if WASM_ENABLE_THREAD_MGR != 0
107
+ /* thread return value */
108
+ void *thread_ret_value;
109
+
110
+ /* Must be provided by thread library */
111
+ void *(*thread_start_routine)(void *);
112
+ void *thread_arg;
113
+
114
+ /* pointer to the cluster */
115
+ WASMCluster *cluster;
116
+
117
+ /* used to support debugger */
118
+ korp_mutex wait_lock;
119
+ korp_cond wait_cond;
120
+ /* the count of threads which are joining current thread */
121
+ uint32 wait_count;
122
+
123
+ /* whether current thread is detached */
124
+ bool thread_is_detached;
125
+
126
+ /* whether the aux stack is allocated */
127
+ bool is_aux_stack_allocated;
128
+ #endif
129
+
130
+ #if WASM_ENABLE_GC != 0
131
+ /* Current local object reference variable */
132
+ struct WASMLocalObjectRef *cur_local_object_ref;
133
+ #endif
134
+
135
+ #if WASM_ENABLE_DEBUG_INTERP != 0
136
+ WASMCurrentEnvStatus *current_status;
137
+ #endif
138
+
139
+ /* attachment for native function */
140
+ void *attachment;
141
+
142
+ void *user_data;
143
+
144
+ /* The boundary of native stack set by host embedder. It is used
145
+ if it is not NULL when calling wasm functions. */
146
+ uint8 *user_native_stack_boundary;
147
+
148
+ /* The native thread handle of current thread */
149
+ korp_tid handle;
150
+
151
+ #if WASM_ENABLE_INTERP != 0 && WASM_ENABLE_FAST_INTERP == 0
152
+ BlockAddr block_addr_cache[BLOCK_ADDR_CACHE_SIZE][BLOCK_ADDR_CONFLICT_SIZE];
153
+ #endif
154
+
155
+ #ifdef OS_ENABLE_HW_BOUND_CHECK
156
+ WASMJmpBuf *jmpbuf_stack_top;
157
+ /* One guard page for the exception check */
158
+ uint8 *exce_check_guard_page;
159
+ #endif
160
+
161
+ #if WASM_ENABLE_MEMORY_PROFILING != 0
162
+ uint32 max_wasm_stack_used;
163
+ #endif
164
+
165
+ /* The WASM stack size */
166
+ uint32 wasm_stack_size;
167
+
168
+ /* The WASM stack of current thread */
169
+ union {
170
+ uint64 __make_it_8_byte_aligned_;
171
+ /* The WASM stack. */
172
+ uint8 bottom[1];
173
+ } wasm_stack_u;
174
+ } WASMExecEnv;
175
+
176
+ #if WASM_ENABLE_MEMORY_PROFILING != 0
177
+ #define RECORD_STACK_USAGE(e, p) \
178
+ do { \
179
+ if ((e)->native_stack_top_min > (p)) { \
180
+ (e)->native_stack_top_min = (p); \
181
+ } \
182
+ } while (0)
183
+ #else
184
+ #define RECORD_STACK_USAGE(e, p) (void)0
185
+ #endif
186
+
187
+ WASMExecEnv *
188
+ wasm_exec_env_create_internal(struct WASMModuleInstanceCommon *module_inst,
189
+ uint32 stack_size);
190
+
191
+ void
192
+ wasm_exec_env_destroy_internal(WASMExecEnv *exec_env);
193
+
194
+ WASMExecEnv *
195
+ wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
196
+ uint32 stack_size);
197
+
198
+ void
199
+ wasm_exec_env_destroy(WASMExecEnv *exec_env);
200
+
201
+ static inline bool
202
+ wasm_exec_env_is_aux_stack_managed_by_runtime(WASMExecEnv *exec_env)
203
+ {
204
+ return exec_env->aux_stack_boundary != 0 || exec_env->aux_stack_bottom != 0;
205
+ }
206
+
207
+ /**
208
+ * Allocate a WASM frame from the WASM stack.
209
+ *
210
+ * @param exec_env the current execution environment
211
+ * @param size size of the WASM frame, it must be a multiple of 4
212
+ *
213
+ * @return the WASM frame if there is enough space in the stack area
214
+ * with a protection area, NULL otherwise
215
+ */
216
+ static inline void *
217
+ wasm_exec_env_alloc_wasm_frame(WASMExecEnv *exec_env, unsigned size)
218
+ {
219
+ uint8 *addr = exec_env->wasm_stack.top;
220
+
221
+ bh_assert(!(size & 3));
222
+
223
+ /* For classic interpreter, the outs area doesn't contain the const cells,
224
+ its size cannot be larger than the frame size, so here checking stack
225
+ overflow with multiplying by 2 is enough. For fast interpreter, since
226
+ the outs area contains const cells, its size may be larger than current
227
+ frame size, we should check again before putting the function arguments
228
+ into the outs area. */
229
+ if (size * 2
230
+ > (uint32)(uintptr_t)(exec_env->wasm_stack.top_boundary - addr)) {
231
+ /* WASM stack overflow. */
232
+ return NULL;
233
+ }
234
+
235
+ exec_env->wasm_stack.top += size;
236
+
237
+ #if WASM_ENABLE_MEMORY_PROFILING != 0
238
+ {
239
+ uint32 wasm_stack_used =
240
+ exec_env->wasm_stack.top - exec_env->wasm_stack.bottom;
241
+ if (wasm_stack_used > exec_env->max_wasm_stack_used)
242
+ exec_env->max_wasm_stack_used = wasm_stack_used;
243
+ }
244
+ #endif
245
+ return addr;
246
+ }
247
+
248
+ static inline void
249
+ wasm_exec_env_free_wasm_frame(WASMExecEnv *exec_env, void *prev_top)
250
+ {
251
+ bh_assert((uint8 *)prev_top >= exec_env->wasm_stack.bottom);
252
+ exec_env->wasm_stack.top = (uint8 *)prev_top;
253
+ }
254
+
255
+ /**
256
+ * Get the current WASM stack top pointer.
257
+ *
258
+ * @param exec_env the current execution environment
259
+ *
260
+ * @return the current WASM stack top pointer
261
+ */
262
+ static inline void *
263
+ wasm_exec_env_wasm_stack_top(WASMExecEnv *exec_env)
264
+ {
265
+ return exec_env->wasm_stack.top;
266
+ }
267
+
268
+ /**
269
+ * Set the current frame pointer.
270
+ *
271
+ * @param exec_env the current execution environment
272
+ * @param frame the WASM frame to be set for the current exec env
273
+ */
274
+ static inline void
275
+ wasm_exec_env_set_cur_frame(WASMExecEnv *exec_env,
276
+ struct WASMInterpFrame *frame)
277
+ {
278
+ exec_env->cur_frame = frame;
279
+ }
280
+
281
+ /**
282
+ * Get the current frame pointer.
283
+ *
284
+ * @param exec_env the current execution environment
285
+ *
286
+ * @return the current frame pointer
287
+ */
288
+ static inline struct WASMInterpFrame *
289
+ wasm_exec_env_get_cur_frame(WASMExecEnv *exec_env)
290
+ {
291
+ return exec_env->cur_frame;
292
+ }
293
+
294
+ struct WASMModuleInstanceCommon *
295
+ wasm_exec_env_get_module_inst(WASMExecEnv *exec_env);
296
+
297
+ void
298
+ wasm_exec_env_set_module_inst(
299
+ WASMExecEnv *exec_env, struct WASMModuleInstanceCommon *const module_inst);
300
+
301
+ void
302
+ wasm_exec_env_restore_module_inst(
303
+ WASMExecEnv *exec_env, struct WASMModuleInstanceCommon *const module_inst);
304
+
305
+ void
306
+ wasm_exec_env_set_thread_info(WASMExecEnv *exec_env);
307
+
308
+ #if WASM_ENABLE_THREAD_MGR != 0
309
+ void *
310
+ wasm_exec_env_get_thread_arg(WASMExecEnv *exec_env);
311
+
312
+ void
313
+ wasm_exec_env_set_thread_arg(WASMExecEnv *exec_env, void *thread_arg);
314
+ #endif
315
+
316
+ #ifdef OS_ENABLE_HW_BOUND_CHECK
317
+ void
318
+ wasm_exec_env_push_jmpbuf(WASMExecEnv *exec_env, WASMJmpBuf *jmpbuf);
319
+
320
+ WASMJmpBuf *
321
+ wasm_exec_env_pop_jmpbuf(WASMExecEnv *exec_env);
322
+ #endif
323
+
324
+ #ifdef __cplusplus
325
+ }
326
+ #endif
327
+
328
+ #endif /* end of _WASM_EXEC_ENV_H */
@@ -0,0 +1,242 @@
1
+ /*
2
+ * Copyright (C) 2024 Amazon Inc. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
+ */
5
+ #include "wasm_loader_common.h"
6
+ #include "bh_leb128.h"
7
+ #include "bh_log.h"
8
+ #if WASM_ENABLE_GC != 0
9
+ #include "../common/gc/gc_type.h"
10
+ #endif
11
+
12
+ void
13
+ wasm_loader_set_error_buf(char *error_buf, uint32 error_buf_size,
14
+ const char *string, bool is_aot)
15
+ {
16
+ if (error_buf != NULL) {
17
+ snprintf(error_buf, error_buf_size, "%s module load failed: %s",
18
+ is_aot ? "AOT" : "WASM", string);
19
+ }
20
+ }
21
+
22
+ #if WASM_ENABLE_MEMORY64 != 0
23
+ bool
24
+ check_memory64_flags_consistency(WASMModule *module, char *error_buf,
25
+ uint32 error_buf_size, bool is_aot)
26
+ {
27
+ uint32 i;
28
+ bool wasm64_flag, all_wasm64 = true, none_wasm64 = true;
29
+
30
+ for (i = 0; i < module->import_memory_count; ++i) {
31
+ wasm64_flag =
32
+ module->import_memories[i].u.memory.mem_type.flags & MEMORY64_FLAG;
33
+ all_wasm64 &= wasm64_flag;
34
+ none_wasm64 &= !wasm64_flag;
35
+ }
36
+
37
+ for (i = 0; i < module->memory_count; ++i) {
38
+ wasm64_flag = module->memories[i].flags & MEMORY64_FLAG;
39
+ all_wasm64 &= wasm64_flag;
40
+ none_wasm64 &= !wasm64_flag;
41
+ }
42
+
43
+ if (!(all_wasm64 || none_wasm64)) {
44
+ wasm_loader_set_error_buf(
45
+ error_buf, error_buf_size,
46
+ "inconsistent limits wasm64 flags for memory sections", is_aot);
47
+ return false;
48
+ }
49
+ return true;
50
+ }
51
+ #endif
52
+
53
+ bool
54
+ wasm_memory_check_flags(const uint8 mem_flag, char *error_buf,
55
+ uint32 error_buf_size, bool is_aot)
56
+ {
57
+ /* Check whether certain features indicated by mem_flag are enabled in
58
+ * runtime */
59
+ if (mem_flag > MAX_PAGE_COUNT_FLAG) {
60
+ #if WASM_ENABLE_SHARED_MEMORY == 0
61
+ if (mem_flag & SHARED_MEMORY_FLAG) {
62
+ LOG_VERBOSE("shared memory flag was found, please enable shared "
63
+ "memory, lib-pthread or lib-wasi-threads");
64
+ wasm_loader_set_error_buf(error_buf, error_buf_size,
65
+ "invalid limits flags", is_aot);
66
+ return false;
67
+ }
68
+ #endif
69
+ #if WASM_ENABLE_MEMORY64 == 0
70
+ if (mem_flag & MEMORY64_FLAG) {
71
+ LOG_VERBOSE("memory64 flag was found, please enable memory64");
72
+ wasm_loader_set_error_buf(error_buf, error_buf_size,
73
+ "invalid limits flags", is_aot);
74
+ return false;
75
+ }
76
+ #endif
77
+ }
78
+
79
+ if (mem_flag > MAX_PAGE_COUNT_FLAG + SHARED_MEMORY_FLAG + MEMORY64_FLAG) {
80
+ wasm_loader_set_error_buf(error_buf, error_buf_size,
81
+ "invalid limits flags", is_aot);
82
+ return false;
83
+ }
84
+ else if ((mem_flag & SHARED_MEMORY_FLAG)
85
+ && !(mem_flag & MAX_PAGE_COUNT_FLAG)) {
86
+ wasm_loader_set_error_buf(error_buf, error_buf_size,
87
+ "shared memory must have maximum", is_aot);
88
+ return false;
89
+ }
90
+
91
+ return true;
92
+ }
93
+
94
+ bool
95
+ wasm_table_check_flags(const uint8 table_flag, char *error_buf,
96
+ uint32 error_buf_size, bool is_aot)
97
+ {
98
+ /* Check whether certain features indicated by mem_flag are enabled in
99
+ * runtime */
100
+ if (table_flag > MAX_TABLE_SIZE_FLAG) {
101
+ if (table_flag & SHARED_TABLE_FLAG) {
102
+ wasm_loader_set_error_buf(error_buf, error_buf_size,
103
+ "tables cannot be shared", is_aot);
104
+ }
105
+ #if WASM_ENABLE_MEMORY64 == 0
106
+ if (table_flag & TABLE64_FLAG) {
107
+ wasm_loader_set_error_buf(error_buf, error_buf_size,
108
+ "invalid limits flags(table64 flag was "
109
+ "found, please enable memory64)",
110
+ is_aot);
111
+ return false;
112
+ }
113
+ #endif
114
+ }
115
+
116
+ if (table_flag > MAX_TABLE_SIZE_FLAG + TABLE64_FLAG) {
117
+ wasm_loader_set_error_buf(error_buf, error_buf_size,
118
+ "invalid limits flags", is_aot);
119
+ return false;
120
+ }
121
+
122
+ return true;
123
+ }
124
+
125
+ /*
126
+ * compare with a bigger type set in `wasm_value_type_size_internal()`,
127
+ * this function will only cover global value type, function's param
128
+ * value type and function's result value type.
129
+ *
130
+ * please feel free to add more if there are more requirements
131
+ */
132
+ bool
133
+ is_valid_value_type(uint8 type)
134
+ {
135
+ if (/* I32/I64/F32/F64, 0x7C to 0x7F */
136
+ (type >= VALUE_TYPE_F64 && type <= VALUE_TYPE_I32)
137
+ #if WASM_ENABLE_GC != 0
138
+ /* reference types, 0x65 to 0x70 */
139
+ || wasm_is_type_reftype(type)
140
+ #elif WASM_ENABLE_REF_TYPES != 0
141
+ || (type == VALUE_TYPE_FUNCREF || type == VALUE_TYPE_EXTERNREF)
142
+ #endif
143
+ #if WASM_ENABLE_SIMD != 0
144
+ || type == VALUE_TYPE_V128 /* 0x7B */
145
+ #endif
146
+ )
147
+ return true;
148
+ return false;
149
+ }
150
+
151
+ bool
152
+ is_valid_value_type_for_interpreter(uint8 value_type)
153
+ {
154
+ #if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0) \
155
+ && (WASM_ENABLE_SIMDE == 0)
156
+ /*
157
+ * Note: regardless of WASM_ENABLE_SIMD, our classic interpreters don't
158
+ * have SIMD implemented.
159
+ *
160
+ * WASM_ENABLE_SIMDE is used to control SIMD feaure in fast interpreter
161
+ */
162
+ if (value_type == VALUE_TYPE_V128)
163
+ return false;
164
+ #endif
165
+ return is_valid_value_type(value_type);
166
+ }
167
+
168
+ bool
169
+ is_valid_func_type(const WASMFuncType *func_type)
170
+ {
171
+ unsigned i;
172
+ for (i = 0;
173
+ i < (unsigned)(func_type->param_count + func_type->result_count);
174
+ i++) {
175
+ if (!is_valid_value_type(func_type->types[i]))
176
+ return false;
177
+ }
178
+
179
+ return true;
180
+ }
181
+
182
+ /*
183
+ * Indices are represented as a u32.
184
+ */
185
+ bool
186
+ is_indices_overflow(uint32 import, uint32 other, char *error_buf,
187
+ uint32 error_buf_size)
188
+ {
189
+ if (import > UINT32_MAX - other) {
190
+ snprintf(error_buf, error_buf_size,
191
+ "too many items in the index space(%" PRIu32 "+%" PRIu32 ").",
192
+ import, other);
193
+ return true;
194
+ }
195
+
196
+ return false;
197
+ }
198
+
199
+ bool
200
+ read_leb(uint8 **p_buf, const uint8 *buf_end, uint32 maxbits, bool sign,
201
+ uint64 *p_result, char *error_buf, uint32 error_buf_size)
202
+ {
203
+ size_t offset = 0;
204
+ bh_leb_read_status_t status =
205
+ bh_leb_read(*p_buf, buf_end, maxbits, sign, p_result, &offset);
206
+
207
+ switch (status) {
208
+ case BH_LEB_READ_SUCCESS:
209
+ *p_buf += offset;
210
+ return true;
211
+ case BH_LEB_READ_TOO_LONG:
212
+ wasm_loader_set_error_buf(error_buf, error_buf_size,
213
+ "integer representation too long", false);
214
+ return false;
215
+ case BH_LEB_READ_OVERFLOW:
216
+ wasm_loader_set_error_buf(error_buf, error_buf_size,
217
+ "integer too large", false);
218
+ return false;
219
+ case BH_LEB_READ_UNEXPECTED_END:
220
+ wasm_loader_set_error_buf(error_buf, error_buf_size,
221
+ "unexpected end", false);
222
+ return false;
223
+ default:
224
+ bh_assert(false);
225
+ return false;
226
+ }
227
+ }
228
+
229
+ #if WASM_ENABLE_EXTENDED_CONST_EXPR != 0
230
+ void
231
+ destroy_init_expr_recursive(InitializerExpression *expr)
232
+ {
233
+ if (expr == NULL) {
234
+ return;
235
+ }
236
+ if (is_expr_binary_op(expr->init_expr_type)) {
237
+ destroy_init_expr_recursive(expr->u.binary.l_expr);
238
+ destroy_init_expr_recursive(expr->u.binary.r_expr);
239
+ }
240
+ wasm_runtime_free(expr);
241
+ }
242
+ #endif /* end of WASM_ENABLE_EXTENDED_CONST_EXPR != 0 */
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Copyright (C) 2024 Amazon Inc. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
+ */
5
+
6
+ #ifndef _WASM_LOADER_COMMON_H
7
+ #define _WASM_LOADER_COMMON_H
8
+
9
+ #include "platform_common.h"
10
+ #include "../interpreter/wasm.h"
11
+
12
+ #ifdef __cplusplus
13
+ extern "C" {
14
+ #endif
15
+
16
+ #if WASM_ENABLE_MEMORY64 != 0
17
+ /* check consistency of memory64 flags across all memories,
18
+ * they must be either all wasm64 or all wasm32 */
19
+ bool
20
+ check_memory64_flags_consistency(WASMModule *module, char *error_buf,
21
+ uint32 error_buf_size, bool is_aot);
22
+ #endif
23
+
24
+ bool
25
+ wasm_memory_check_flags(const uint8 mem_flag, char *error_buf,
26
+ uint32 error_buf_size, bool is_aot);
27
+
28
+ bool
29
+ wasm_table_check_flags(const uint8 table_flag, char *error_buf,
30
+ uint32 error_buf_size, bool is_aot);
31
+
32
+ bool
33
+ is_valid_value_type(uint8 value_tpye);
34
+
35
+ bool
36
+ is_valid_value_type_for_interpreter(uint8 value_tpye);
37
+
38
+ bool
39
+ is_valid_func_type(const WASMFuncType *func_type);
40
+
41
+ bool
42
+ is_indices_overflow(uint32 import, uint32 other, char *error_buf,
43
+ uint32 error_buf_size);
44
+
45
+ bool
46
+ read_leb(uint8 **p_buf, const uint8 *buf_end, uint32 maxbits, bool sign,
47
+ uint64 *p_result, char *error_buf, uint32 error_buf_size);
48
+
49
+ void
50
+ wasm_loader_set_error_buf(char *error_buf, uint32 error_buf_size,
51
+ const char *string, bool is_aot);
52
+
53
+ #if WASM_ENABLE_EXTENDED_CONST_EXPR != 0
54
+ void
55
+ destroy_init_expr_recursive(InitializerExpression *expr);
56
+ #endif
57
+
58
+ #ifdef __cplusplus
59
+ }
60
+ #endif
61
+
62
+ #endif /* end of _WASM_LOADER_COMMON_H */