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,1492 @@
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_H_
7
+ #define _WASM_H_
8
+
9
+ #include "bh_platform.h"
10
+ #include "bh_hashmap.h"
11
+ #include "bh_assert.h"
12
+ #if WASM_ENABLE_GC != 0
13
+ #include "gc_export.h"
14
+ #endif
15
+
16
+ #ifdef __cplusplus
17
+ extern "C" {
18
+ #endif
19
+
20
+ /* Value Type */
21
+ #define VALUE_TYPE_I32 0x7F
22
+ #define VALUE_TYPE_I64 0X7E
23
+ #define VALUE_TYPE_F32 0x7D
24
+ #define VALUE_TYPE_F64 0x7C
25
+ #define VALUE_TYPE_V128 0x7B
26
+ #define VALUE_TYPE_FUNCREF 0x70
27
+ #define VALUE_TYPE_EXTERNREF 0x6F
28
+ #define VALUE_TYPE_VOID 0x40
29
+
30
+ /* Packed Types */
31
+ #define PACKED_TYPE_I8 0x78
32
+ #define PACKED_TYPE_I16 0x77
33
+
34
+ /* Reference Types */
35
+ #define REF_TYPE_NULLFUNCREF 0x73
36
+ #define REF_TYPE_NULLEXTERNREF 0x72
37
+ #define REF_TYPE_NULLREF 0x71
38
+ #define REF_TYPE_FUNCREF VALUE_TYPE_FUNCREF /* 0x70 */
39
+ #define REF_TYPE_EXTERNREF VALUE_TYPE_EXTERNREF /* 0x6F */
40
+ #define REF_TYPE_ANYREF 0x6E
41
+ #define REF_TYPE_EQREF 0x6D
42
+ #define REF_TYPE_I31REF 0x6C
43
+ #define REF_TYPE_STRUCTREF 0x6B
44
+ #define REF_TYPE_ARRAYREF 0x6A
45
+ #define REF_TYPE_HT_NON_NULLABLE 0x64
46
+ #define REF_TYPE_HT_NULLABLE 0x63
47
+ #define REF_TYPE_STRINGREF VALUE_TYPE_STRINGREF /* 0x67 */
48
+ #define REF_TYPE_STRINGVIEWWTF8 VALUE_TYPE_STRINGVIEWWTF8 /* 0x66 */
49
+ #define REF_TYPE_STRINGVIEWWTF16 VALUE_TYPE_STRINGVIEWWTF16 /* 0x62 */
50
+ #define REF_TYPE_STRINGVIEWITER VALUE_TYPE_STRINGVIEWITER /* 0x61 */
51
+
52
+ /* Heap Types */
53
+ #define HEAP_TYPE_NOFUNC (-0x0D)
54
+ #define HEAP_TYPE_NOEXTERN (-0x0E)
55
+ #define HEAP_TYPE_NONE (-0x0F)
56
+ #define HEAP_TYPE_FUNC (-0x10)
57
+ #define HEAP_TYPE_EXTERN (-0x11)
58
+ #define HEAP_TYPE_ANY (-0x12)
59
+ #define HEAP_TYPE_EQ (-0x13)
60
+ #define HEAP_TYPE_I31 (-0x14)
61
+ #define HEAP_TYPE_STRUCT (-0x15)
62
+ #define HEAP_TYPE_ARRAY (-0x16)
63
+ #define HEAP_TYPE_STRINGREF (-0x19)
64
+ #define HEAP_TYPE_STRINGVIEWWTF8 (-0x1A)
65
+ #define HEAP_TYPE_STRINGVIEWWTF16 (-0x1E)
66
+ #define HEAP_TYPE_STRINGVIEWITER (-0x1F)
67
+
68
+ /* Defined Types */
69
+ #define DEFINED_TYPE_FUNC 0x60
70
+ #define DEFINED_TYPE_STRUCT 0x5F
71
+ #define DEFINED_TYPE_ARRAY 0x5E
72
+ #define DEFINED_TYPE_SUB 0x50
73
+ #define DEFINED_TYPE_SUB_FINAL 0x4F
74
+ #define DEFINED_TYPE_REC 0x4E
75
+
76
+ /* Used by AOT */
77
+ #define VALUE_TYPE_I1 0x41
78
+ /**
79
+ * Used by loader to represent any type of i32/i64/f32/f64/v128
80
+ * and ref types, including funcref, externref, anyref, eqref,
81
+ * (ref null $ht), (ref $ht), i31ref, structref, arrayref,
82
+ * nullfuncref, nullexternref, nullref and stringref
83
+ */
84
+ #define VALUE_TYPE_ANY 0x42
85
+ /**
86
+ * Used by wamr compiler to represent object ref types,
87
+ * including func object ref, externref object ref,
88
+ * internal object ref, eq object ref, i31 object ref,
89
+ * struct object ref, array object ref
90
+ */
91
+ #define VALUE_TYPE_GC_REF 0x43
92
+
93
+ #define MAX_PAGE_COUNT_FLAG 0x01
94
+ #define SHARED_MEMORY_FLAG 0x02
95
+ #define MEMORY64_FLAG 0x04
96
+ #define MAX_TABLE_SIZE_FLAG 0x01
97
+ /* the shared flag for table is not actual used now */
98
+ #define SHARED_TABLE_FLAG 0x02
99
+ #define TABLE64_FLAG 0x04
100
+
101
+ /**
102
+ * In the multi-memory proposal, the memarg in loads and stores are
103
+ * reinterpreted as a bitfield, bit 6 serves as a flag indicating the presence
104
+ * of the optional memory index, if it is set, then an i32 memory index follows
105
+ * after the alignment bitfield
106
+ */
107
+ #define OPT_MEMIDX_FLAG 0x40
108
+
109
+ #define DEFAULT_NUM_BYTES_PER_PAGE 65536
110
+ #define DEFAULT_MAX_PAGES 65536
111
+ #define DEFAULT_MEM64_MAX_PAGES UINT32_MAX
112
+
113
+ /* Max size of linear memory */
114
+ #define MAX_LINEAR_MEMORY_SIZE (4 * (uint64)BH_GB)
115
+ /* Roughly 274 TB */
116
+ #define MAX_LINEAR_MEM64_MEMORY_SIZE \
117
+ (DEFAULT_MEM64_MAX_PAGES * (uint64)64 * (uint64)BH_KB)
118
+ /* Macro to check memory flag and return appropriate memory size */
119
+ #define GET_MAX_LINEAR_MEMORY_SIZE(is_memory64) \
120
+ (is_memory64 ? MAX_LINEAR_MEM64_MEMORY_SIZE : MAX_LINEAR_MEMORY_SIZE)
121
+
122
+ #if WASM_ENABLE_GC == 0
123
+ typedef uintptr_t table_elem_type_t;
124
+ #define NULL_REF (0xFFFFFFFF)
125
+ #else
126
+ typedef void *table_elem_type_t;
127
+ #define NULL_REF (NULL)
128
+ #define REF_CELL_NUM ((uint32)sizeof(uintptr_t) / sizeof(uint32))
129
+ #endif
130
+
131
+ #define INIT_EXPR_NONE 0x00
132
+ #define INIT_EXPR_TYPE_I32_CONST 0x41
133
+ #define INIT_EXPR_TYPE_I64_CONST 0x42
134
+ #define INIT_EXPR_TYPE_F32_CONST 0x43
135
+ #define INIT_EXPR_TYPE_F64_CONST 0x44
136
+ #define INIT_EXPR_TYPE_V128_CONST 0xFD
137
+ #define INIT_EXPR_TYPE_GET_GLOBAL 0x23
138
+ #define INIT_EXPR_TYPE_I32_ADD 0x6A
139
+ #define INIT_EXPR_TYPE_I32_SUB 0x6B
140
+ #define INIT_EXPR_TYPE_I32_MUL 0x6C
141
+ #define INIT_EXPR_TYPE_I64_ADD 0x7C
142
+ #define INIT_EXPR_TYPE_I64_SUB 0x7D
143
+ #define INIT_EXPR_TYPE_I64_MUL 0x7E
144
+ #define INIT_EXPR_TYPE_REFNULL_CONST 0xD0
145
+ #define INIT_EXPR_TYPE_FUNCREF_CONST 0xD2
146
+ #define INIT_EXPR_TYPE_STRUCT_NEW 0xD3
147
+ #define INIT_EXPR_TYPE_STRUCT_NEW_DEFAULT 0xD4
148
+ #define INIT_EXPR_TYPE_ARRAY_NEW 0xD5
149
+ #define INIT_EXPR_TYPE_ARRAY_NEW_DEFAULT 0xD6
150
+ #define INIT_EXPR_TYPE_ARRAY_NEW_FIXED 0xD7
151
+ #define INIT_EXPR_TYPE_I31_NEW 0xD8
152
+ #define INIT_EXPR_TYPE_ANY_CONVERT_EXTERN 0xD9
153
+ #define INIT_EXPR_TYPE_EXTERN_CONVERT_ANY 0xDA
154
+
155
+ #define WASM_MAGIC_NUMBER 0x6d736100
156
+ #define WASM_CURRENT_VERSION 1
157
+
158
+ #define SECTION_TYPE_USER 0
159
+ #define SECTION_TYPE_TYPE 1
160
+ #define SECTION_TYPE_IMPORT 2
161
+ #define SECTION_TYPE_FUNC 3
162
+ #define SECTION_TYPE_TABLE 4
163
+ #define SECTION_TYPE_MEMORY 5
164
+ #define SECTION_TYPE_GLOBAL 6
165
+ #define SECTION_TYPE_EXPORT 7
166
+ #define SECTION_TYPE_START 8
167
+ #define SECTION_TYPE_ELEM 9
168
+ #define SECTION_TYPE_CODE 10
169
+ #define SECTION_TYPE_DATA 11
170
+ #if WASM_ENABLE_BULK_MEMORY != 0
171
+ #define SECTION_TYPE_DATACOUNT 12
172
+ #endif
173
+ #if WASM_ENABLE_TAGS != 0
174
+ #define SECTION_TYPE_TAG 13
175
+ #endif
176
+ #if WASM_ENABLE_STRINGREF != 0
177
+ #define SECTION_TYPE_STRINGREF 14
178
+ #endif
179
+
180
+ #define SUB_SECTION_TYPE_MODULE 0
181
+ #define SUB_SECTION_TYPE_FUNC 1
182
+ #define SUB_SECTION_TYPE_LOCAL 2
183
+
184
+ #define IMPORT_KIND_FUNC 0
185
+ #define IMPORT_KIND_TABLE 1
186
+ #define IMPORT_KIND_MEMORY 2
187
+ #define IMPORT_KIND_GLOBAL 3
188
+ #if WASM_ENABLE_TAGS != 0
189
+ #define IMPORT_KIND_TAG 4
190
+ #endif
191
+
192
+ #define EXPORT_KIND_FUNC 0
193
+ #define EXPORT_KIND_TABLE 1
194
+ #define EXPORT_KIND_MEMORY 2
195
+ #define EXPORT_KIND_GLOBAL 3
196
+ #if WASM_ENABLE_TAGS != 0
197
+ #define EXPORT_KIND_TAG 4
198
+ #endif
199
+
200
+ #define LABEL_TYPE_BLOCK 0
201
+ #define LABEL_TYPE_LOOP 1
202
+ #define LABEL_TYPE_IF 2
203
+ #define LABEL_TYPE_FUNCTION 3
204
+ #if WASM_ENABLE_EXCE_HANDLING != 0
205
+ #define LABEL_TYPE_TRY 4
206
+ #define LABEL_TYPE_CATCH 5
207
+ #define LABEL_TYPE_CATCH_ALL 6
208
+ #endif
209
+
210
+ #define WASM_TYPE_FUNC 0
211
+ #define WASM_TYPE_STRUCT 1
212
+ #define WASM_TYPE_ARRAY 2
213
+
214
+ #if WASM_ENABLE_STRINGREF != 0
215
+ #define WASM_TYPE_STRINGREF 3
216
+ #define WASM_TYPE_STRINGVIEWWTF8 4
217
+ #define WASM_TYPE_STRINGVIEWWTF16 5
218
+ #define WASM_TYPE_STRINGVIEWITER 6
219
+ #endif
220
+
221
+ /* In WasmGC, a table can start with [0x40 0x00] to indicate it has an
222
+ * initializer */
223
+ #define TABLE_INIT_EXPR_FLAG 0x40
224
+
225
+ typedef struct WASMModule WASMModule;
226
+ typedef struct WASMFunction WASMFunction;
227
+ typedef struct WASMGlobal WASMGlobal;
228
+ #if WASM_ENABLE_TAGS != 0
229
+ typedef struct WASMTag WASMTag;
230
+ #endif
231
+
232
+ #ifndef WASM_VALUE_DEFINED
233
+ #define WASM_VALUE_DEFINED
234
+
235
+ typedef union V128 {
236
+ int8 i8x16[16];
237
+ int16 i16x8[8];
238
+ int32 i32x4[4];
239
+ int64 i64x2[2];
240
+ float32 f32x4[4];
241
+ float64 f64x2[2];
242
+ } V128;
243
+
244
+ typedef union WASMValue {
245
+ int32 i32;
246
+ uint32 u32;
247
+ uint32 global_index;
248
+ uint32 ref_index;
249
+ int64 i64;
250
+ uint64 u64;
251
+ float32 f32;
252
+ float64 f64;
253
+ V128 v128;
254
+ #if WASM_ENABLE_GC != 0
255
+ wasm_obj_t gc_obj;
256
+ uint32 type_index;
257
+ struct {
258
+ uint32 type_index;
259
+ uint32 length;
260
+ } array_new_default;
261
+ /* pointer to a memory space holding more data, current usage:
262
+ * struct.new init value: WASMStructNewInitValues *
263
+ * array.new init value: WASMArrayNewInitValues *
264
+ */
265
+ void *data;
266
+ #endif
267
+ } WASMValue;
268
+ #endif /* end of WASM_VALUE_DEFINED */
269
+
270
+ typedef struct WASMStructNewInitValues {
271
+ uint32 type_idx;
272
+ uint32 count;
273
+ WASMValue fields[1];
274
+ } WASMStructNewInitValues;
275
+
276
+ typedef struct WASMArrayNewInitValues {
277
+ uint32 type_idx;
278
+ uint32 length;
279
+ WASMValue elem_data[1];
280
+ } WASMArrayNewInitValues;
281
+
282
+ typedef struct InitializerExpression {
283
+ /* type of INIT_EXPR_TYPE_XXX, which is an instruction of
284
+ constant expression */
285
+ uint8 init_expr_type;
286
+ union {
287
+ struct {
288
+ WASMValue v;
289
+ } unary;
290
+ struct {
291
+ struct InitializerExpression *l_expr;
292
+ struct InitializerExpression *r_expr;
293
+ } binary;
294
+ } u;
295
+ } InitializerExpression;
296
+
297
+ static inline bool
298
+ is_expr_binary_op(uint8 flag)
299
+ {
300
+ return flag == INIT_EXPR_TYPE_I32_ADD || flag == INIT_EXPR_TYPE_I32_SUB
301
+ || flag == INIT_EXPR_TYPE_I32_MUL || flag == INIT_EXPR_TYPE_I64_ADD
302
+ || flag == INIT_EXPR_TYPE_I64_SUB || flag == INIT_EXPR_TYPE_I64_MUL;
303
+ }
304
+
305
+ /* check if table or data offset is valid for i32 offset */
306
+ static inline bool
307
+ is_valid_i32_offset(uint8 flag)
308
+ {
309
+ return flag == INIT_EXPR_TYPE_I32_CONST || flag == INIT_EXPR_TYPE_I32_ADD
310
+ || flag == INIT_EXPR_TYPE_I32_SUB || flag == INIT_EXPR_TYPE_I32_MUL;
311
+ }
312
+
313
+ /* check if table or data offset is valid for i64 offset */
314
+ static inline bool
315
+ is_valid_i64_offset(uint8 flag)
316
+ {
317
+ return flag == INIT_EXPR_TYPE_I64_CONST || flag == INIT_EXPR_TYPE_I64_ADD
318
+ || flag == INIT_EXPR_TYPE_I64_SUB || flag == INIT_EXPR_TYPE_I64_MUL;
319
+ }
320
+
321
+ #if WASM_ENABLE_GC != 0
322
+ /**
323
+ * Reference type of (ref null ht) or (ref ht),
324
+ * and heap type is defined type (type i), i >= 0
325
+ */
326
+ typedef struct RefHeapType_TypeIdx {
327
+ /* ref_type is REF_TYPE_HT_NULLABLE or
328
+ REF_TYPE_HT_NON_NULLABLE, (0x63 or 0x64) */
329
+ uint8 ref_type;
330
+ /* true if ref_type is REF_TYPE_HT_NULLABLE */
331
+ bool nullable;
332
+ /* heap type is defined type: type_index >= 0 */
333
+ int32 type_idx;
334
+ } RefHeapType_TypeIdx;
335
+
336
+ /**
337
+ * Reference type of (ref null ht) or (ref ht),
338
+ * and heap type is non-defined type
339
+ */
340
+ typedef struct RefHeapType_Common {
341
+ /* ref_type is REF_TYPE_HT_NULLABLE or
342
+ REF_TYPE_HT_NON_NULLABLE (0x63 or 0x64) */
343
+ uint8 ref_type;
344
+ /* true if ref_type is REF_TYPE_HT_NULLABLE */
345
+ bool nullable;
346
+ /* Common heap type (not defined type):
347
+ -0x10 (func), -0x11 (extern), -0x12 (any), -0x13 (eq),
348
+ -0x16 (i31), -0x17 (nofunc), -0x18 (noextern),
349
+ -0x19 (struct), -0x20 (array), -0x21 (none) */
350
+ int32 heap_type;
351
+ } RefHeapType_Common;
352
+
353
+ /**
354
+ * Reference type
355
+ */
356
+ typedef union WASMRefType {
357
+ uint8 ref_type;
358
+ RefHeapType_TypeIdx ref_ht_typeidx;
359
+ RefHeapType_Common ref_ht_common;
360
+ } WASMRefType;
361
+
362
+ typedef struct WASMRefTypeMap {
363
+ /**
364
+ * The type index of a type array, which only stores
365
+ * the first byte of the type, e.g. WASMFuncType.types,
366
+ * WASMStructType.fields
367
+ */
368
+ uint16 index;
369
+ /* The full type info if the type cannot be described
370
+ with one byte */
371
+ WASMRefType *ref_type;
372
+ } WASMRefTypeMap;
373
+ #endif /* end of WASM_ENABLE_GC */
374
+
375
+ #if WASM_ENABLE_GC == 0
376
+ typedef struct WASMFuncType WASMType;
377
+ typedef WASMType *WASMTypePtr;
378
+ #else
379
+ /**
380
+ * Common type, store the same fields of
381
+ * WASMFuncType, WASMStructType and WASMArrayType
382
+ */
383
+ typedef struct WASMType {
384
+ /**
385
+ * type_flag must be WASM_TYPE_FUNC/STRUCT/ARRAY to
386
+ * denote that it is a WASMFuncType, WASMStructType or
387
+ * WASMArrayType
388
+ */
389
+ uint16 type_flag;
390
+
391
+ bool is_sub_final;
392
+ /* How many types are referring to this type */
393
+ uint16 ref_count;
394
+ /* The inheritance depth */
395
+ uint16 inherit_depth;
396
+ /* The root type */
397
+ struct WASMType *root_type;
398
+ /* The parent type */
399
+ struct WASMType *parent_type;
400
+ uint32 parent_type_idx;
401
+
402
+ /* The number of internal types in the current rec group, and if
403
+ the type is not in a recursive group, rec_count is 1 since a
404
+ single type definition is reinterpreted as a short-hand for a
405
+ recursive group containing just one type */
406
+ uint16 rec_count;
407
+ uint16 rec_idx;
408
+ /* The index of the begin type of this group */
409
+ uint32 rec_begin_type_idx;
410
+ } WASMType, *WASMTypePtr;
411
+ #endif /* end of WASM_ENABLE_GC */
412
+
413
+ /* Function type */
414
+ typedef struct WASMFuncType {
415
+ #if WASM_ENABLE_GC != 0
416
+ WASMType base_type;
417
+ #endif
418
+
419
+ uint16 param_count;
420
+ uint16 result_count;
421
+ uint16 param_cell_num;
422
+ uint16 ret_cell_num;
423
+
424
+ #if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
425
+ && WASM_ENABLE_LAZY_JIT != 0
426
+ /* Code block to call llvm jit functions of this
427
+ kind of function type from fast jit jitted code */
428
+ void *call_to_llvm_jit_from_fast_jit;
429
+ #endif
430
+
431
+ #if WASM_ENABLE_GC != 0
432
+ uint16 ref_type_map_count;
433
+ WASMRefTypeMap *ref_type_maps;
434
+ WASMRefTypeMap *result_ref_type_maps;
435
+ #else
436
+ uint16 ref_count;
437
+ #endif
438
+
439
+ #if WASM_ENABLE_QUICK_AOT_ENTRY != 0
440
+ /* Quick AOT/JIT entry of this func type */
441
+ void *quick_aot_entry;
442
+ #endif
443
+
444
+ /* types of params and results, only store the first byte
445
+ * of the type, if it cannot be described with one byte,
446
+ * then the full type info is stored in ref_type_maps */
447
+ uint8 types[1];
448
+ } WASMFuncType;
449
+
450
+ #if WASM_ENABLE_GC != 0
451
+ typedef struct WASMStructFieldType {
452
+ uint16 field_flags;
453
+ uint8 field_type;
454
+ uint8 field_size;
455
+ uint32 field_offset;
456
+ #if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
457
+ /*
458
+ * The field size and field offset of a wasm struct may vary
459
+ * in 32-bit target and 64-bit target, e.g., the size of a
460
+ * GC reference is 4 bytes in the former and 8 bytes in the
461
+ * latter, the AOT compiler needs to use the correct field
462
+ * offset according to the target info.
463
+ */
464
+ uint8 field_size_64bit;
465
+ uint8 field_size_32bit;
466
+ uint32 field_offset_64bit;
467
+ uint32 field_offset_32bit;
468
+ #endif
469
+ } WASMStructFieldType;
470
+
471
+ typedef struct WASMStructType {
472
+ WASMType base_type;
473
+
474
+ /* total size of this struct object */
475
+ uint32 total_size;
476
+ uint16 field_count;
477
+
478
+ uint16 ref_type_map_count;
479
+ WASMRefTypeMap *ref_type_maps;
480
+
481
+ /* Offsets of reference fields that need to be traced during GC.
482
+ The first element of the table is the number of such offsets. */
483
+ uint16 *reference_table;
484
+
485
+ /* Field info, note that fields[i]->field_type only stores
486
+ * the first byte of the field type, if it cannot be described
487
+ * with one byte, then the full field type info is stored in
488
+ * ref_type_maps */
489
+ WASMStructFieldType fields[1];
490
+ } WASMStructType;
491
+
492
+ typedef struct WASMArrayType {
493
+ WASMType base_type;
494
+
495
+ uint16 elem_flags;
496
+ uint8 elem_type;
497
+ /* The full elem type info if the elem type cannot be
498
+ described with one byte */
499
+ WASMRefType *elem_ref_type;
500
+ } WASMArrayType;
501
+
502
+ #if WASM_ENABLE_STRINGREF != 0
503
+ /* stringref representation, we define it as a void * pointer here, the
504
+ * stringref implementation can use any structure */
505
+ /*
506
+ WasmGC heap
507
+ +-----------------------+
508
+ | |
509
+ | stringref |
510
+ | +----------+ | external string representation
511
+ | | host_ptr |--------o------+----->+------------+
512
+ | +----------+ | | | |
513
+ | | | +------------+
514
+ | stringview_wtf8/16 | |
515
+ | +----------+ | |
516
+ | | host_ptr |--------o------+
517
+ | +----------+ | |
518
+ | | |
519
+ | stringview_iter | |
520
+ | +----------+ | |
521
+ | | host_ptr |--------o------+
522
+ | +----------+ |
523
+ | | pos | |
524
+ | +----------+ |
525
+ | |
526
+ +-----------------------+
527
+ */
528
+ typedef void *WASMString;
529
+
530
+ #endif /* end of WASM_ENABLE_STRINGREF != 0 */
531
+ #endif /* end of WASM_ENABLE_GC != 0 */
532
+
533
+ typedef struct WASMTableType {
534
+ uint8 elem_type;
535
+ /**
536
+ * 0: no max size and not shared
537
+ * 1: has max size
538
+ * 2: shared
539
+ * 4: table64
540
+ */
541
+ uint8 flags;
542
+ bool possible_grow;
543
+ uint32 init_size;
544
+ /* specified if (flags & 1), else it is 0x10000 */
545
+ uint32 max_size;
546
+ #if WASM_ENABLE_GC != 0
547
+ WASMRefType *elem_ref_type;
548
+ #endif
549
+ } WASMTableType;
550
+
551
+ typedef struct WASMTable {
552
+ WASMTableType table_type;
553
+ #if WASM_ENABLE_GC != 0
554
+ /* init expr for the whole table */
555
+ InitializerExpression init_expr;
556
+ #endif
557
+ } WASMTable;
558
+
559
+ #if WASM_ENABLE_MEMORY64 != 0
560
+ typedef uint64 mem_offset_t;
561
+ #define PR_MEM_OFFSET PRIu64
562
+ #else
563
+ typedef uint32 mem_offset_t;
564
+ #define PR_MEM_OFFSET PRIu32
565
+ #endif
566
+ typedef mem_offset_t tbl_elem_idx_t;
567
+
568
+ typedef struct WASMMemory {
569
+ uint32 flags;
570
+ uint32 num_bytes_per_page;
571
+ uint32 init_page_count;
572
+ uint32 max_page_count;
573
+ } WASMMemory;
574
+ #ifndef WASM_MEMORY_T_DEFINED
575
+ #define WASM_MEMORY_T_DEFINED
576
+ typedef struct WASMMemory WASMMemoryType;
577
+ #endif
578
+
579
+ typedef struct WASMTableImport {
580
+ char *module_name;
581
+ char *field_name;
582
+ WASMTableType table_type;
583
+ #if WASM_ENABLE_MULTI_MODULE != 0
584
+ WASMModule *import_module;
585
+ WASMTable *import_table_linked;
586
+ #endif
587
+ } WASMTableImport;
588
+
589
+ typedef struct WASMMemoryImport {
590
+ char *module_name;
591
+ char *field_name;
592
+ WASMMemoryType mem_type;
593
+ #if WASM_ENABLE_MULTI_MODULE != 0
594
+ WASMModule *import_module;
595
+ WASMMemory *import_memory_linked;
596
+ #endif
597
+ } WASMMemoryImport;
598
+
599
+ typedef struct WASMFunctionImport {
600
+ char *module_name;
601
+ char *field_name;
602
+ /* function type */
603
+ WASMFuncType *func_type;
604
+ /* native function pointer after linked */
605
+ void *func_ptr_linked;
606
+ /* signature from registered native symbols */
607
+ const char *signature;
608
+ /* attachment */
609
+ void *attachment;
610
+ #if WASM_ENABLE_GC != 0
611
+ /* the type index of this function's func_type */
612
+ uint32 type_idx;
613
+ #endif
614
+ bool call_conv_raw;
615
+ bool call_conv_wasm_c_api;
616
+ #if WASM_ENABLE_MULTI_MODULE != 0
617
+ WASMModule *import_module;
618
+ WASMFunction *import_func_linked;
619
+ #endif
620
+ } WASMFunctionImport;
621
+
622
+ #if WASM_ENABLE_TAGS != 0
623
+ typedef struct WASMTagImport {
624
+ char *module_name;
625
+ char *field_name;
626
+ uint8 attribute; /* the type of the tag (numerical) */
627
+ uint32 type; /* the type of the catch function (numerical)*/
628
+ WASMFuncType *tag_type;
629
+ void *tag_ptr_linked;
630
+
631
+ #if WASM_ENABLE_MULTI_MODULE != 0
632
+ /* imported tag pointer after linked */
633
+ WASMModule *import_module;
634
+ WASMTag *import_tag_linked;
635
+ uint32 import_tag_index_linked;
636
+ #endif
637
+ } WASMTagImport;
638
+ #endif
639
+
640
+ typedef struct WASMGlobalType {
641
+ uint8 val_type;
642
+ bool is_mutable;
643
+ } WASMGlobalType;
644
+
645
+ typedef struct WASMGlobalImport {
646
+ char *module_name;
647
+ char *field_name;
648
+ WASMGlobalType type;
649
+ bool is_linked;
650
+ /* global data after linked */
651
+ WASMValue global_data_linked;
652
+ #if WASM_ENABLE_GC != 0
653
+ WASMRefType *ref_type;
654
+ #endif
655
+ #if WASM_ENABLE_MULTI_MODULE != 0
656
+ /* imported function pointer after linked */
657
+ /* TODO: remove if not needed */
658
+ WASMModule *import_module;
659
+ WASMGlobal *import_global_linked;
660
+ #endif
661
+ #if WASM_ENABLE_FAST_JIT != 0
662
+ /* The data offset of current global in global data */
663
+ uint32 data_offset;
664
+ #endif
665
+ } WASMGlobalImport;
666
+
667
+ typedef struct WASMImport {
668
+ uint8 kind;
669
+ union {
670
+ WASMFunctionImport function;
671
+ WASMTableImport table;
672
+ WASMMemoryImport memory;
673
+ #if WASM_ENABLE_TAGS != 0
674
+ WASMTagImport tag;
675
+ #endif
676
+ WASMGlobalImport global;
677
+ struct {
678
+ char *module_name;
679
+ char *field_name;
680
+ } names;
681
+ } u;
682
+ } WASMImport;
683
+
684
+ struct WASMFunction {
685
+ #if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
686
+ char *field_name;
687
+ #endif
688
+ /* the type of function */
689
+ WASMFuncType *func_type;
690
+ uint32 local_count;
691
+ uint8 *local_types;
692
+ #if WASM_ENABLE_GC != 0
693
+ uint16 local_ref_type_map_count;
694
+ WASMRefTypeMap *local_ref_type_maps;
695
+ #endif
696
+
697
+ /* cell num of parameters */
698
+ uint16 param_cell_num;
699
+ /* cell num of return type */
700
+ uint16 ret_cell_num;
701
+ /* cell num of local variables */
702
+ uint16 local_cell_num;
703
+ /* offset of each local, including function parameters
704
+ and local variables */
705
+ uint16 *local_offsets;
706
+
707
+ uint32 max_stack_cell_num;
708
+ uint32 max_block_num;
709
+ uint32 code_size;
710
+ uint8 *code;
711
+ #if WASM_ENABLE_FAST_INTERP != 0
712
+ uint32 code_compiled_size;
713
+ uint8 *code_compiled;
714
+ uint8 *consts;
715
+ uint32 const_cell_num;
716
+ #endif
717
+
718
+ #if WASM_ENABLE_GC != 0
719
+ /* the type index of this function's func_type */
720
+ uint32 type_idx;
721
+ #endif
722
+
723
+ #if WASM_ENABLE_EXCE_HANDLING != 0
724
+ uint32 exception_handler_count;
725
+ #endif
726
+
727
+ #if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 \
728
+ || WASM_ENABLE_WAMR_COMPILER != 0
729
+ /* Whether function has opcode memory.grow */
730
+ bool has_op_memory_grow;
731
+ /* Whether function has opcode call or call_indirect */
732
+ bool has_op_func_call;
733
+ #endif
734
+ #if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0
735
+ /* Whether function has memory operation opcodes */
736
+ bool has_memory_operations;
737
+ /* Whether function has opcode call_indirect */
738
+ bool has_op_call_indirect;
739
+ /* Whether function has opcode set_global_aux_stack */
740
+ bool has_op_set_global_aux_stack;
741
+ #endif
742
+
743
+ #if WASM_ENABLE_FAST_JIT != 0
744
+ /* The compiled fast jit jitted code block of this function */
745
+ void *fast_jit_jitted_code;
746
+ #if WASM_ENABLE_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0
747
+ /* The compiled llvm jit func ptr of this function */
748
+ void *llvm_jit_func_ptr;
749
+ /* Code block to call fast jit jitted code of this function
750
+ from the llvm jit jitted code */
751
+ void *call_to_fast_jit_from_llvm_jit;
752
+ #endif
753
+ #endif
754
+ };
755
+
756
+ #if WASM_ENABLE_TAGS != 0
757
+ struct WASMTag {
758
+ uint8 attribute; /* the attribute property of the tag (expected to be 0) */
759
+ uint32 type; /* the type of the tag (expected valid inden in type table) */
760
+ WASMFuncType *tag_type;
761
+ };
762
+ #endif
763
+
764
+ struct WASMGlobal {
765
+ WASMGlobalType type;
766
+ #if WASM_ENABLE_GC != 0
767
+ WASMRefType *ref_type;
768
+ #endif
769
+ InitializerExpression init_expr;
770
+ #if WASM_ENABLE_FAST_JIT != 0
771
+ /* The data offset of current global in global data */
772
+ uint32 data_offset;
773
+ #endif
774
+ };
775
+
776
+ typedef struct WASMExport {
777
+ char *name;
778
+ uint8 kind;
779
+ uint32 index;
780
+ } WASMExport;
781
+
782
+ typedef struct WASMTableSeg {
783
+ /* 0 to 7 */
784
+ uint32 mode;
785
+ /* funcref or externref, elemkind will be considered as funcref */
786
+ uint32 elem_type;
787
+ #if WASM_ENABLE_GC != 0
788
+ WASMRefType *elem_ref_type;
789
+ #endif
790
+ /* optional, only for active */
791
+ uint32 table_index;
792
+ InitializerExpression base_offset;
793
+ uint32 value_count;
794
+ InitializerExpression *init_values;
795
+ } WASMTableSeg;
796
+
797
+ typedef struct WASMDataSeg {
798
+ uint32 memory_index;
799
+ InitializerExpression base_offset;
800
+ uint32 data_length;
801
+ #if WASM_ENABLE_BULK_MEMORY != 0
802
+ bool is_passive;
803
+ #endif
804
+ uint8 *data;
805
+ bool is_data_cloned;
806
+ } WASMDataSeg;
807
+
808
+ typedef struct BlockAddr {
809
+ const uint8 *start_addr;
810
+ uint8 *else_addr;
811
+ uint8 *end_addr;
812
+ } BlockAddr;
813
+
814
+ #if WASM_ENABLE_LIBC_WASI != 0
815
+ typedef struct WASIArguments {
816
+ const char **dir_list;
817
+ uint32 dir_count;
818
+ const char **map_dir_list;
819
+ uint32 map_dir_count;
820
+ const char **env;
821
+ uint32 env_count;
822
+ /* in CIDR notation */
823
+ const char **addr_pool;
824
+ uint32 addr_count;
825
+ const char **ns_lookup_pool;
826
+ uint32 ns_lookup_count;
827
+ char **argv;
828
+ uint32 argc;
829
+ os_raw_file_handle stdio[3];
830
+ } WASIArguments;
831
+ #endif
832
+
833
+ typedef struct StringNode {
834
+ struct StringNode *next;
835
+ char *str;
836
+ } StringNode, *StringList;
837
+
838
+ typedef struct BrTableCache {
839
+ struct BrTableCache *next;
840
+ /* Address of br_table opcode */
841
+ uint8 *br_table_op_addr;
842
+ uint32 br_count;
843
+ uint32 br_depths[1];
844
+ } BrTableCache;
845
+
846
+ #if WASM_ENABLE_DEBUG_INTERP != 0
847
+ typedef struct WASMFastOPCodeNode {
848
+ struct WASMFastOPCodeNode *next;
849
+ uint64 offset;
850
+ uint8 orig_op;
851
+ } WASMFastOPCodeNode;
852
+ #endif
853
+
854
+ #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
855
+ typedef struct WASMCustomSection {
856
+ struct WASMCustomSection *next;
857
+ /* Start address of the section name */
858
+ char *name_addr;
859
+ /* Length of the section name decoded from leb */
860
+ uint32 name_len;
861
+ /* Start address of the content (name len and name skipped) */
862
+ uint8 *content_addr;
863
+ uint32 content_len;
864
+ } WASMCustomSection;
865
+ #endif
866
+
867
+ #if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0
868
+ struct AOTCompData;
869
+ struct AOTCompContext;
870
+
871
+ /* Orc JIT thread arguments */
872
+ typedef struct OrcJitThreadArg {
873
+ #if WASM_ENABLE_JIT != 0
874
+ struct AOTCompContext *comp_ctx;
875
+ #endif
876
+ struct WASMModule *module;
877
+ uint32 group_idx;
878
+ } OrcJitThreadArg;
879
+ #endif
880
+
881
+ struct WASMModuleInstance;
882
+
883
+ struct WASMModule {
884
+ /* Module type, for module loaded from WASM bytecode binary,
885
+ this field is Wasm_Module_Bytecode;
886
+ for module loaded from AOT file, this field is
887
+ Wasm_Module_AoT, and this structure should be treated as
888
+ AOTModule structure. */
889
+ uint32 module_type;
890
+
891
+ /* the package version read from the WASM file */
892
+ uint32 package_version;
893
+
894
+ uint32 type_count;
895
+ uint32 import_count;
896
+ uint32 function_count;
897
+ uint32 table_count;
898
+ uint32 memory_count;
899
+ #if WASM_ENABLE_TAGS != 0
900
+ uint32 tag_count;
901
+ #endif
902
+ uint32 global_count;
903
+ uint32 export_count;
904
+ uint32 table_seg_count;
905
+ /* data seg count read from data segment section */
906
+ uint32 data_seg_count;
907
+ #if WASM_ENABLE_BULK_MEMORY != 0
908
+ /* data count read from datacount section */
909
+ uint32 data_seg_count1;
910
+ #endif
911
+ #if WASM_ENABLE_GC != 0
912
+ #if WASM_ENABLE_STRINGREF != 0
913
+ uint32 string_literal_count;
914
+ uint32 *string_literal_lengths;
915
+ const uint8 **string_literal_ptrs;
916
+ #endif
917
+ #endif
918
+
919
+ uint32 import_function_count;
920
+ uint32 import_table_count;
921
+ uint32 import_memory_count;
922
+ #if WASM_ENABLE_TAGS != 0
923
+ uint32 import_tag_count;
924
+ #endif
925
+ uint32 import_global_count;
926
+
927
+ WASMImport *import_functions;
928
+ WASMImport *import_tables;
929
+ WASMImport *import_memories;
930
+ #if WASM_ENABLE_TAGS != 0
931
+ WASMImport *import_tags;
932
+ #endif
933
+ WASMImport *import_globals;
934
+
935
+ WASMType **types;
936
+ WASMImport *imports;
937
+ WASMFunction **functions;
938
+ WASMTable *tables;
939
+ WASMMemory *memories;
940
+ #if WASM_ENABLE_TAGS != 0
941
+ WASMTag **tags;
942
+ #endif
943
+ WASMGlobal *globals;
944
+ WASMExport *exports;
945
+ WASMTableSeg *table_segments;
946
+ WASMDataSeg **data_segments;
947
+ uint32 start_function;
948
+
949
+ /* total global variable size */
950
+ uint32 global_data_size;
951
+
952
+ /* the index of auxiliary __data_end global,
953
+ -1 means unexported */
954
+ uint32 aux_data_end_global_index;
955
+ /* auxiliary __data_end exported by wasm app */
956
+ uint64 aux_data_end;
957
+
958
+ /* the index of auxiliary __heap_base global,
959
+ -1 means unexported */
960
+ uint32 aux_heap_base_global_index;
961
+ /* auxiliary __heap_base exported by wasm app */
962
+ uint64 aux_heap_base;
963
+
964
+ /* the index of auxiliary stack top global,
965
+ -1 means unexported */
966
+ uint32 aux_stack_top_global_index;
967
+ /* auxiliary stack bottom resolved */
968
+ uint64 aux_stack_bottom;
969
+ /* auxiliary stack size resolved */
970
+ uint32 aux_stack_size;
971
+
972
+ /* the index of malloc/free function,
973
+ -1 means unexported */
974
+ uint32 malloc_function;
975
+ uint32 free_function;
976
+
977
+ /* the index of __retain function,
978
+ -1 means unexported */
979
+ uint32 retain_function;
980
+
981
+ /* Whether there is possible memory grow, e.g. memory.grow opcode */
982
+ bool possible_memory_grow;
983
+
984
+ StringList const_str_list;
985
+ #if WASM_ENABLE_FAST_INTERP == 0
986
+ bh_list br_table_cache_list_head;
987
+ bh_list *br_table_cache_list;
988
+ #endif
989
+
990
+ #if WASM_ENABLE_LIBC_WASI != 0
991
+ WASIArguments wasi_args;
992
+ bool import_wasi_api;
993
+ #endif
994
+
995
+ #if WASM_ENABLE_MULTI_MODULE != 0
996
+ /* TODO: add mutex for mutli-thread? */
997
+ bh_list import_module_list_head;
998
+ bh_list *import_module_list;
999
+ #endif
1000
+
1001
+ #if WASM_ENABLE_GC != 0
1002
+ /* Ref types hash set */
1003
+ HashMap *ref_type_set;
1004
+ struct WASMRttType **rtt_types;
1005
+ korp_mutex rtt_type_lock;
1006
+ #if WASM_ENABLE_STRINGREF != 0
1007
+ /* special rtts for stringref types
1008
+ - stringref
1009
+ - stringview_wtf8
1010
+ - stringview_wtf16
1011
+ - stringview_iter
1012
+ */
1013
+ struct WASMRttType *stringref_rtts[4];
1014
+ #endif
1015
+ #endif
1016
+
1017
+ #if WASM_ENABLE_DEBUG_INTERP != 0 || WASM_ENABLE_DEBUG_AOT != 0
1018
+ bh_list fast_opcode_list;
1019
+ uint8 *buf_code;
1020
+ uint64 buf_code_size;
1021
+ #endif
1022
+
1023
+ #if WASM_ENABLE_DEBUG_INTERP != 0 || WASM_ENABLE_FAST_JIT != 0 \
1024
+ || WASM_ENABLE_DUMP_CALL_STACK != 0 || WASM_ENABLE_JIT != 0 \
1025
+ || WASM_ENABLE_WAMR_COMPILER != 0
1026
+ uint8 *load_addr;
1027
+ uint64 load_size;
1028
+ #endif
1029
+
1030
+ #if WASM_ENABLE_DEBUG_INTERP != 0 \
1031
+ || (WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
1032
+ && WASM_ENABLE_LAZY_JIT != 0)
1033
+ /**
1034
+ * List of instances referred to this module. When source debugging
1035
+ * feature is enabled, the debugger may modify the code section of
1036
+ * the module, so we need to report a warning if user create several
1037
+ * instances based on the same module.
1038
+ *
1039
+ * Also add the instance to the list for Fast JIT to LLVM JIT
1040
+ * tier-up, since we need to lazily update the LLVM func pointers
1041
+ * in the instance.
1042
+ */
1043
+ struct WASMModuleInstance *instance_list;
1044
+ korp_mutex instance_list_lock;
1045
+ #endif
1046
+
1047
+ #if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
1048
+ const uint8 *name_section_buf;
1049
+ const uint8 *name_section_buf_end;
1050
+ #endif
1051
+
1052
+ #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
1053
+ WASMCustomSection *custom_section_list;
1054
+ #endif
1055
+
1056
+ #if WASM_ENABLE_FAST_JIT != 0
1057
+ /**
1058
+ * func pointers of Fast JITed (un-imported) functions
1059
+ * for non Multi-Tier JIT mode:
1060
+ * (1) when lazy jit is disabled, each pointer is set to the compiled
1061
+ * fast jit jitted code
1062
+ * (2) when lazy jit is enabled, each pointer is firstly inited as
1063
+ * jit_global->compile_fast_jit_and_then_call, and then set to the
1064
+ * compiled fast jit jitted code when it is called (the stub will
1065
+ * compile the jit function and then update itself)
1066
+ * for Multi-Tier JIT mode:
1067
+ * each pointer is firstly inited as compile_fast_jit_and_then_call,
1068
+ * and then set to the compiled fast jit jitted code when it is called,
1069
+ * and when the llvm jit func ptr of the same function is compiled, it
1070
+ * will be set to call_to_llvm_jit_from_fast_jit of this function type
1071
+ * (tier-up from fast-jit to llvm-jit)
1072
+ */
1073
+ void **fast_jit_func_ptrs;
1074
+ /* locks for Fast JIT lazy compilation */
1075
+ korp_mutex fast_jit_thread_locks[WASM_ORC_JIT_BACKEND_THREAD_NUM];
1076
+ bool fast_jit_thread_locks_inited[WASM_ORC_JIT_BACKEND_THREAD_NUM];
1077
+ #endif
1078
+
1079
+ #if WASM_ENABLE_JIT != 0
1080
+ struct AOTCompData *comp_data;
1081
+ struct AOTCompContext *comp_ctx;
1082
+ /**
1083
+ * func pointers of LLVM JITed (un-imported) functions
1084
+ * for non Multi-Tier JIT mode:
1085
+ * each pointer is set to the looked up llvm jit func ptr, note that it
1086
+ * is a stub and will trigger the actual compilation when it is called
1087
+ * for Multi-Tier JIT mode:
1088
+ * each pointer is inited as call_to_fast_jit code block, when the llvm
1089
+ * jit func ptr is actually compiled, it is set to the compiled llvm jit
1090
+ * func ptr
1091
+ */
1092
+ void **func_ptrs;
1093
+ /* whether the func pointers are compiled */
1094
+ bool *func_ptrs_compiled;
1095
+ #endif
1096
+
1097
+ #if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0
1098
+ /* backend compilation threads */
1099
+ korp_tid orcjit_threads[WASM_ORC_JIT_BACKEND_THREAD_NUM];
1100
+ /* backend thread arguments */
1101
+ OrcJitThreadArg orcjit_thread_args[WASM_ORC_JIT_BACKEND_THREAD_NUM];
1102
+ /* whether to stop the compilation of backend threads */
1103
+ bool orcjit_stop_compiling;
1104
+ #endif
1105
+
1106
+ #if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
1107
+ && WASM_ENABLE_LAZY_JIT != 0
1108
+ /* wait lock/cond for the synchronization of
1109
+ the llvm jit initialization */
1110
+ korp_mutex tierup_wait_lock;
1111
+ korp_cond tierup_wait_cond;
1112
+ bool tierup_wait_lock_inited;
1113
+ korp_tid llvm_jit_init_thread;
1114
+ /* whether the llvm jit is initialized */
1115
+ bool llvm_jit_inited;
1116
+ /* Whether to enable llvm jit compilation:
1117
+ it is set to true only when there is a module instance starts to
1118
+ run with running mode Mode_LLVM_JIT or Mode_Multi_Tier_JIT,
1119
+ since no need to enable llvm jit compilation for Mode_Interp and
1120
+ Mode_Fast_JIT, so as to improve performance for them */
1121
+ bool enable_llvm_jit_compilation;
1122
+ /* The count of groups which finish compiling the fast jit
1123
+ functions in that group */
1124
+ uint32 fast_jit_ready_groups;
1125
+ #endif
1126
+
1127
+ #if WASM_ENABLE_WAMR_COMPILER != 0
1128
+ bool is_simd_used;
1129
+ bool is_ref_types_used;
1130
+ bool is_bulk_memory_used;
1131
+ #endif
1132
+
1133
+ /* user defined name */
1134
+ char *name;
1135
+
1136
+ /* Whether the underlying wasm binary buffer can be freed */
1137
+ bool is_binary_freeable;
1138
+ };
1139
+
1140
+ typedef struct BlockType {
1141
+ /* Block type may be expressed in one of two forms:
1142
+ * either by the type of the single return value or
1143
+ * by a type index of module.
1144
+ */
1145
+ union {
1146
+ struct {
1147
+ uint8 type;
1148
+ #if WASM_ENABLE_GC != 0
1149
+ WASMRefTypeMap ref_type_map;
1150
+ #endif
1151
+ } value_type;
1152
+ WASMFuncType *type;
1153
+ } u;
1154
+ bool is_value_type;
1155
+ } BlockType;
1156
+
1157
+ typedef struct WASMBranchBlock {
1158
+ uint8 *begin_addr;
1159
+ uint8 *target_addr;
1160
+ uint32 *frame_sp;
1161
+ uint32 cell_num;
1162
+ #if WASM_ENABLE_EXCE_HANDLING != 0
1163
+ /* in exception handling, label_type needs to be stored to lookup exception
1164
+ * handlers */
1165
+ uint8 label_type;
1166
+ #endif
1167
+ } WASMBranchBlock;
1168
+
1169
+ /**
1170
+ * Align an unsigned value on a alignment boundary.
1171
+ *
1172
+ * @param v the value to be aligned
1173
+ * @param b the alignment boundary (2, 4, 8, ...)
1174
+ *
1175
+ * @return the aligned value
1176
+ */
1177
+ inline static unsigned
1178
+ align_uint(unsigned v, unsigned b)
1179
+ {
1180
+ unsigned m = b - 1;
1181
+ return (v + m) & ~m;
1182
+ }
1183
+
1184
+ /**
1185
+ * Align an 64 bit unsigned value on a alignment boundary.
1186
+ *
1187
+ * @param v the value to be aligned
1188
+ * @param b the alignment boundary (2, 4, 8, ...)
1189
+ *
1190
+ * @return the aligned value
1191
+ */
1192
+ inline static uint64
1193
+ align_uint64(uint64 v, uint64 b)
1194
+ {
1195
+ uint64 m = b - 1;
1196
+ return (v + m) & ~m;
1197
+ }
1198
+
1199
+ /**
1200
+ * Check whether a piece of data is out of range
1201
+ *
1202
+ * @param offset the offset that the data starts
1203
+ * @param len the length of the data
1204
+ * @param max_size the maximum size of the data range
1205
+ *
1206
+ * @return true if out of range, false otherwise
1207
+ */
1208
+ inline static bool
1209
+ offset_len_out_of_bounds(uint32 offset, uint32 len, uint32 max_size)
1210
+ {
1211
+ if (offset + len < offset /* integer overflow */
1212
+ || offset + len > max_size)
1213
+ return true;
1214
+ return false;
1215
+ }
1216
+
1217
+ /**
1218
+ * Return the hash value of c string.
1219
+ */
1220
+ inline static uint32
1221
+ wasm_string_hash(const char *str)
1222
+ {
1223
+ unsigned h = (unsigned)strlen(str);
1224
+ const uint8 *p = (uint8 *)str;
1225
+ const uint8 *end = p + h;
1226
+
1227
+ while (p != end)
1228
+ h = ((h << 5) - h) + *p++;
1229
+ return h;
1230
+ }
1231
+
1232
+ /**
1233
+ * Whether two c strings are equal.
1234
+ */
1235
+ inline static bool
1236
+ wasm_string_equal(const char *s1, const char *s2)
1237
+ {
1238
+ return strcmp(s1, s2) == 0 ? true : false;
1239
+ }
1240
+
1241
+ /**
1242
+ * Return the byte size of value type with specific pointer size.
1243
+ *
1244
+ * Note: Please use wasm_value_type_size for interpreter, only aot compiler
1245
+ * can use this API directly to calculate type size for different target
1246
+ */
1247
+ inline static uint32
1248
+ wasm_value_type_size_internal(uint8 value_type, uint8 pointer_size)
1249
+ {
1250
+ if (value_type == VALUE_TYPE_VOID)
1251
+ return 0;
1252
+ else if (value_type == VALUE_TYPE_I32 || value_type == VALUE_TYPE_F32
1253
+ || value_type == VALUE_TYPE_ANY)
1254
+ return sizeof(int32);
1255
+ else if (value_type == VALUE_TYPE_I64 || value_type == VALUE_TYPE_F64)
1256
+ return sizeof(int64);
1257
+ #if WASM_ENABLE_SIMD != 0
1258
+ else if (value_type == VALUE_TYPE_V128)
1259
+ return sizeof(int64) * 2;
1260
+ #endif
1261
+ #if WASM_ENABLE_GC == 0 && WASM_ENABLE_REF_TYPES != 0
1262
+ else if (value_type == VALUE_TYPE_FUNCREF
1263
+ || value_type == VALUE_TYPE_EXTERNREF)
1264
+ return sizeof(uint32);
1265
+ #elif WASM_ENABLE_GC != 0
1266
+ else if ((value_type >= (uint8)REF_TYPE_ARRAYREF /* 0x6A */
1267
+ && value_type <= (uint8)REF_TYPE_NULLFUNCREF) /* 0x73 */
1268
+ || (value_type >= (uint8)REF_TYPE_HT_NULLABLE /* 0x63 */
1269
+ && value_type <= (uint8)REF_TYPE_HT_NON_NULLABLE) /* 0x64 */
1270
+ #if WASM_ENABLE_STRINGREF != 0
1271
+ || (value_type >= (uint8)REF_TYPE_STRINGVIEWWTF8 /* 0x66 */
1272
+ && value_type <= (uint8)REF_TYPE_STRINGREF) /* 0x67 */
1273
+ || (value_type >= (uint8)REF_TYPE_STRINGVIEWITER /* 0x61 */
1274
+ && value_type <= (uint8)REF_TYPE_STRINGVIEWWTF16) /* 0x62 */
1275
+ #endif
1276
+ )
1277
+ return pointer_size;
1278
+ else if (value_type == PACKED_TYPE_I8)
1279
+ return sizeof(int8);
1280
+ else if (value_type == PACKED_TYPE_I16)
1281
+ return sizeof(int16);
1282
+ #endif
1283
+ else {
1284
+ bh_assert(0 && "Unknown value type. It should be handled ahead.");
1285
+ }
1286
+ #if WASM_ENABLE_GC == 0
1287
+ (void)pointer_size;
1288
+ #endif
1289
+ return 0;
1290
+ }
1291
+
1292
+ /**
1293
+ * Return the cell num of value type with specific pointer size.
1294
+ *
1295
+ * Note: Please use wasm_value_type_cell_num for interpreter, only aot compiler
1296
+ * can use this API directly to calculate type cell num for different target
1297
+ */
1298
+ inline static uint16
1299
+ wasm_value_type_cell_num_internal(uint8 value_type, uint8 pointer_size)
1300
+ {
1301
+ return wasm_value_type_size_internal(value_type, pointer_size) / 4;
1302
+ }
1303
+
1304
+ /**
1305
+ * Return the byte size of value type.
1306
+ */
1307
+ inline static uint32
1308
+ wasm_value_type_size(uint8 value_type)
1309
+ {
1310
+ return wasm_value_type_size_internal(value_type, sizeof(uintptr_t));
1311
+ }
1312
+
1313
+ inline static uint16
1314
+ wasm_value_type_cell_num(uint8 value_type)
1315
+ {
1316
+ return wasm_value_type_size(value_type) / 4;
1317
+ }
1318
+
1319
+ inline static uint32
1320
+ wasm_get_cell_num(const uint8 *types, uint32 type_count)
1321
+ {
1322
+ uint32 cell_num = 0;
1323
+ uint32 i;
1324
+ for (i = 0; i < type_count; i++)
1325
+ cell_num += wasm_value_type_cell_num(types[i]);
1326
+ return cell_num;
1327
+ }
1328
+
1329
+ #if WASM_ENABLE_REF_TYPES != 0
1330
+ inline static uint16
1331
+ wasm_value_type_cell_num_outside(uint8 value_type)
1332
+ {
1333
+ if (VALUE_TYPE_EXTERNREF == value_type) {
1334
+ return sizeof(uintptr_t) / sizeof(uint32);
1335
+ }
1336
+ else {
1337
+ return wasm_value_type_cell_num(value_type);
1338
+ }
1339
+ }
1340
+ #endif
1341
+
1342
+ #if WASM_ENABLE_GC == 0
1343
+ inline static bool
1344
+ wasm_type_equal(const WASMType *type1, const WASMType *type2,
1345
+ const WASMTypePtr *types, uint32 type_count)
1346
+ {
1347
+ const WASMFuncType *func_type1 = (const WASMFuncType *)type1;
1348
+ const WASMFuncType *func_type2 = (const WASMFuncType *)type2;
1349
+
1350
+ if (type1 == type2) {
1351
+ return true;
1352
+ }
1353
+
1354
+ return (func_type1->param_count == func_type2->param_count
1355
+ && func_type1->result_count == func_type2->result_count
1356
+ && memcmp(
1357
+ func_type1->types, func_type2->types,
1358
+ (uint32)(func_type1->param_count + func_type1->result_count))
1359
+ == 0)
1360
+ ? true
1361
+ : false;
1362
+ (void)types;
1363
+ (void)type_count;
1364
+ }
1365
+ #else
1366
+ /* implemented in gc_type.c */
1367
+ bool
1368
+ wasm_type_equal(const WASMType *type1, const WASMType *type2,
1369
+ const WASMTypePtr *types, uint32 type_count);
1370
+ #endif
1371
+
1372
+ inline static uint32
1373
+ wasm_get_smallest_type_idx(const WASMTypePtr *types, uint32 type_count,
1374
+ uint32 cur_type_idx)
1375
+ {
1376
+ uint32 i;
1377
+
1378
+ for (i = 0; i < cur_type_idx; i++) {
1379
+ if (wasm_type_equal(types[cur_type_idx], types[i], types, type_count))
1380
+ return i;
1381
+ }
1382
+ return cur_type_idx;
1383
+ }
1384
+
1385
+ #if WASM_ENABLE_GC == 0
1386
+ static inline uint32
1387
+ block_type_get_param_types(BlockType *block_type, uint8 **p_param_types)
1388
+ #else
1389
+ static inline uint32
1390
+ block_type_get_param_types(BlockType *block_type, uint8 **p_param_types,
1391
+ WASMRefTypeMap **p_param_reftype_maps,
1392
+ uint32 *p_param_reftype_map_count)
1393
+ #endif
1394
+ {
1395
+ uint32 param_count = 0;
1396
+ if (!block_type->is_value_type) {
1397
+ WASMFuncType *func_type = block_type->u.type;
1398
+ *p_param_types = func_type->types;
1399
+ param_count = func_type->param_count;
1400
+ #if WASM_ENABLE_GC != 0
1401
+ *p_param_reftype_maps = func_type->ref_type_maps;
1402
+ *p_param_reftype_map_count = (uint32)(func_type->result_ref_type_maps
1403
+ - func_type->ref_type_maps);
1404
+ #endif
1405
+ }
1406
+ else {
1407
+ *p_param_types = NULL;
1408
+ param_count = 0;
1409
+ #if WASM_ENABLE_GC != 0
1410
+ *p_param_reftype_maps = NULL;
1411
+ *p_param_reftype_map_count = 0;
1412
+ #endif
1413
+ }
1414
+
1415
+ return param_count;
1416
+ }
1417
+
1418
+ #if WASM_ENABLE_GC == 0
1419
+ static inline uint32
1420
+ block_type_get_result_types(BlockType *block_type, uint8 **p_result_types)
1421
+ #else
1422
+ static inline uint32
1423
+ block_type_get_result_types(BlockType *block_type, uint8 **p_result_types,
1424
+ WASMRefTypeMap **p_result_reftype_maps,
1425
+ uint32 *p_result_reftype_map_count)
1426
+ #endif
1427
+ {
1428
+ uint32 result_count = 0;
1429
+ uint8 *result_types = NULL;
1430
+ #if WASM_ENABLE_GC != 0
1431
+ uint8 type;
1432
+ uint32 result_reftype_map_count = 0;
1433
+ WASMRefTypeMap *result_reftype_maps = NULL;
1434
+ #endif
1435
+
1436
+ if (block_type->is_value_type) {
1437
+ if (block_type->u.value_type.type != VALUE_TYPE_VOID) {
1438
+ result_types = &block_type->u.value_type.type;
1439
+ result_count = 1;
1440
+ #if WASM_ENABLE_GC != 0
1441
+ type = block_type->u.value_type.type;
1442
+ if (type == (uint8)REF_TYPE_HT_NULLABLE
1443
+ || type == (uint8)REF_TYPE_HT_NON_NULLABLE) {
1444
+ result_reftype_maps = &block_type->u.value_type.ref_type_map;
1445
+ result_reftype_map_count = 1;
1446
+ }
1447
+ #endif
1448
+ }
1449
+ }
1450
+ else {
1451
+ WASMFuncType *func_type = block_type->u.type;
1452
+ result_types = func_type->types + func_type->param_count;
1453
+ result_count = func_type->result_count;
1454
+ #if WASM_ENABLE_GC != 0
1455
+ result_reftype_maps = func_type->result_ref_type_maps;
1456
+ result_reftype_map_count = (uint32)(func_type->ref_type_map_count
1457
+ - (func_type->result_ref_type_maps
1458
+ - func_type->ref_type_maps));
1459
+ #endif
1460
+ }
1461
+ *p_result_types = result_types;
1462
+ #if WASM_ENABLE_GC != 0
1463
+ *p_result_reftype_maps = result_reftype_maps;
1464
+ *p_result_reftype_map_count = result_reftype_map_count;
1465
+ #endif
1466
+ return result_count;
1467
+ }
1468
+
1469
+ static inline uint32
1470
+ block_type_get_arity(const BlockType *block_type, uint8 label_type)
1471
+ {
1472
+ if (label_type == LABEL_TYPE_LOOP) {
1473
+ if (block_type->is_value_type)
1474
+ return 0;
1475
+ else
1476
+ return block_type->u.type->param_count;
1477
+ }
1478
+ else {
1479
+ if (block_type->is_value_type) {
1480
+ return block_type->u.value_type.type != VALUE_TYPE_VOID ? 1 : 0;
1481
+ }
1482
+ else
1483
+ return block_type->u.type->result_count;
1484
+ }
1485
+ return 0;
1486
+ }
1487
+
1488
+ #ifdef __cplusplus
1489
+ } /* end of extern "C" */
1490
+ #endif
1491
+
1492
+ #endif /* end of _WASM_H_ */