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,384 @@
1
+ /*
2
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
+ */
5
+
6
+ #ifndef _EMS_GC_INTERNAL_H
7
+ #define _EMS_GC_INTERNAL_H
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ #include "bh_platform.h"
14
+ #include "ems_gc.h"
15
+
16
+ /* HMU (heap memory unit) basic block type */
17
+ typedef enum hmu_type_enum {
18
+ HMU_TYPE_MIN = 0,
19
+ HMU_TYPE_MAX = 3,
20
+ HMU_WO = 3, /* WASM Object */
21
+ HMU_VO = 2, /* VM Object */
22
+ HMU_FC = 1,
23
+ HMU_FM = 0
24
+ } hmu_type_t;
25
+
26
+ typedef struct hmu_struct {
27
+ gc_uint32 header;
28
+ } hmu_t;
29
+
30
+ #if BH_ENABLE_GC_VERIFY != 0
31
+
32
+ #if UINTPTR_MAX > UINT32_MAX
33
+ /* 2 prefix paddings for 64-bit pointer */
34
+ #define GC_OBJECT_PREFIX_PADDING_CNT 2
35
+ #else
36
+ /* 3 prefix paddings for 32-bit pointer */
37
+ #define GC_OBJECT_PREFIX_PADDING_CNT 3
38
+ #endif
39
+ #define GC_OBJECT_SUFFIX_PADDING_CNT 4
40
+ #define GC_OBJECT_PADDING_VALUE (0x12345678)
41
+
42
+ typedef struct gc_object_prefix {
43
+ const char *file_name;
44
+ gc_int32 line_no;
45
+ gc_int32 size;
46
+ gc_uint32 padding[GC_OBJECT_PREFIX_PADDING_CNT];
47
+ } gc_object_prefix_t;
48
+
49
+ typedef struct gc_object_suffix {
50
+ gc_uint32 padding[GC_OBJECT_SUFFIX_PADDING_CNT];
51
+ } gc_object_suffix_t;
52
+
53
+ #define OBJ_PREFIX_SIZE (sizeof(gc_object_prefix_t))
54
+ #define OBJ_SUFFIX_SIZE (sizeof(gc_object_suffix_t))
55
+
56
+ void
57
+ hmu_init_prefix_and_suffix(hmu_t *hmu, gc_size_t tot_size,
58
+ const char *file_name, int line_no);
59
+
60
+ void
61
+ hmu_verify(void *vheap, hmu_t *hmu);
62
+
63
+ #define SKIP_OBJ_PREFIX(p) ((void *)((gc_uint8 *)(p) + OBJ_PREFIX_SIZE))
64
+ #define SKIP_OBJ_SUFFIX(p) ((void *)((gc_uint8 *)(p) + OBJ_SUFFIX_SIZE))
65
+
66
+ #define OBJ_EXTRA_SIZE (HMU_SIZE + OBJ_PREFIX_SIZE + OBJ_SUFFIX_SIZE)
67
+
68
+ #else /* else of BH_ENABLE_GC_VERIFY */
69
+
70
+ #define OBJ_PREFIX_SIZE 0
71
+ #define OBJ_SUFFIX_SIZE 0
72
+
73
+ #define SKIP_OBJ_PREFIX(p) ((void *)((gc_uint8 *)(p) + OBJ_PREFIX_SIZE))
74
+ #define SKIP_OBJ_SUFFIX(p) ((void *)((gc_uint8 *)(p) + OBJ_SUFFIX_SIZE))
75
+
76
+ #define OBJ_EXTRA_SIZE (HMU_SIZE + OBJ_PREFIX_SIZE + OBJ_SUFFIX_SIZE)
77
+
78
+ #endif /* end of BH_ENABLE_GC_VERIFY */
79
+
80
+ #define hmu_obj_size(s) ((s)-OBJ_EXTRA_SIZE)
81
+
82
+ #define GC_ALIGN_8(s) (((uint32)(s) + 7) & (uint32)~7)
83
+
84
+ #define GC_SMALLEST_SIZE \
85
+ GC_ALIGN_8(HMU_SIZE + OBJ_PREFIX_SIZE + OBJ_SUFFIX_SIZE + 8)
86
+ #define GC_GET_REAL_SIZE(x) \
87
+ GC_ALIGN_8(HMU_SIZE + OBJ_PREFIX_SIZE + OBJ_SUFFIX_SIZE \
88
+ + (((x) > 8) ? (x) : 8))
89
+
90
+ /**
91
+ * hmu bit operation
92
+ */
93
+
94
+ #define SETBIT(v, offset) (v) |= ((uint32)1 << (offset))
95
+ #define GETBIT(v, offset) ((v) & ((uint32)1 << (offset)) ? 1 : 0)
96
+ #define CLRBIT(v, offset) (v) &= (~((uint32)1 << (offset)))
97
+
98
+ /* clang-format off */
99
+ #define SETBITS(v, offset, size, value) \
100
+ do { \
101
+ (v) &= ~((((uint32)1 << size) - 1) << offset); \
102
+ (v) |= ((uint32)value << offset); \
103
+ } while (0)
104
+ #define CLRBITS(v, offset, size) \
105
+ (v) &= ~((((uint32)1 << size) - 1) << offset)
106
+ #define GETBITS(v, offset, size) \
107
+ (((v) & (((((uint32)1 << size) - 1) << offset))) >> offset)
108
+ /* clang-format on */
109
+
110
+ /**
111
+ * gc object layout definition
112
+ */
113
+
114
+ #define HMU_SIZE (sizeof(hmu_t))
115
+
116
+ #define hmu_to_obj(hmu) (gc_object_t)(SKIP_OBJ_PREFIX((hmu_t *)(hmu) + 1))
117
+ #define obj_to_hmu(obj) ((hmu_t *)((gc_uint8 *)(obj)-OBJ_PREFIX_SIZE) - 1)
118
+
119
+ #define HMU_UT_SIZE 2
120
+ #define HMU_UT_OFFSET 30
121
+
122
+ /* clang-format off */
123
+ #define hmu_get_ut(hmu) \
124
+ GETBITS((hmu)->header, HMU_UT_OFFSET, HMU_UT_SIZE)
125
+ #define hmu_set_ut(hmu, type) \
126
+ SETBITS((hmu)->header, HMU_UT_OFFSET, HMU_UT_SIZE, type)
127
+ #define hmu_is_ut_valid(tp) \
128
+ (tp >= HMU_TYPE_MIN && tp <= HMU_TYPE_MAX)
129
+ /* clang-format on */
130
+
131
+ /* P in use bit means the previous chunk is in use */
132
+ #define HMU_P_OFFSET 29
133
+
134
+ #define hmu_mark_pinuse(hmu) SETBIT((hmu)->header, HMU_P_OFFSET)
135
+ #define hmu_unmark_pinuse(hmu) CLRBIT((hmu)->header, HMU_P_OFFSET)
136
+ #define hmu_get_pinuse(hmu) GETBIT((hmu)->header, HMU_P_OFFSET)
137
+
138
+ #define HMU_WO_VT_SIZE 27
139
+ #define HMU_WO_VT_OFFSET 0
140
+ #define HMU_WO_MB_OFFSET 28
141
+
142
+ #define hmu_mark_wo(hmu) SETBIT((hmu)->header, HMU_WO_MB_OFFSET)
143
+ #define hmu_unmark_wo(hmu) CLRBIT((hmu)->header, HMU_WO_MB_OFFSET)
144
+ #define hmu_is_wo_marked(hmu) GETBIT((hmu)->header, HMU_WO_MB_OFFSET)
145
+
146
+ /**
147
+ * The hmu size is divisible by 8, its lowest 3 bits are 0, so we only
148
+ * store its higher bits of bit [29..3], and bit [2..0] are not stored.
149
+ * After that, the maximal heap size can be enlarged from (1<<27) = 128MB
150
+ * to (1<<27) * 8 = 1GB.
151
+ */
152
+ #define HMU_SIZE_SIZE 27
153
+ #define HMU_SIZE_OFFSET 0
154
+
155
+ #define HMU_VO_FB_OFFSET 28
156
+
157
+ #define hmu_is_vo_freed(hmu) GETBIT((hmu)->header, HMU_VO_FB_OFFSET)
158
+ #define hmu_unfree_vo(hmu) CLRBIT((hmu)->header, HMU_VO_FB_OFFSET)
159
+
160
+ #define hmu_get_size(hmu) \
161
+ (GETBITS((hmu)->header, HMU_SIZE_OFFSET, HMU_SIZE_SIZE) << 3)
162
+ #define hmu_set_size(hmu, size) \
163
+ SETBITS((hmu)->header, HMU_SIZE_OFFSET, HMU_SIZE_SIZE, ((size) >> 3))
164
+
165
+ /**
166
+ * HMU free chunk management
167
+ */
168
+
169
+ #ifndef HMU_NORMAL_NODE_CNT
170
+ #define HMU_NORMAL_NODE_CNT 32
171
+ #endif
172
+ #define HMU_FC_NORMAL_MAX_SIZE ((HMU_NORMAL_NODE_CNT - 1) << 3)
173
+ #define HMU_IS_FC_NORMAL(size) ((size) < HMU_FC_NORMAL_MAX_SIZE)
174
+ #if HMU_FC_NORMAL_MAX_SIZE >= GC_MAX_HEAP_SIZE
175
+ #error "Too small GC_MAX_HEAP_SIZE"
176
+ #endif
177
+
178
+ typedef struct hmu_normal_node {
179
+ hmu_t hmu_header;
180
+ gc_int32 next_offset;
181
+ } hmu_normal_node_t;
182
+
183
+ typedef struct hmu_normal_list {
184
+ hmu_normal_node_t *next;
185
+ } hmu_normal_list_t;
186
+
187
+ static inline hmu_normal_node_t *
188
+ get_hmu_normal_node_next(hmu_normal_node_t *node)
189
+ {
190
+ return node->next_offset
191
+ ? (hmu_normal_node_t *)((uint8 *)node + node->next_offset)
192
+ : NULL;
193
+ }
194
+
195
+ static inline void
196
+ set_hmu_normal_node_next(hmu_normal_node_t *node, hmu_normal_node_t *next)
197
+ {
198
+ if (next) {
199
+ bh_assert((uint8 *)next - (uint8 *)node < INT32_MAX);
200
+ node->next_offset = (gc_int32)(intptr_t)((uint8 *)next - (uint8 *)node);
201
+ }
202
+ else {
203
+ node->next_offset = 0;
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Define hmu_tree_node as a packed struct, since it is at the 4-byte
209
+ * aligned address and the size of hmu_head is 4, so in 64-bit target,
210
+ * the left/right/parent fields will be at 8-byte aligned address,
211
+ * we can access them directly.
212
+ */
213
+ #if UINTPTR_MAX == UINT64_MAX
214
+ #if defined(_MSC_VER)
215
+ __pragma(pack(push, 1));
216
+ #define __attr_packed
217
+ #define __attr_aligned(a)
218
+ #elif defined(__GNUC__) || defined(__clang__)
219
+ #define __attr_packed __attribute__((packed))
220
+ #define __attr_aligned(a) __attribute__((aligned(a)))
221
+ #else
222
+ #error "packed attribute isn't used to define struct hmu_tree_node"
223
+ #endif
224
+ #else /* else of UINTPTR_MAX == UINT64_MAX */
225
+ #define __attr_packed
226
+ #define __attr_aligned(a)
227
+ #endif
228
+
229
+ typedef struct hmu_tree_node {
230
+ hmu_t hmu_header;
231
+ struct hmu_tree_node *left;
232
+ struct hmu_tree_node *right;
233
+ struct hmu_tree_node *parent;
234
+ gc_size_t size;
235
+ } __attr_packed __attr_aligned(4) hmu_tree_node_t;
236
+
237
+ #if UINTPTR_MAX == UINT64_MAX
238
+ #if defined(_MSC_VER)
239
+ __pragma(pack(pop));
240
+ #endif
241
+ #endif
242
+
243
+ bh_static_assert(sizeof(hmu_tree_node_t) == 8 + 3 * sizeof(void *));
244
+ bh_static_assert(offsetof(hmu_tree_node_t, left) == 4);
245
+
246
+ #define ASSERT_TREE_NODE_ALIGNED_ACCESS(tree_node) \
247
+ do { \
248
+ bh_assert((((uintptr_t)&tree_node->left) & (sizeof(uintptr_t) - 1)) \
249
+ == 0); \
250
+ } while (0)
251
+
252
+ typedef struct gc_heap_struct {
253
+ /* for double checking*/
254
+ gc_handle_t heap_id;
255
+
256
+ gc_uint8 *base_addr;
257
+ gc_size_t current_size;
258
+
259
+ korp_mutex lock;
260
+
261
+ hmu_normal_list_t kfc_normal_list[HMU_NORMAL_NODE_CNT];
262
+
263
+ #if UINTPTR_MAX == UINT64_MAX
264
+ /* make kfc_tree_root_buf 4-byte aligned and not 8-byte aligned,
265
+ so kfc_tree_root's left/right/parent fields are 8-byte aligned
266
+ and we can access them directly */
267
+ uint32 __padding;
268
+ #endif
269
+ uint8 kfc_tree_root_buf[sizeof(hmu_tree_node_t)];
270
+ /* point to kfc_tree_root_buf, the order in kfc_tree is:
271
+ size[left] <= size[cur] < size[right] */
272
+ hmu_tree_node_t *kfc_tree_root;
273
+
274
+ #if WASM_ENABLE_GC != 0
275
+ /* for rootset enumeration of private heap*/
276
+ void *root_set;
277
+
278
+ #if WASM_ENABLE_THREAD_MGR == 0
279
+ /* exec_env of current wasm module instance */
280
+ void *exec_env;
281
+ #else
282
+ /* thread cluster of current module instances */
283
+ void *cluster;
284
+ #endif
285
+
286
+ /* whether the fast mode of marking process that requires
287
+ additional memory fails. When the fast mode fails, the
288
+ marking process can still be done in the slow mode, which
289
+ doesn't need additional memory (by walking through all
290
+ blocks and marking successors of marked nodes until no new
291
+ node is marked). TODO: slow mode is not implemented. */
292
+ unsigned is_fast_marking_failed : 1;
293
+
294
+ /* whether the heap is doing reclaim */
295
+ unsigned is_doing_reclaim : 1;
296
+
297
+ /* Whether the heap can do reclaim */
298
+ unsigned is_reclaim_enabled : 1;
299
+ #endif
300
+
301
+ #if BH_ENABLE_GC_CORRUPTION_CHECK != 0
302
+ /* whether heap is corrupted, e.g. the hmu nodes are modified
303
+ by user */
304
+ bool is_heap_corrupted;
305
+ #endif
306
+
307
+ gc_size_t init_size;
308
+ gc_size_t highmark_size;
309
+ gc_size_t total_free_size;
310
+
311
+ #if WASM_ENABLE_GC != 0
312
+ gc_size_t gc_threshold;
313
+ gc_size_t gc_threshold_factor;
314
+ gc_size_t total_gc_count;
315
+ gc_size_t total_gc_time;
316
+ gc_size_t max_gc_time;
317
+ /* Usually there won't be too many extra info node, so we try to use a fixed
318
+ * array to store them, if the fixed array don't have enough space to store
319
+ * the nodes, a new space will be allocated from heap */
320
+ extra_info_node_t *extra_info_normal_nodes[EXTRA_INFO_NORMAL_NODE_CNT];
321
+ /* Used to store extra information such as finalizer for specified nodes, we
322
+ * introduce a separate space to store these information so only nodes who
323
+ * really require extra information will occupy additional memory spaces. */
324
+ extra_info_node_t **extra_info_nodes;
325
+ gc_size_t extra_info_node_cnt;
326
+ gc_size_t extra_info_node_capacity;
327
+ #endif
328
+ #if GC_STAT_DATA != 0
329
+ gc_uint64 total_size_allocated;
330
+ gc_uint64 total_size_freed;
331
+ #endif
332
+ } gc_heap_t;
333
+
334
+ #if WASM_ENABLE_GC != 0
335
+
336
+ #define GC_DEFAULT_THRESHOLD_FACTOR 300
337
+
338
+ static inline void
339
+ gc_update_threshold(gc_heap_t *heap)
340
+ {
341
+ heap->gc_threshold =
342
+ heap->total_free_size * heap->gc_threshold_factor / 1000;
343
+ }
344
+
345
+ #define gct_vm_mutex_init os_mutex_init
346
+ #define gct_vm_mutex_destroy os_mutex_destroy
347
+ #define gct_vm_mutex_lock os_mutex_lock
348
+ #define gct_vm_mutex_unlock os_mutex_unlock
349
+ #define gct_vm_gc_prepare wasm_runtime_gc_prepare
350
+ #define gct_vm_gc_finished wasm_runtime_gc_finalize
351
+ #define gct_vm_begin_rootset_enumeration wasm_runtime_traverse_gc_rootset
352
+ #define gct_vm_get_wasm_object_ref_list wasm_runtime_get_wasm_object_ref_list
353
+ #define gct_vm_get_extra_info_flag wasm_runtime_get_wasm_object_extra_info_flag
354
+ #define gct_vm_set_extra_info_flag wasm_runtime_set_wasm_object_extra_info_flag
355
+
356
+ #endif /* end of WAMS_ENABLE_GC != 0 */
357
+
358
+ /**
359
+ * MISC internal used APIs
360
+ */
361
+
362
+ bool
363
+ gci_add_fc(gc_heap_t *heap, hmu_t *hmu, gc_size_t size);
364
+
365
+ int
366
+ gci_is_heap_valid(gc_heap_t *heap);
367
+
368
+ /**
369
+ * Verify heap integrity
370
+ */
371
+ void
372
+ gci_verify_heap(gc_heap_t *heap);
373
+
374
+ /**
375
+ * Dump heap nodes
376
+ */
377
+ void
378
+ gci_dump(gc_heap_t *heap);
379
+
380
+ #ifdef __cplusplus
381
+ }
382
+ #endif
383
+
384
+ #endif /* end of _EMS_GC_INTERNAL_H */
@@ -0,0 +1,95 @@
1
+ /*
2
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
+ */
5
+
6
+ #include "ems_gc_internal.h"
7
+
8
+ #if BH_ENABLE_GC_VERIFY != 0
9
+
10
+ /**
11
+ * Set default value to prefix and suffix
12
+ * @param hmu should not be NULL and should have been correctly initialized
13
+ * (except prefix and suffix part)
14
+ * @param tot_size is offered here because hmu_get_size can not be used
15
+ * till now. tot_size should not be smaller than OBJ_EXTRA_SIZE.
16
+ * For VO, tot_size should be equal to object total size.
17
+ */
18
+ void
19
+ hmu_init_prefix_and_suffix(hmu_t *hmu, gc_size_t tot_size,
20
+ const char *file_name, int line_no)
21
+ {
22
+ gc_object_prefix_t *prefix = NULL;
23
+ gc_object_suffix_t *suffix = NULL;
24
+ gc_uint32 i = 0;
25
+
26
+ bh_assert(hmu);
27
+ bh_assert(hmu_get_ut(hmu) == HMU_WO || hmu_get_ut(hmu) == HMU_VO);
28
+ bh_assert(tot_size >= OBJ_EXTRA_SIZE);
29
+ bh_assert(!(tot_size & 7));
30
+ bh_assert(hmu_get_ut(hmu) != HMU_VO || hmu_get_size(hmu) >= tot_size);
31
+
32
+ prefix = (gc_object_prefix_t *)(hmu + 1);
33
+ suffix =
34
+ (gc_object_suffix_t *)((gc_uint8 *)hmu + tot_size - OBJ_SUFFIX_SIZE);
35
+ prefix->file_name = file_name;
36
+ prefix->line_no = line_no;
37
+ prefix->size = tot_size;
38
+
39
+ for (i = 0; i < GC_OBJECT_PREFIX_PADDING_CNT; i++) {
40
+ prefix->padding[i] = GC_OBJECT_PADDING_VALUE;
41
+ }
42
+
43
+ for (i = 0; i < GC_OBJECT_SUFFIX_PADDING_CNT; i++) {
44
+ suffix->padding[i] = GC_OBJECT_PADDING_VALUE;
45
+ }
46
+ }
47
+
48
+ void
49
+ hmu_verify(void *vheap, hmu_t *hmu)
50
+ {
51
+ #if BH_ENABLE_GC_CORRUPTION_CHECK != 0
52
+ gc_heap_t *heap = (gc_heap_t *)vheap;
53
+ #endif
54
+ gc_object_prefix_t *prefix = NULL;
55
+ gc_object_suffix_t *suffix = NULL;
56
+ gc_uint32 i = 0;
57
+ hmu_type_t ut;
58
+ gc_size_t size = 0;
59
+ int is_padding_ok = 1;
60
+
61
+ bh_assert(hmu);
62
+ ut = hmu_get_ut(hmu);
63
+ bh_assert(hmu_is_ut_valid(ut));
64
+
65
+ prefix = (gc_object_prefix_t *)(hmu + 1);
66
+ size = prefix->size;
67
+ suffix = (gc_object_suffix_t *)((gc_uint8 *)hmu + size - OBJ_SUFFIX_SIZE);
68
+
69
+ if (ut == HMU_VO || ut == HMU_WO) {
70
+ /* check padding*/
71
+ for (i = 0; i < GC_OBJECT_PREFIX_PADDING_CNT; i++) {
72
+ if (prefix->padding[i] != GC_OBJECT_PADDING_VALUE) {
73
+ is_padding_ok = 0;
74
+ break;
75
+ }
76
+ }
77
+ for (i = 0; i < GC_OBJECT_SUFFIX_PADDING_CNT; i++) {
78
+ if (suffix->padding[i] != GC_OBJECT_PADDING_VALUE) {
79
+ is_padding_ok = 0;
80
+ break;
81
+ }
82
+ }
83
+
84
+ if (!is_padding_ok) {
85
+ LOG_ERROR("Invalid padding for object created at %s:%d\n",
86
+ (prefix->file_name ? prefix->file_name : ""),
87
+ prefix->line_no);
88
+ #if BH_ENABLE_GC_CORRUPTION_CHECK != 0
89
+ heap->is_heap_corrupted = true;
90
+ #endif
91
+ }
92
+ }
93
+ }
94
+
95
+ #endif /* end of BH_ENABLE_GC_VERIFY */