krillplayer-plugin 0.5.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 +2 -0
- package/dist/cli.js +397 -80
- package/dist/crypto.js +38 -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 +46 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live-selected-line-gone.json +46 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live.json +21 -1
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/plugin.ts +39 -4
- package/skill/krillplayer-plugin/references/cases.md +20 -2
- package/skill/krillplayer-plugin/references/contract.d.ts +114 -12
- package/skill/krillplayer-plugin/references/crypto-tools.md +104 -0
- package/skill/krillplayer-plugin/references/errors-and-fixes.md +5 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#ifndef _PLATFORM_INTERNAL_H
|
|
7
|
+
#define _PLATFORM_INTERNAL_H
|
|
8
|
+
|
|
9
|
+
#include <inttypes.h>
|
|
10
|
+
#include <stdbool.h>
|
|
11
|
+
#include <assert.h>
|
|
12
|
+
#include <time.h>
|
|
13
|
+
#include <string.h>
|
|
14
|
+
#include <stdio.h>
|
|
15
|
+
#include <stdlib.h>
|
|
16
|
+
#include <math.h>
|
|
17
|
+
#include <stdarg.h>
|
|
18
|
+
#include <ctype.h>
|
|
19
|
+
#include <pthread.h>
|
|
20
|
+
#include <signal.h>
|
|
21
|
+
#include <semaphore.h>
|
|
22
|
+
#include <limits.h>
|
|
23
|
+
#include <dirent.h>
|
|
24
|
+
#include <fcntl.h>
|
|
25
|
+
#include <unistd.h>
|
|
26
|
+
#include <poll.h>
|
|
27
|
+
#include <sched.h>
|
|
28
|
+
#include <errno.h>
|
|
29
|
+
#include <netinet/in.h>
|
|
30
|
+
#include <sys/types.h>
|
|
31
|
+
#include <sys/stat.h>
|
|
32
|
+
#include <sys/mman.h>
|
|
33
|
+
#include <sys/time.h>
|
|
34
|
+
#include <sys/timeb.h>
|
|
35
|
+
#include <sys/uio.h>
|
|
36
|
+
#include <sys/ioctl.h>
|
|
37
|
+
#include <sys/socket.h>
|
|
38
|
+
#include <sys/resource.h>
|
|
39
|
+
|
|
40
|
+
#ifdef __cplusplus
|
|
41
|
+
extern "C" {
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
#ifndef BH_PLATFORM_LINUX
|
|
45
|
+
#define BH_PLATFORM_LINUX
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
/* Stack size of applet threads's native part. */
|
|
49
|
+
#define BH_APPLET_PRESERVED_STACK_SIZE (32 * 1024)
|
|
50
|
+
|
|
51
|
+
/* Default thread priority */
|
|
52
|
+
#define BH_THREAD_DEFAULT_PRIORITY 0
|
|
53
|
+
|
|
54
|
+
typedef pthread_t korp_tid;
|
|
55
|
+
typedef pthread_mutex_t korp_mutex;
|
|
56
|
+
typedef pthread_cond_t korp_cond;
|
|
57
|
+
typedef pthread_t korp_thread;
|
|
58
|
+
typedef pthread_rwlock_t korp_rwlock;
|
|
59
|
+
typedef sem_t korp_sem;
|
|
60
|
+
|
|
61
|
+
#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
|
62
|
+
|
|
63
|
+
#define os_thread_local_attribute __thread
|
|
64
|
+
|
|
65
|
+
#define bh_socket_t int
|
|
66
|
+
|
|
67
|
+
#if WASM_DISABLE_WRITE_GS_BASE == 0
|
|
68
|
+
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
|
|
69
|
+
#define os_writegsbase(base_addr) \
|
|
70
|
+
do { \
|
|
71
|
+
uint64 __gs_value = (uint64)(uintptr_t)base_addr; \
|
|
72
|
+
asm volatile("wrgsbase %0" ::"r"(__gs_value) : "memory"); \
|
|
73
|
+
} while (0)
|
|
74
|
+
#if 0
|
|
75
|
+
/* _writegsbase_u64 also works, but need to add -mfsgsbase flag for gcc */
|
|
76
|
+
#include <immintrin.h>
|
|
77
|
+
#define os_writegsbase(base_addr) \
|
|
78
|
+
_writegsbase_u64(((uint64)(uintptr_t)base_addr))
|
|
79
|
+
#endif
|
|
80
|
+
#endif
|
|
81
|
+
#endif
|
|
82
|
+
|
|
83
|
+
#if WASM_DISABLE_HW_BOUND_CHECK == 0
|
|
84
|
+
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \
|
|
85
|
+
|| defined(BUILD_TARGET_AARCH64) || defined(BUILD_TARGET_RISCV64_LP64D) \
|
|
86
|
+
|| defined(BUILD_TARGET_RISCV64_LP64)
|
|
87
|
+
|
|
88
|
+
#include <setjmp.h>
|
|
89
|
+
|
|
90
|
+
#define OS_ENABLE_HW_BOUND_CHECK
|
|
91
|
+
|
|
92
|
+
typedef jmp_buf korp_jmpbuf;
|
|
93
|
+
|
|
94
|
+
#define os_setjmp setjmp
|
|
95
|
+
#define os_longjmp longjmp
|
|
96
|
+
#define os_alloca alloca
|
|
97
|
+
|
|
98
|
+
typedef void (*os_signal_handler)(void *sig_addr);
|
|
99
|
+
|
|
100
|
+
int
|
|
101
|
+
os_thread_signal_init(os_signal_handler handler);
|
|
102
|
+
|
|
103
|
+
void
|
|
104
|
+
os_thread_signal_destroy();
|
|
105
|
+
|
|
106
|
+
bool
|
|
107
|
+
os_thread_signal_inited();
|
|
108
|
+
|
|
109
|
+
void
|
|
110
|
+
os_signal_unmask();
|
|
111
|
+
|
|
112
|
+
void
|
|
113
|
+
os_sigreturn();
|
|
114
|
+
#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */
|
|
115
|
+
#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */
|
|
116
|
+
|
|
117
|
+
#define os_getpagesize getpagesize
|
|
118
|
+
|
|
119
|
+
#if WASM_DISABLE_WAKEUP_BLOCKING_OP == 0
|
|
120
|
+
#define OS_ENABLE_WAKEUP_BLOCKING_OP
|
|
121
|
+
#endif
|
|
122
|
+
void
|
|
123
|
+
os_set_signal_number_for_blocking_op(int signo);
|
|
124
|
+
|
|
125
|
+
typedef int os_file_handle;
|
|
126
|
+
typedef DIR *os_dir_stream;
|
|
127
|
+
typedef int os_raw_file_handle;
|
|
128
|
+
|
|
129
|
+
static inline os_file_handle
|
|
130
|
+
os_get_invalid_handle(void)
|
|
131
|
+
{
|
|
132
|
+
return -1;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#ifdef __cplusplus
|
|
136
|
+
}
|
|
137
|
+
#endif
|
|
138
|
+
|
|
139
|
+
#endif /* end of _PLATFORM_INTERNAL_H */
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include "bh_assert.h"
|
|
7
|
+
|
|
8
|
+
void
|
|
9
|
+
bh_assert_internal(int64 v, const char *file_name, int line_number,
|
|
10
|
+
const char *expr_string)
|
|
11
|
+
{
|
|
12
|
+
if (v)
|
|
13
|
+
return;
|
|
14
|
+
|
|
15
|
+
if (!file_name)
|
|
16
|
+
file_name = "NULL FILENAME";
|
|
17
|
+
|
|
18
|
+
if (!expr_string)
|
|
19
|
+
expr_string = "NULL EXPR_STRING";
|
|
20
|
+
|
|
21
|
+
LOG_ERROR("\nASSERTION FAILED: %s, at file %s, line %d\n", expr_string,
|
|
22
|
+
file_name, line_number);
|
|
23
|
+
|
|
24
|
+
abort();
|
|
25
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#ifndef _BH_ASSERT_H
|
|
7
|
+
#define _BH_ASSERT_H
|
|
8
|
+
|
|
9
|
+
#include "bh_platform.h"
|
|
10
|
+
|
|
11
|
+
#ifdef __cplusplus
|
|
12
|
+
extern "C" {
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
#if BH_DEBUG != 0
|
|
16
|
+
void
|
|
17
|
+
bh_assert_internal(int64 v, const char *file_name, int line_number,
|
|
18
|
+
const char *expr_string);
|
|
19
|
+
#define bh_assert(expr) \
|
|
20
|
+
bh_assert_internal((int64)(uintptr_t)(expr), __FILE__, __LINE__, #expr)
|
|
21
|
+
#else
|
|
22
|
+
#define bh_assert(expr) (void)0
|
|
23
|
+
#endif /* end of BH_DEBUG */
|
|
24
|
+
|
|
25
|
+
#if !defined(__has_extension)
|
|
26
|
+
#define __has_extension(a) 0
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \
|
|
30
|
+
|| (defined(__GNUC__) && __GNUC__ * 0x100 + __GNUC_MINOR__ >= 0x406) \
|
|
31
|
+
|| __has_extension(c_static_assert)
|
|
32
|
+
|
|
33
|
+
#define bh_static_assert(expr) _Static_assert(expr, #expr)
|
|
34
|
+
#else
|
|
35
|
+
#define bh_static_assert(expr) /* nothing */
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#ifdef __cplusplus
|
|
39
|
+
}
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
#endif /* end of _BH_ASSERT_H */
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2023 Amazon Inc. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#ifndef _BH_ATOMIC_H
|
|
7
|
+
#define _BH_ATOMIC_H
|
|
8
|
+
|
|
9
|
+
#include "bh_platform.h"
|
|
10
|
+
#include "gnuc.h"
|
|
11
|
+
|
|
12
|
+
#ifdef __cplusplus
|
|
13
|
+
extern "C" {
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* Why don't we use C11 stdatomics here?
|
|
18
|
+
*
|
|
19
|
+
* Unlike C11 stdatomics,
|
|
20
|
+
*
|
|
21
|
+
* - bh_atomic_xxx_t is guaranteed to have the same size as the base type.
|
|
22
|
+
* Thus more friendly to our AOT conventions.
|
|
23
|
+
*
|
|
24
|
+
* - It's available for C++.
|
|
25
|
+
* Although C++23 will have C-compatible stdatomics.h, it isn't widely
|
|
26
|
+
* available yet.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Note about BH_ATOMIC_32_IS_ATOMIC
|
|
31
|
+
*
|
|
32
|
+
* If BH_ATOMIC_32_IS_ATOMIC == 0, BH_ATOMIC_xxx operations defined below
|
|
33
|
+
* are not really atomic and require an external lock.
|
|
34
|
+
*
|
|
35
|
+
* Expected usage is:
|
|
36
|
+
*
|
|
37
|
+
* bh_atomic_32_t var = 0;
|
|
38
|
+
* uint32 old;
|
|
39
|
+
* #if BH_ATOMIC_32_IS_ATOMIC == 0
|
|
40
|
+
* lock(&some_lock);
|
|
41
|
+
* #endif
|
|
42
|
+
* old = BH_ATOMIC_32_FETCH_AND(var, 1);
|
|
43
|
+
* #if BH_ATOMIC_32_IS_ATOMIC == 0
|
|
44
|
+
* unlock(&some_lock);
|
|
45
|
+
* #endif
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
typedef uint64 bh_atomic_64_t;
|
|
49
|
+
typedef uint32 bh_atomic_32_t;
|
|
50
|
+
typedef uint16 bh_atomic_16_t;
|
|
51
|
+
|
|
52
|
+
/* The flag can be defined by the user if the platform
|
|
53
|
+
* supports atomic 32-bit operations.
|
|
54
|
+
* If left undefined, it will be automatically defined
|
|
55
|
+
* according to the platform.
|
|
56
|
+
*/
|
|
57
|
+
#ifdef WASM_UINT64_IS_ATOMIC
|
|
58
|
+
#define BH_ATOMIC_64_IS_ATOMIC WASM_UINT64_IS_ATOMIC
|
|
59
|
+
#endif /* WASM_UINT64_IS_ATOMIC */
|
|
60
|
+
|
|
61
|
+
#ifdef WASM_UINT32_IS_ATOMIC
|
|
62
|
+
#define BH_ATOMIC_32_IS_ATOMIC WASM_UINT32_IS_ATOMIC
|
|
63
|
+
#endif /* WASM_UINT32_IS_ATOMIC */
|
|
64
|
+
|
|
65
|
+
#ifdef WASM_UINT16_IS_ATOMIC
|
|
66
|
+
#define BH_ATOMIC_16_IS_ATOMIC WASM_UINT16_IS_ATOMIC
|
|
67
|
+
#endif /* WASM_UINT16_IS_ATOMIC */
|
|
68
|
+
|
|
69
|
+
#if defined(__GNUC_PREREQ)
|
|
70
|
+
#if __GNUC_PREREQ(4, 7)
|
|
71
|
+
#define CLANG_GCC_HAS_ATOMIC_BUILTIN
|
|
72
|
+
#endif
|
|
73
|
+
#elif defined(__clang__)
|
|
74
|
+
#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0)
|
|
75
|
+
#define CLANG_GCC_HAS_ATOMIC_BUILTIN
|
|
76
|
+
#endif
|
|
77
|
+
#endif
|
|
78
|
+
|
|
79
|
+
#if defined(CLANG_GCC_HAS_ATOMIC_BUILTIN)
|
|
80
|
+
#ifndef BH_ATOMIC_64_IS_ATOMIC
|
|
81
|
+
#define BH_ATOMIC_64_IS_ATOMIC 1
|
|
82
|
+
#endif
|
|
83
|
+
#ifndef BH_ATOMIC_32_IS_ATOMIC
|
|
84
|
+
#define BH_ATOMIC_32_IS_ATOMIC 1
|
|
85
|
+
#endif
|
|
86
|
+
#ifndef BH_ATOMIC_16_IS_ATOMIC
|
|
87
|
+
#define BH_ATOMIC_16_IS_ATOMIC 1
|
|
88
|
+
#endif
|
|
89
|
+
#else
|
|
90
|
+
#ifndef BH_ATOMIC_64_IS_ATOMIC
|
|
91
|
+
#define BH_ATOMIC_64_IS_ATOMIC 0
|
|
92
|
+
#endif
|
|
93
|
+
#ifndef BH_ATOMIC_32_IS_ATOMIC
|
|
94
|
+
#define BH_ATOMIC_32_IS_ATOMIC 0
|
|
95
|
+
#endif
|
|
96
|
+
#ifndef BH_ATOMIC_16_IS_ATOMIC
|
|
97
|
+
#define BH_ATOMIC_16_IS_ATOMIC 0
|
|
98
|
+
#endif
|
|
99
|
+
#endif
|
|
100
|
+
|
|
101
|
+
/* Force disable atomic 16-bit operations on bare-metal RISC-V
|
|
102
|
+
* because the 16-bit atomic operations is emulated by 32-bit
|
|
103
|
+
* atomic operations, which has linkage problem on current toolchain:
|
|
104
|
+
* in function `shared_memory_inc_reference':
|
|
105
|
+
* wasm_shared_memory.c:85:(.text.shared_memory_inc_reference+0x10): undefined
|
|
106
|
+
* reference to `__atomic_fetch_add_2'
|
|
107
|
+
*/
|
|
108
|
+
#ifndef WASM_UINT16_IS_ATOMIC
|
|
109
|
+
#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) \
|
|
110
|
+
&& !defined(__OpenBSD__) && defined(__riscv)
|
|
111
|
+
#undef BH_ATOMIC_16_IS_ATOMIC
|
|
112
|
+
#define BH_ATOMIC_16_IS_ATOMIC 0
|
|
113
|
+
#endif
|
|
114
|
+
#endif
|
|
115
|
+
|
|
116
|
+
/* On some 32-bit platform, disable 64-bit atomic operations, otherwise
|
|
117
|
+
* undefined reference to `__atomic_load_8', if on Zephyr, can add board related
|
|
118
|
+
* macro in autoconf.h to control */
|
|
119
|
+
#ifndef WASM_UINT64_IS_ATOMIC
|
|
120
|
+
#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) \
|
|
121
|
+
&& !defined(__OpenBSD__) && (defined(__riscv) || defined(__arm__)) \
|
|
122
|
+
&& UINT32_MAX == UINTPTR_MAX
|
|
123
|
+
#undef BH_ATOMIC_64_IS_ATOMIC
|
|
124
|
+
#define BH_ATOMIC_64_IS_ATOMIC 0
|
|
125
|
+
#endif
|
|
126
|
+
#endif
|
|
127
|
+
|
|
128
|
+
#if BH_ATOMIC_64_IS_ATOMIC != 0
|
|
129
|
+
|
|
130
|
+
#define BH_ATOMIC_64_LOAD(v) __atomic_load_n(&(v), __ATOMIC_SEQ_CST)
|
|
131
|
+
#define BH_ATOMIC_64_STORE(v, val) __atomic_store_n(&(v), val, __ATOMIC_SEQ_CST)
|
|
132
|
+
#define BH_ATOMIC_64_FETCH_OR(v, val) \
|
|
133
|
+
__atomic_fetch_or(&(v), (val), __ATOMIC_SEQ_CST)
|
|
134
|
+
#define BH_ATOMIC_64_FETCH_AND(v, val) \
|
|
135
|
+
__atomic_fetch_and(&(v), (val), __ATOMIC_SEQ_CST)
|
|
136
|
+
#define BH_ATOMIC_64_FETCH_ADD(v, val) \
|
|
137
|
+
__atomic_fetch_add(&(v), (val), __ATOMIC_SEQ_CST)
|
|
138
|
+
#define BH_ATOMIC_64_FETCH_SUB(v, val) \
|
|
139
|
+
__atomic_fetch_sub(&(v), (val), __ATOMIC_SEQ_CST)
|
|
140
|
+
|
|
141
|
+
#else /* else of BH_ATOMIC_64_IS_ATOMIC != 0 */
|
|
142
|
+
|
|
143
|
+
#define BH_ATOMIC_64_LOAD(v) (v)
|
|
144
|
+
#define BH_ATOMIC_64_STORE(v, val) (v) = val
|
|
145
|
+
#define BH_ATOMIC_64_FETCH_OR(v, val) nonatomic_64_fetch_or(&(v), val)
|
|
146
|
+
#define BH_ATOMIC_64_FETCH_AND(v, val) nonatomic_64_fetch_and(&(v), val)
|
|
147
|
+
#define BH_ATOMIC_64_FETCH_ADD(v, val) nonatomic_64_fetch_add(&(v), val)
|
|
148
|
+
#define BH_ATOMIC_64_FETCH_SUB(v, val) nonatomic_64_fetch_sub(&(v), val)
|
|
149
|
+
|
|
150
|
+
static inline uint64
|
|
151
|
+
nonatomic_64_fetch_or(bh_atomic_64_t *p, uint64 val)
|
|
152
|
+
{
|
|
153
|
+
uint64 old = *p;
|
|
154
|
+
*p |= val;
|
|
155
|
+
return old;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static inline uint64
|
|
159
|
+
nonatomic_64_fetch_and(bh_atomic_64_t *p, uint64 val)
|
|
160
|
+
{
|
|
161
|
+
uint64 old = *p;
|
|
162
|
+
*p &= val;
|
|
163
|
+
return old;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
static inline uint64
|
|
167
|
+
nonatomic_64_fetch_add(bh_atomic_64_t *p, uint64 val)
|
|
168
|
+
{
|
|
169
|
+
uint64 old = *p;
|
|
170
|
+
*p += val;
|
|
171
|
+
return old;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static inline uint64
|
|
175
|
+
nonatomic_64_fetch_sub(bh_atomic_64_t *p, uint64 val)
|
|
176
|
+
{
|
|
177
|
+
uint64 old = *p;
|
|
178
|
+
*p -= val;
|
|
179
|
+
return old;
|
|
180
|
+
}
|
|
181
|
+
#endif
|
|
182
|
+
|
|
183
|
+
#if BH_ATOMIC_32_IS_ATOMIC != 0
|
|
184
|
+
|
|
185
|
+
#define BH_ATOMIC_32_LOAD(v) __atomic_load_n(&(v), __ATOMIC_SEQ_CST)
|
|
186
|
+
#define BH_ATOMIC_32_STORE(v, val) __atomic_store_n(&(v), val, __ATOMIC_SEQ_CST)
|
|
187
|
+
#define BH_ATOMIC_32_FETCH_OR(v, val) \
|
|
188
|
+
__atomic_fetch_or(&(v), (val), __ATOMIC_SEQ_CST)
|
|
189
|
+
#define BH_ATOMIC_32_FETCH_AND(v, val) \
|
|
190
|
+
__atomic_fetch_and(&(v), (val), __ATOMIC_SEQ_CST)
|
|
191
|
+
#define BH_ATOMIC_32_FETCH_ADD(v, val) \
|
|
192
|
+
__atomic_fetch_add(&(v), (val), __ATOMIC_SEQ_CST)
|
|
193
|
+
#define BH_ATOMIC_32_FETCH_SUB(v, val) \
|
|
194
|
+
__atomic_fetch_sub(&(v), (val), __ATOMIC_SEQ_CST)
|
|
195
|
+
|
|
196
|
+
#else /* else of BH_ATOMIC_32_IS_ATOMIC != 0 */
|
|
197
|
+
|
|
198
|
+
#define BH_ATOMIC_32_LOAD(v) (v)
|
|
199
|
+
#define BH_ATOMIC_32_STORE(v, val) (v) = val
|
|
200
|
+
#define BH_ATOMIC_32_FETCH_OR(v, val) nonatomic_32_fetch_or(&(v), val)
|
|
201
|
+
#define BH_ATOMIC_32_FETCH_AND(v, val) nonatomic_32_fetch_and(&(v), val)
|
|
202
|
+
#define BH_ATOMIC_32_FETCH_ADD(v, val) nonatomic_32_fetch_add(&(v), val)
|
|
203
|
+
#define BH_ATOMIC_32_FETCH_SUB(v, val) nonatomic_32_fetch_sub(&(v), val)
|
|
204
|
+
|
|
205
|
+
static inline uint32
|
|
206
|
+
nonatomic_32_fetch_or(bh_atomic_32_t *p, uint32 val)
|
|
207
|
+
{
|
|
208
|
+
uint32 old = *p;
|
|
209
|
+
*p |= val;
|
|
210
|
+
return old;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
static inline uint32
|
|
214
|
+
nonatomic_32_fetch_and(bh_atomic_32_t *p, uint32 val)
|
|
215
|
+
{
|
|
216
|
+
uint32 old = *p;
|
|
217
|
+
*p &= val;
|
|
218
|
+
return old;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
static inline uint32
|
|
222
|
+
nonatomic_32_fetch_add(bh_atomic_32_t *p, uint32 val)
|
|
223
|
+
{
|
|
224
|
+
uint32 old = *p;
|
|
225
|
+
*p += val;
|
|
226
|
+
return old;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
static inline uint32
|
|
230
|
+
nonatomic_32_fetch_sub(bh_atomic_32_t *p, uint32 val)
|
|
231
|
+
{
|
|
232
|
+
uint32 old = *p;
|
|
233
|
+
*p -= val;
|
|
234
|
+
return old;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
#endif
|
|
238
|
+
|
|
239
|
+
#if BH_ATOMIC_16_IS_ATOMIC != 0
|
|
240
|
+
|
|
241
|
+
#define BH_ATOMIC_16_IS_ATOMIC 1
|
|
242
|
+
#define BH_ATOMIC_16_LOAD(v) __atomic_load_n(&(v), __ATOMIC_SEQ_CST)
|
|
243
|
+
#define BH_ATOMIC_16_STORE(v, val) __atomic_store_n(&(v), val, __ATOMIC_SEQ_CST)
|
|
244
|
+
#define BH_ATOMIC_16_FETCH_OR(v, val) \
|
|
245
|
+
__atomic_fetch_or(&(v), (val), __ATOMIC_SEQ_CST)
|
|
246
|
+
#define BH_ATOMIC_16_FETCH_AND(v, val) \
|
|
247
|
+
__atomic_fetch_and(&(v), (val), __ATOMIC_SEQ_CST)
|
|
248
|
+
#define BH_ATOMIC_16_FETCH_ADD(v, val) \
|
|
249
|
+
__atomic_fetch_add(&(v), (val), __ATOMIC_SEQ_CST)
|
|
250
|
+
#define BH_ATOMIC_16_FETCH_SUB(v, val) \
|
|
251
|
+
__atomic_fetch_sub(&(v), (val), __ATOMIC_SEQ_CST)
|
|
252
|
+
|
|
253
|
+
#else /* else of BH_ATOMIC_16_IS_ATOMIC != 0 */
|
|
254
|
+
|
|
255
|
+
#define BH_ATOMIC_16_LOAD(v) (v)
|
|
256
|
+
#define BH_ATOMIC_16_STORE(v) (v) = val
|
|
257
|
+
#define BH_ATOMIC_16_FETCH_OR(v, val) nonatomic_16_fetch_or(&(v), val)
|
|
258
|
+
#define BH_ATOMIC_16_FETCH_AND(v, val) nonatomic_16_fetch_and(&(v), val)
|
|
259
|
+
#define BH_ATOMIC_16_FETCH_ADD(v, val) nonatomic_16_fetch_add(&(v), val)
|
|
260
|
+
#define BH_ATOMIC_16_FETCH_SUB(v, val) nonatomic_16_fetch_sub(&(v), val)
|
|
261
|
+
|
|
262
|
+
static inline uint16
|
|
263
|
+
nonatomic_16_fetch_or(bh_atomic_16_t *p, uint16 val)
|
|
264
|
+
{
|
|
265
|
+
uint16 old = *p;
|
|
266
|
+
*p |= val;
|
|
267
|
+
return old;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
static inline uint16
|
|
271
|
+
nonatomic_16_fetch_and(bh_atomic_16_t *p, uint16 val)
|
|
272
|
+
{
|
|
273
|
+
uint16 old = *p;
|
|
274
|
+
*p &= val;
|
|
275
|
+
return old;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
static inline uint16
|
|
279
|
+
nonatomic_16_fetch_add(bh_atomic_16_t *p, uint16 val)
|
|
280
|
+
{
|
|
281
|
+
uint16 old = *p;
|
|
282
|
+
*p += val;
|
|
283
|
+
return old;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
static inline uint16
|
|
287
|
+
nonatomic_16_fetch_sub(bh_atomic_16_t *p, uint16 val)
|
|
288
|
+
{
|
|
289
|
+
uint16 old = *p;
|
|
290
|
+
*p -= val;
|
|
291
|
+
return old;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
#endif
|
|
295
|
+
|
|
296
|
+
#ifdef __cplusplus
|
|
297
|
+
}
|
|
298
|
+
#endif
|
|
299
|
+
|
|
300
|
+
#endif /* end of _BH_ATOMIC_H */
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2021 Intel Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include "bh_bitmap.h"
|
|
7
|
+
|
|
8
|
+
bh_bitmap *
|
|
9
|
+
bh_bitmap_new(uintptr_t begin_index, unsigned bitnum)
|
|
10
|
+
{
|
|
11
|
+
bh_bitmap *bitmap;
|
|
12
|
+
uint32 bitmap_size = (bitnum + 7) / 8;
|
|
13
|
+
uint32 total_size = offsetof(bh_bitmap, map) + bitmap_size;
|
|
14
|
+
|
|
15
|
+
if (bitnum > UINT32_MAX - 7 || total_size < offsetof(bh_bitmap, map)
|
|
16
|
+
|| (total_size - offsetof(bh_bitmap, map)) != bitmap_size) {
|
|
17
|
+
return NULL; /* integer overflow */
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if ((bitmap = BH_MALLOC(total_size)) != NULL) {
|
|
21
|
+
memset(bitmap, 0, total_size);
|
|
22
|
+
bitmap->begin_index = begin_index;
|
|
23
|
+
bitmap->end_index = begin_index + bitnum;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return bitmap;
|
|
27
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2021 Intel Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#ifndef _BH_BITMAP_H
|
|
7
|
+
#define _BH_BITMAP_H
|
|
8
|
+
|
|
9
|
+
#include "bh_platform.h"
|
|
10
|
+
|
|
11
|
+
#ifdef __cplusplus
|
|
12
|
+
extern "C" {
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A simple fixed size bitmap.
|
|
17
|
+
*/
|
|
18
|
+
typedef struct bh_bitmap {
|
|
19
|
+
/* The first valid bit index. */
|
|
20
|
+
uintptr_t begin_index;
|
|
21
|
+
|
|
22
|
+
/* The last valid bit index plus one. */
|
|
23
|
+
uintptr_t end_index;
|
|
24
|
+
|
|
25
|
+
/* The bitmap. */
|
|
26
|
+
uint8 map[1];
|
|
27
|
+
} bh_bitmap;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create a new bitmap.
|
|
31
|
+
*
|
|
32
|
+
* @param begin_index the first valid bit index
|
|
33
|
+
* @param bitnum maximal bit number of the bitmap.
|
|
34
|
+
*
|
|
35
|
+
* @return the new bitmap if succeeds, NULL otherwise.
|
|
36
|
+
*/
|
|
37
|
+
bh_bitmap *
|
|
38
|
+
bh_bitmap_new(uintptr_t begin_index, unsigned bitnum);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Delete a bitmap.
|
|
42
|
+
*
|
|
43
|
+
* @param bitmap the bitmap to be deleted
|
|
44
|
+
*/
|
|
45
|
+
static inline void
|
|
46
|
+
bh_bitmap_delete(bh_bitmap *bitmap)
|
|
47
|
+
{
|
|
48
|
+
if (bitmap != NULL)
|
|
49
|
+
BH_FREE(bitmap);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Check whether the given index is in the range of the bitmap.
|
|
54
|
+
*
|
|
55
|
+
* @param bitmap the bitmap
|
|
56
|
+
* @param n the bit index
|
|
57
|
+
*
|
|
58
|
+
* @return true if the index is in range, false otherwise
|
|
59
|
+
*/
|
|
60
|
+
static inline bool
|
|
61
|
+
bh_bitmap_is_in_range(bh_bitmap *bitmap, uintptr_t n)
|
|
62
|
+
{
|
|
63
|
+
return n >= bitmap->begin_index && n < bitmap->end_index;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get a bit in the bitmap
|
|
68
|
+
*
|
|
69
|
+
* @param bitmap the bitmap
|
|
70
|
+
* @param n the n-th bit to be get
|
|
71
|
+
*
|
|
72
|
+
* @return value of the bit
|
|
73
|
+
*/
|
|
74
|
+
static inline int
|
|
75
|
+
bh_bitmap_get_bit(bh_bitmap *bitmap, uintptr_t n)
|
|
76
|
+
{
|
|
77
|
+
uintptr_t idx = n - bitmap->begin_index;
|
|
78
|
+
bh_assert(n >= bitmap->begin_index && n < bitmap->end_index);
|
|
79
|
+
return (bitmap->map[idx / 8] >> (idx % 8)) & 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Set a bit in the bitmap.
|
|
84
|
+
*
|
|
85
|
+
* @param bitmap the bitmap
|
|
86
|
+
* @param n the n-th bit to be set
|
|
87
|
+
*/
|
|
88
|
+
static inline void
|
|
89
|
+
bh_bitmap_set_bit(bh_bitmap *bitmap, uintptr_t n)
|
|
90
|
+
{
|
|
91
|
+
uintptr_t idx = n - bitmap->begin_index;
|
|
92
|
+
bh_assert(n >= bitmap->begin_index && n < bitmap->end_index);
|
|
93
|
+
bitmap->map[idx / 8] |= 1 << (idx % 8);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Clear a bit in the bitmap.
|
|
98
|
+
*
|
|
99
|
+
* @param bitmap the bitmap
|
|
100
|
+
* @param n the n-th bit to be cleared
|
|
101
|
+
*/
|
|
102
|
+
static inline void
|
|
103
|
+
bh_bitmap_clear_bit(bh_bitmap *bitmap, uintptr_t n)
|
|
104
|
+
{
|
|
105
|
+
uintptr_t idx = n - bitmap->begin_index;
|
|
106
|
+
bh_assert(n >= bitmap->begin_index && n < bitmap->end_index);
|
|
107
|
+
bitmap->map[idx / 8] &= ~(1 << (idx % 8));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#ifdef __cplusplus
|
|
111
|
+
}
|
|
112
|
+
#endif
|
|
113
|
+
|
|
114
|
+
#endif
|