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.
- package/LICENSE +2 -1
- package/README.md +1 -0
- package/dist/cli.js +351 -73
- package/dist/crypto.js +37 -11
- package/dist/engine/engine.c +6 -3
- package/kernel/Sources/CQuickJS/include/kernel_qjs.h +8 -1
- package/kernel/Sources/CQuickJS/kernel_internal.h +54 -0
- package/kernel/Sources/CQuickJS/kernel_qjs.c +17 -29
- package/kernel/Sources/CQuickJS/kernel_wasm.c +1155 -0
- package/kernel/Sources/CWAMR/include/kernel_wamr.h +151 -0
- package/kernel/Sources/CWAMR/include/kernel_wamr_config.h +66 -0
- package/kernel/Sources/CWAMR/vendor/LICENSE +219 -0
- package/kernel/Sources/CWAMR/vendor/core/config.h +727 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/aot/aot_runtime.h +899 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/arch/invokeNative_general.c +123 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_application.c +933 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_blocking_op.c +92 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_c_api.c +5391 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_c_api_internal.h +246 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_exec_env.c +336 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_exec_env.h +328 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_loader_common.c +242 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_loader_common.h +62 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_memory.c +1999 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_memory.h +154 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_native.c +1532 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_native.h +117 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_runtime_common.c +8070 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_runtime_common.h +1396 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_shared_memory.c +477 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_shared_memory.h +63 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/common/wasm_suspend_flags.h +52 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/compilation/aot.h +366 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/include/lib_export.h +60 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/include/wasm_c_api.h +910 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/include/wasm_export.h +2440 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm.h +1492 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_interp.h +122 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_interp_fast.c +7998 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_loader.c +16909 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_loader.h +80 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_opcode.h +1043 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_runtime.c +5174 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/interpreter/wasm_runtime.h +912 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/libraries/thread-mgr/thread_manager.c +1569 -0
- package/kernel/Sources/CWAMR/vendor/core/iwasm/libraries/thread-mgr/thread_manager.h +256 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/ems/ems_alloc.c +1169 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/ems/ems_gc.c +497 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/ems/ems_gc.h +350 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/ems/ems_gc_internal.h +384 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/ems/ems_hmu.c +95 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/ems/ems_kfc.c +547 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/mem_alloc.c +252 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/mem-alloc/mem_alloc.h +96 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/memory/mremap.c +12 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/posix/posix_blocking_op.c +70 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/posix/posix_malloc.c +72 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/posix/posix_memmap.c +302 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/posix/posix_sleep.c +20 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/posix/posix_thread.c +784 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/common/posix/posix_time.c +28 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/darwin/platform_init.c +43 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/darwin/platform_internal.h +126 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/include/platform_api_extension.h +1676 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/include/platform_api_vmcore.h +192 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/include/platform_common.h +204 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/include/platform_wasi_types.h +610 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/linux/platform_init.c +43 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/platform/linux/platform_internal.h +139 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_assert.c +25 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_assert.h +42 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_atomic.h +300 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_bitmap.c +27 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_bitmap.h +114 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_common.c +217 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_common.h +83 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_hashmap.c +339 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_hashmap.h +168 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_leb128.c +77 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_leb128.h +30 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_list.c +111 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_list.h +109 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_log.c +111 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_log.h +94 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_platform.h +38 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_queue.c +256 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_queue.h +80 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_vector.c +279 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/bh_vector.h +126 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/gnuc.h +14 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/runtime_timer.c +469 -0
- package/kernel/Sources/CWAMR/vendor/core/shared/utils/runtime_timer.h +51 -0
- package/kernel/Sources/CWAMR/vendor/core/version.h +24 -0
- package/kernel/Sources/CWAMR/wamr_bh_assert.c +98 -0
- package/kernel/Sources/CWAMR/wamr_bh_bitmap.c +98 -0
- package/kernel/Sources/CWAMR/wamr_bh_common.c +98 -0
- package/kernel/Sources/CWAMR/wamr_bh_hashmap.c +98 -0
- package/kernel/Sources/CWAMR/wamr_bh_leb128.c +98 -0
- package/kernel/Sources/CWAMR/wamr_bh_list.c +98 -0
- package/kernel/Sources/CWAMR/wamr_bh_log.c +98 -0
- package/kernel/Sources/CWAMR/wamr_bh_queue.c +98 -0
- package/kernel/Sources/CWAMR/wamr_bh_vector.c +98 -0
- package/kernel/Sources/CWAMR/wamr_ems_alloc.c +98 -0
- package/kernel/Sources/CWAMR/wamr_ems_gc.c +98 -0
- package/kernel/Sources/CWAMR/wamr_ems_hmu.c +98 -0
- package/kernel/Sources/CWAMR/wamr_ems_kfc.c +98 -0
- package/kernel/Sources/CWAMR/wamr_invokeNative_general.c +98 -0
- package/kernel/Sources/CWAMR/wamr_mem_alloc.c +98 -0
- package/kernel/Sources/CWAMR/wamr_mremap.c +98 -0
- package/kernel/Sources/CWAMR/wamr_platform_init_darwin.c +100 -0
- package/kernel/Sources/CWAMR/wamr_platform_init_linux.c +100 -0
- package/kernel/Sources/CWAMR/wamr_posix_blocking_op.c +98 -0
- package/kernel/Sources/CWAMR/wamr_posix_malloc.c +98 -0
- package/kernel/Sources/CWAMR/wamr_posix_memmap.c +98 -0
- package/kernel/Sources/CWAMR/wamr_posix_sleep.c +98 -0
- package/kernel/Sources/CWAMR/wamr_posix_thread.c +98 -0
- package/kernel/Sources/CWAMR/wamr_posix_time.c +98 -0
- package/kernel/Sources/CWAMR/wamr_runtime_timer.c +98 -0
- package/kernel/Sources/CWAMR/wamr_thread_manager.c +98 -0
- package/kernel/Sources/CWAMR/wamr_wasm_application.c +98 -0
- package/kernel/Sources/CWAMR/wamr_wasm_blocking_op.c +98 -0
- package/kernel/Sources/CWAMR/wamr_wasm_c_api.c +98 -0
- package/kernel/Sources/CWAMR/wamr_wasm_exec_env.c +98 -0
- package/kernel/Sources/CWAMR/wamr_wasm_interp_fast.c +98 -0
- package/kernel/Sources/CWAMR/wamr_wasm_loader.c +98 -0
- package/kernel/Sources/CWAMR/wamr_wasm_loader_common.c +98 -0
- package/kernel/Sources/CWAMR/wamr_wasm_memory.c +98 -0
- package/kernel/Sources/CWAMR/wamr_wasm_native.c +98 -0
- package/kernel/Sources/CWAMR/wamr_wasm_runtime.c +98 -0
- package/kernel/Sources/CWAMR/wamr_wasm_runtime_common.c +98 -0
- package/kernel/Sources/CWAMR/wamr_wasm_shared_memory.c +98 -0
- package/kernel/Sources/Kernel/PluginPrelude.js +5 -2
- package/kernel/Tests/KernelTests/CasePins.js +50 -0
- package/package.json +2 -2
- package/skill/krillplayer-plugin/SKILL.md +2 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-content-rejected.json +8 -4
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-login-expired.json +8 -4
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-muted.json +8 -4
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-other.json +8 -4
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-rate-limited.json +8 -4
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/danmaku-send-sent.json +8 -4
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live-logged-in.json +39 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live-selected-backup-line.json +8 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live-selected-line-gone.json +8 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live.json +8 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/plugin.ts +26 -9
- package/skill/krillplayer-plugin/references/cases.md +19 -1
- package/skill/krillplayer-plugin/references/contract.d.ts +104 -11
- package/skill/krillplayer-plugin/references/crypto-tools.md +104 -0
- package/skill/krillplayer-plugin/references/errors-and-fixes.md +5 -1
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include "mem_alloc.h"
|
|
7
|
+
#include <stdbool.h>
|
|
8
|
+
|
|
9
|
+
#if DEFAULT_MEM_ALLOCATOR == MEM_ALLOCATOR_EMS
|
|
10
|
+
|
|
11
|
+
#include "ems/ems_gc.h"
|
|
12
|
+
|
|
13
|
+
mem_allocator_t
|
|
14
|
+
mem_allocator_create(void *mem, uint32_t size)
|
|
15
|
+
{
|
|
16
|
+
return gc_init_with_pool((char *)mem, size);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
mem_allocator_t
|
|
20
|
+
mem_allocator_create_with_struct_and_pool(void *struct_buf,
|
|
21
|
+
uint32_t struct_buf_size,
|
|
22
|
+
void *pool_buf,
|
|
23
|
+
uint32_t pool_buf_size)
|
|
24
|
+
{
|
|
25
|
+
return gc_init_with_struct_and_pool((char *)struct_buf, struct_buf_size,
|
|
26
|
+
pool_buf, pool_buf_size);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
int
|
|
30
|
+
mem_allocator_destroy(mem_allocator_t allocator)
|
|
31
|
+
{
|
|
32
|
+
return gc_destroy_with_pool((gc_handle_t)allocator);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
uint32
|
|
36
|
+
mem_allocator_get_heap_struct_size()
|
|
37
|
+
{
|
|
38
|
+
return gc_get_heap_struct_size();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
void *
|
|
42
|
+
mem_allocator_malloc(mem_allocator_t allocator, uint32_t size)
|
|
43
|
+
{
|
|
44
|
+
return gc_alloc_vo((gc_handle_t)allocator, size);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
void *
|
|
48
|
+
mem_allocator_realloc(mem_allocator_t allocator, void *ptr, uint32_t size)
|
|
49
|
+
{
|
|
50
|
+
return gc_realloc_vo((gc_handle_t)allocator, ptr, size);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void
|
|
54
|
+
mem_allocator_free(mem_allocator_t allocator, void *ptr)
|
|
55
|
+
{
|
|
56
|
+
if (ptr)
|
|
57
|
+
gc_free_vo((gc_handle_t)allocator, ptr);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#if WASM_ENABLE_GC != 0
|
|
61
|
+
void *
|
|
62
|
+
mem_allocator_malloc_with_gc(mem_allocator_t allocator, uint32_t size)
|
|
63
|
+
{
|
|
64
|
+
return gc_alloc_wo((gc_handle_t)allocator, size);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#if WASM_GC_MANUALLY != 0
|
|
68
|
+
void
|
|
69
|
+
mem_allocator_free_with_gc(mem_allocator_t allocator, void *ptr)
|
|
70
|
+
{
|
|
71
|
+
if (ptr)
|
|
72
|
+
gc_free_wo((gc_handle_t)allocator, ptr);
|
|
73
|
+
}
|
|
74
|
+
#endif
|
|
75
|
+
|
|
76
|
+
#if WASM_ENABLE_THREAD_MGR == 0
|
|
77
|
+
void
|
|
78
|
+
mem_allocator_enable_gc_reclaim(mem_allocator_t allocator, void *exec_env)
|
|
79
|
+
{
|
|
80
|
+
gc_enable_gc_reclaim((gc_handle_t)allocator, exec_env);
|
|
81
|
+
}
|
|
82
|
+
#else
|
|
83
|
+
void
|
|
84
|
+
mem_allocator_enable_gc_reclaim(mem_allocator_t allocator, void *cluster)
|
|
85
|
+
{
|
|
86
|
+
gc_enable_gc_reclaim((gc_handle_t)allocator, cluster);
|
|
87
|
+
}
|
|
88
|
+
#endif
|
|
89
|
+
|
|
90
|
+
int
|
|
91
|
+
mem_allocator_add_root(mem_allocator_t allocator, WASMObjectRef obj)
|
|
92
|
+
{
|
|
93
|
+
return gc_add_root((gc_handle_t)allocator, (gc_object_t)obj);
|
|
94
|
+
}
|
|
95
|
+
#endif
|
|
96
|
+
|
|
97
|
+
int
|
|
98
|
+
mem_allocator_migrate(mem_allocator_t allocator, char *pool_buf_new,
|
|
99
|
+
uint32 pool_buf_size)
|
|
100
|
+
{
|
|
101
|
+
return gc_migrate((gc_handle_t)allocator, pool_buf_new, pool_buf_size);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
bool
|
|
105
|
+
mem_allocator_is_heap_corrupted(mem_allocator_t allocator)
|
|
106
|
+
{
|
|
107
|
+
return gc_is_heap_corrupted((gc_handle_t)allocator);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
bool
|
|
111
|
+
mem_allocator_get_alloc_info(mem_allocator_t allocator, void *mem_alloc_info)
|
|
112
|
+
{
|
|
113
|
+
gc_heap_stats((gc_handle_t)allocator, mem_alloc_info, 3);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#if WASM_ENABLE_GC != 0
|
|
118
|
+
bool
|
|
119
|
+
mem_allocator_set_gc_finalizer(mem_allocator_t allocator, void *obj,
|
|
120
|
+
gc_finalizer_t cb, void *data)
|
|
121
|
+
{
|
|
122
|
+
return gc_set_finalizer((gc_handle_t)allocator, (gc_object_t)obj, cb, data);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
void
|
|
126
|
+
mem_allocator_unset_gc_finalizer(mem_allocator_t allocator, void *obj)
|
|
127
|
+
{
|
|
128
|
+
gc_unset_finalizer((gc_handle_t)allocator, (gc_object_t)obj);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
#if WASM_ENABLE_GC_PERF_PROFILING != 0
|
|
132
|
+
void
|
|
133
|
+
mem_allocator_dump_perf_profiling(mem_allocator_t allocator)
|
|
134
|
+
{
|
|
135
|
+
gc_dump_perf_profiling((gc_handle_t)allocator);
|
|
136
|
+
}
|
|
137
|
+
#endif
|
|
138
|
+
|
|
139
|
+
#endif
|
|
140
|
+
|
|
141
|
+
#else /* else of DEFAULT_MEM_ALLOCATOR */
|
|
142
|
+
|
|
143
|
+
#include "tlsf/tlsf.h"
|
|
144
|
+
|
|
145
|
+
typedef struct mem_allocator_tlsf {
|
|
146
|
+
tlsf_t tlsf;
|
|
147
|
+
korp_mutex lock;
|
|
148
|
+
} mem_allocator_tlsf;
|
|
149
|
+
|
|
150
|
+
mem_allocator_t
|
|
151
|
+
mem_allocator_create(void *mem, uint32_t size)
|
|
152
|
+
{
|
|
153
|
+
mem_allocator_tlsf *allocator_tlsf;
|
|
154
|
+
tlsf_t tlsf;
|
|
155
|
+
char *mem_aligned = (char *)(((uintptr_t)mem + 3) & ~3);
|
|
156
|
+
|
|
157
|
+
if (size < 1024) {
|
|
158
|
+
printf("Create mem allocator failed: pool size must be "
|
|
159
|
+
"at least 1024 bytes.\n");
|
|
160
|
+
return NULL;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
size -= mem_aligned - (char *)mem;
|
|
164
|
+
mem = (void *)mem_aligned;
|
|
165
|
+
|
|
166
|
+
tlsf = tlsf_create_with_pool(mem, size);
|
|
167
|
+
if (!tlsf) {
|
|
168
|
+
printf("Create mem allocator failed: tlsf_create_with_pool failed.\n");
|
|
169
|
+
return NULL;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
allocator_tlsf = tlsf_malloc(tlsf, sizeof(mem_allocator_tlsf));
|
|
173
|
+
if (!allocator_tlsf) {
|
|
174
|
+
printf("Create mem allocator failed: tlsf_malloc failed.\n");
|
|
175
|
+
tlsf_destroy(tlsf);
|
|
176
|
+
return NULL;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
allocator_tlsf->tlsf = tlsf;
|
|
180
|
+
|
|
181
|
+
if (os_mutex_init(&allocator_tlsf->lock)) {
|
|
182
|
+
printf("Create mem allocator failed: tlsf_malloc failed.\n");
|
|
183
|
+
tlsf_free(tlsf, allocator_tlsf);
|
|
184
|
+
tlsf_destroy(tlsf);
|
|
185
|
+
return NULL;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return allocator_tlsf;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
void
|
|
192
|
+
mem_allocator_destroy(mem_allocator_t allocator)
|
|
193
|
+
{
|
|
194
|
+
mem_allocator_tlsf *allocator_tlsf = (mem_allocator_tlsf *)allocator;
|
|
195
|
+
tlsf_t tlsf = allocator_tlsf->tlsf;
|
|
196
|
+
|
|
197
|
+
os_mutex_destroy(&allocator_tlsf->lock);
|
|
198
|
+
tlsf_free(tlsf, allocator_tlsf);
|
|
199
|
+
tlsf_destroy(tlsf);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
void *
|
|
203
|
+
mem_allocator_malloc(mem_allocator_t allocator, uint32_t size)
|
|
204
|
+
{
|
|
205
|
+
void *ret;
|
|
206
|
+
mem_allocator_tlsf *allocator_tlsf = (mem_allocator_tlsf *)allocator;
|
|
207
|
+
|
|
208
|
+
if (size == 0)
|
|
209
|
+
/* tlsf doesn't allow to allocate 0 byte */
|
|
210
|
+
size = 1;
|
|
211
|
+
|
|
212
|
+
os_mutex_lock(&allocator_tlsf->lock);
|
|
213
|
+
ret = tlsf_malloc(allocator_tlsf->tlsf, size);
|
|
214
|
+
os_mutex_unlock(&allocator_tlsf->lock);
|
|
215
|
+
return ret;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
void *
|
|
219
|
+
mem_allocator_realloc(mem_allocator_t allocator, void *ptr, uint32_t size)
|
|
220
|
+
{
|
|
221
|
+
void *ret;
|
|
222
|
+
mem_allocator_tlsf *allocator_tlsf = (mem_allocator_tlsf *)allocator;
|
|
223
|
+
|
|
224
|
+
if (size == 0)
|
|
225
|
+
/* tlsf doesn't allow to allocate 0 byte */
|
|
226
|
+
size = 1;
|
|
227
|
+
|
|
228
|
+
os_mutex_lock(&allocator_tlsf->lock);
|
|
229
|
+
ret = tlsf_realloc(allocator_tlsf->tlsf, ptr, size);
|
|
230
|
+
os_mutex_unlock(&allocator_tlsf->lock);
|
|
231
|
+
return ret;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
void
|
|
235
|
+
mem_allocator_free(mem_allocator_t allocator, void *ptr)
|
|
236
|
+
{
|
|
237
|
+
if (ptr) {
|
|
238
|
+
mem_allocator_tlsf *allocator_tlsf = (mem_allocator_tlsf *)allocator;
|
|
239
|
+
os_mutex_lock(&allocator_tlsf->lock);
|
|
240
|
+
tlsf_free(allocator_tlsf->tlsf, ptr);
|
|
241
|
+
os_mutex_unlock(&allocator_tlsf->lock);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
int
|
|
246
|
+
mem_allocator_migrate(mem_allocator_t allocator, mem_allocator_t allocator_old)
|
|
247
|
+
{
|
|
248
|
+
return tlsf_migrate((mem_allocator_tlsf *)allocator,
|
|
249
|
+
(mem_allocator_tlsf *)allocator_old);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#endif /* end of DEFAULT_MEM_ALLOCATOR */
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#ifndef __MEM_ALLOC_H
|
|
7
|
+
#define __MEM_ALLOC_H
|
|
8
|
+
|
|
9
|
+
#include "bh_platform.h"
|
|
10
|
+
#if WASM_ENABLE_GC != 0
|
|
11
|
+
#include "../../common/gc/gc_object.h"
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#ifdef __cplusplus
|
|
15
|
+
extern "C" {
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
typedef void *mem_allocator_t;
|
|
19
|
+
|
|
20
|
+
#ifndef GC_FINALIZER_T_DEFINED
|
|
21
|
+
#define GC_FINALIZER_T_DEFINED
|
|
22
|
+
typedef void (*gc_finalizer_t)(void *obj, void *data);
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
mem_allocator_t
|
|
26
|
+
mem_allocator_create(void *mem, uint32_t size);
|
|
27
|
+
|
|
28
|
+
mem_allocator_t
|
|
29
|
+
mem_allocator_create_with_struct_and_pool(void *struct_buf,
|
|
30
|
+
uint32_t struct_buf_size,
|
|
31
|
+
void *pool_buf,
|
|
32
|
+
uint32_t pool_buf_size);
|
|
33
|
+
|
|
34
|
+
int
|
|
35
|
+
mem_allocator_destroy(mem_allocator_t allocator);
|
|
36
|
+
|
|
37
|
+
uint32
|
|
38
|
+
mem_allocator_get_heap_struct_size(void);
|
|
39
|
+
|
|
40
|
+
void *
|
|
41
|
+
mem_allocator_malloc(mem_allocator_t allocator, uint32_t size);
|
|
42
|
+
|
|
43
|
+
void *
|
|
44
|
+
mem_allocator_realloc(mem_allocator_t allocator, void *ptr, uint32_t size);
|
|
45
|
+
|
|
46
|
+
void
|
|
47
|
+
mem_allocator_free(mem_allocator_t allocator, void *ptr);
|
|
48
|
+
|
|
49
|
+
int
|
|
50
|
+
mem_allocator_migrate(mem_allocator_t allocator, char *pool_buf_new,
|
|
51
|
+
uint32 pool_buf_size);
|
|
52
|
+
|
|
53
|
+
bool
|
|
54
|
+
mem_allocator_is_heap_corrupted(mem_allocator_t allocator);
|
|
55
|
+
|
|
56
|
+
#if WASM_ENABLE_GC != 0
|
|
57
|
+
void *
|
|
58
|
+
mem_allocator_malloc_with_gc(mem_allocator_t allocator, uint32_t size);
|
|
59
|
+
|
|
60
|
+
#if WASM_GC_MANUALLY != 0
|
|
61
|
+
void
|
|
62
|
+
mem_allocator_free_with_gc(mem_allocator_t allocator, void *ptr);
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
#if WASM_ENABLE_THREAD_MGR == 0
|
|
66
|
+
void
|
|
67
|
+
mem_allocator_enable_gc_reclaim(mem_allocator_t allocator, void *exec_env);
|
|
68
|
+
#else
|
|
69
|
+
void
|
|
70
|
+
mem_allocator_enable_gc_reclaim(mem_allocator_t allocator, void *cluster);
|
|
71
|
+
#endif
|
|
72
|
+
|
|
73
|
+
int
|
|
74
|
+
mem_allocator_add_root(mem_allocator_t allocator, WASMObjectRef obj);
|
|
75
|
+
|
|
76
|
+
bool
|
|
77
|
+
mem_allocator_set_gc_finalizer(mem_allocator_t allocator, void *obj,
|
|
78
|
+
gc_finalizer_t cb, void *data);
|
|
79
|
+
|
|
80
|
+
void
|
|
81
|
+
mem_allocator_unset_gc_finalizer(mem_allocator_t allocator, void *obj);
|
|
82
|
+
|
|
83
|
+
#if WASM_ENABLE_GC_PERF_PROFILING != 0
|
|
84
|
+
void
|
|
85
|
+
mem_allocator_dump_perf_profiling(mem_allocator_t allocator);
|
|
86
|
+
#endif
|
|
87
|
+
#endif /* end of WASM_ENABLE_GC != 0 */
|
|
88
|
+
|
|
89
|
+
bool
|
|
90
|
+
mem_allocator_get_alloc_info(mem_allocator_t allocator, void *mem_alloc_info);
|
|
91
|
+
|
|
92
|
+
#ifdef __cplusplus
|
|
93
|
+
}
|
|
94
|
+
#endif
|
|
95
|
+
|
|
96
|
+
#endif /* #ifndef __MEM_ALLOC_H */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024 Amazon Inc. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include "platform_api_vmcore.h"
|
|
7
|
+
|
|
8
|
+
void *
|
|
9
|
+
os_mremap(void *old_addr, size_t old_size, size_t new_size)
|
|
10
|
+
{
|
|
11
|
+
return os_mremap_slow(old_addr, old_size, new_size);
|
|
12
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2023 Midokura Japan KK. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include "platform_api_extension.h"
|
|
7
|
+
|
|
8
|
+
#ifdef OS_ENABLE_WAKEUP_BLOCKING_OP
|
|
9
|
+
|
|
10
|
+
static bool g_blocking_op_inited = false;
|
|
11
|
+
static int g_blocking_op_signo = SIGUSR1;
|
|
12
|
+
static sigset_t g_blocking_op_sigmask;
|
|
13
|
+
|
|
14
|
+
static void
|
|
15
|
+
blocking_op_sighandler(int signo)
|
|
16
|
+
{
|
|
17
|
+
/* nothing */
|
|
18
|
+
(void)signo;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
void
|
|
22
|
+
os_set_signal_number_for_blocking_op(int signo)
|
|
23
|
+
{
|
|
24
|
+
g_blocking_op_signo = signo;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
int
|
|
28
|
+
os_blocking_op_init()
|
|
29
|
+
{
|
|
30
|
+
if (g_blocking_op_inited) {
|
|
31
|
+
return BHT_OK;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
sigemptyset(&g_blocking_op_sigmask);
|
|
35
|
+
sigaddset(&g_blocking_op_sigmask, g_blocking_op_signo);
|
|
36
|
+
|
|
37
|
+
struct sigaction sa;
|
|
38
|
+
sigemptyset(&sa.sa_mask);
|
|
39
|
+
sa.sa_flags = 0;
|
|
40
|
+
sa.sa_handler = blocking_op_sighandler;
|
|
41
|
+
if (sigaction(g_blocking_op_signo, &sa, NULL)) {
|
|
42
|
+
return BHT_ERROR;
|
|
43
|
+
}
|
|
44
|
+
g_blocking_op_inited = true;
|
|
45
|
+
return BHT_OK;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
void
|
|
49
|
+
os_begin_blocking_op()
|
|
50
|
+
{
|
|
51
|
+
pthread_sigmask(SIG_UNBLOCK, &g_blocking_op_sigmask, NULL);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
void
|
|
55
|
+
os_end_blocking_op()
|
|
56
|
+
{
|
|
57
|
+
pthread_sigmask(SIG_BLOCK, &g_blocking_op_sigmask, NULL);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
int
|
|
61
|
+
os_wakeup_blocking_op(korp_tid tid)
|
|
62
|
+
{
|
|
63
|
+
int ret = pthread_kill(tid, g_blocking_op_signo);
|
|
64
|
+
if (ret != 0) {
|
|
65
|
+
return BHT_ERROR;
|
|
66
|
+
}
|
|
67
|
+
return BHT_OK;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#endif /* OS_ENABLE_WAKEUP_BLOCKING_OP */
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include "platform_api_vmcore.h"
|
|
7
|
+
|
|
8
|
+
void *
|
|
9
|
+
os_malloc(unsigned size)
|
|
10
|
+
{
|
|
11
|
+
return malloc(size);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
void *
|
|
15
|
+
os_realloc(void *ptr, unsigned size)
|
|
16
|
+
{
|
|
17
|
+
return realloc(ptr, size);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void
|
|
21
|
+
os_free(void *ptr)
|
|
22
|
+
{
|
|
23
|
+
free(ptr);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
int
|
|
27
|
+
os_dumps_proc_mem_info(char *out, unsigned int size)
|
|
28
|
+
{
|
|
29
|
+
int ret = -1;
|
|
30
|
+
FILE *f;
|
|
31
|
+
char line[128] = { 0 };
|
|
32
|
+
unsigned int out_idx = 0;
|
|
33
|
+
|
|
34
|
+
if (!out || !size)
|
|
35
|
+
goto quit;
|
|
36
|
+
|
|
37
|
+
f = fopen("/proc/self/status", "r");
|
|
38
|
+
if (!f) {
|
|
39
|
+
perror("fopen failed: ");
|
|
40
|
+
goto quit;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
memset(out, 0, size);
|
|
44
|
+
|
|
45
|
+
while (fgets(line, sizeof(line), f)) {
|
|
46
|
+
#if WASM_ENABLE_MEMORY_PROFILING != 0
|
|
47
|
+
if (strncmp(line, "Vm", 2) == 0 || strncmp(line, "Rss", 3) == 0) {
|
|
48
|
+
#else
|
|
49
|
+
if (strncmp(line, "VmRSS", 5) == 0
|
|
50
|
+
|| strncmp(line, "RssAnon", 7) == 0) {
|
|
51
|
+
#endif
|
|
52
|
+
size_t line_len = strlen(line);
|
|
53
|
+
if (line_len >= size - 1 - out_idx)
|
|
54
|
+
goto close_file;
|
|
55
|
+
|
|
56
|
+
/* copying without null-terminated byte */
|
|
57
|
+
memcpy(out + out_idx, line, line_len);
|
|
58
|
+
out_idx += line_len;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (ferror(f)) {
|
|
63
|
+
perror("fgets failed: ");
|
|
64
|
+
goto close_file;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
ret = 0;
|
|
68
|
+
close_file:
|
|
69
|
+
fclose(f);
|
|
70
|
+
quit:
|
|
71
|
+
return ret;
|
|
72
|
+
}
|