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.
Files changed (150) hide show
  1. package/LICENSE +2 -1
  2. package/README.md +2 -0
  3. package/dist/cli.js +397 -80
  4. package/dist/crypto.js +38 -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 +46 -0
  144. package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live-selected-line-gone.json +46 -0
  145. package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live.json +21 -1
  146. package/skill/krillplayer-plugin/assets/samples/live-video-platform/plugin.ts +39 -4
  147. package/skill/krillplayer-plugin/references/cases.md +20 -2
  148. package/skill/krillplayer-plugin/references/contract.d.ts +114 -12
  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,168 @@
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_HASHMAP_H
7
+ #define WASM_HASHMAP_H
8
+
9
+ #include "bh_platform.h"
10
+
11
+ #ifdef __cplusplus
12
+ extern "C" {
13
+ #endif
14
+
15
+ /* Minimum initial size of hash map */
16
+ #define HASH_MAP_MIN_SIZE 4
17
+
18
+ /* Maximum initial size of hash map */
19
+ #define HASH_MAP_MAX_SIZE 65536
20
+
21
+ struct HashMap;
22
+ typedef struct HashMap HashMap;
23
+
24
+ /* Hash function: to get the hash value of key. */
25
+ typedef uint32 (*HashFunc)(const void *key);
26
+
27
+ /* Key equal function: to check whether two keys are equal. */
28
+ typedef bool (*KeyEqualFunc)(void *key1, void *key2);
29
+
30
+ /* Key destroy function: to destroy the key, auto called
31
+ for each key when the hash map is destroyed. */
32
+ typedef void (*KeyDestroyFunc)(void *key);
33
+
34
+ /* Value destroy function: to destroy the value, auto called
35
+ for each value when the hash map is destroyed. */
36
+ typedef void (*ValueDestroyFunc)(void *value);
37
+
38
+ /* traverse callback function:
39
+ auto called when traverse every hash element */
40
+ typedef void (*TraverseCallbackFunc)(void *key, void *value, void *user_data);
41
+
42
+ /**
43
+ * Create a hash map.
44
+ *
45
+ * @param size: the initial size of the hash map
46
+ * @param use_lock whether to lock the hash map when operating on it
47
+ * @param hash_func hash function of the key, must be specified
48
+ * @param key_equal_func key equal function, check whether two keys
49
+ * are equal, must be specified
50
+ * @param key_destroy_func key destroy function, called for each key if not NULL
51
+ * when the hash map is destroyed
52
+ * @param value_destroy_func value destroy function, called for each value if
53
+ * not NULL when the hash map is destroyed
54
+ *
55
+ * @return the hash map created, NULL if failed
56
+ */
57
+ HashMap *
58
+ bh_hash_map_create(uint32 size, bool use_lock, HashFunc hash_func,
59
+ KeyEqualFunc key_equal_func, KeyDestroyFunc key_destroy_func,
60
+ ValueDestroyFunc value_destroy_func);
61
+
62
+ /**
63
+ * Insert an element to the hash map
64
+ *
65
+ * @param map the hash map to insert element
66
+ * @key the key of the element
67
+ * @value the value of the element
68
+ *
69
+ * @return true if success, false otherwise
70
+ * Note: fail if key is NULL or duplicated key exists in the hash map,
71
+ */
72
+ bool
73
+ bh_hash_map_insert(HashMap *map, void *key, void *value);
74
+
75
+ /**
76
+ * Find an element in the hash map
77
+ *
78
+ * @param map the hash map to find element
79
+ * @key the key of the element
80
+ *
81
+ * @return the value of the found element if success, NULL otherwise
82
+ */
83
+ void *
84
+ bh_hash_map_find(HashMap *map, void *key);
85
+
86
+ /**
87
+ * Update an element in the hash map with new value
88
+ *
89
+ * @param map the hash map to update element
90
+ * @key the key of the element
91
+ * @value the new value of the element
92
+ * @p_old_value if not NULL, copies the old value to it
93
+ *
94
+ * @return true if success, false otherwise
95
+ * Note: the old value won't be destroyed by value destroy function,
96
+ * it will be copied to p_old_value for user to process.
97
+ */
98
+ bool
99
+ bh_hash_map_update(HashMap *map, void *key, void *value, void **p_old_value);
100
+
101
+ /**
102
+ * Remove an element from the hash map
103
+ *
104
+ * @param map the hash map to remove element
105
+ * @key the key of the element
106
+ * @p_old_key if not NULL, copies the old key to it
107
+ * @p_old_value if not NULL, copies the old value to it
108
+ *
109
+ * @return true if success, false otherwise
110
+ * Note: the old key and old value won't be destroyed by key destroy
111
+ * function and value destroy function, they will be copied to
112
+ * p_old_key and p_old_value for user to process.
113
+ */
114
+ bool
115
+ bh_hash_map_remove(HashMap *map, void *key, void **p_old_key,
116
+ void **p_old_value);
117
+
118
+ /**
119
+ * Destroy the hashmap
120
+ *
121
+ * @param map the hash map to destroy
122
+ *
123
+ * @return true if success, false otherwise
124
+ * Note: the key destroy function and value destroy function will be
125
+ * called to destroy each element's key and value if they are
126
+ * not NULL.
127
+ */
128
+ bool
129
+ bh_hash_map_destroy(HashMap *map);
130
+
131
+ /**
132
+ * Get the structure size of HashMap
133
+ *
134
+ * @param map the hash map to calculate
135
+ *
136
+ * @return the memory space occupied by HashMap structure
137
+ */
138
+ uint32
139
+ bh_hash_map_get_struct_size(HashMap *hashmap);
140
+
141
+ /**
142
+ * Get the structure size of HashMap Element
143
+ *
144
+ * @return the memory space occupied by HashMapElem structure
145
+ */
146
+ uint32
147
+ bh_hash_map_get_elem_struct_size(void);
148
+
149
+ /**
150
+ * Traverse the hash map and call the callback function
151
+ *
152
+ * @param map the hash map to traverse
153
+ * @param callback the function to be called for every element
154
+ * @param user_data the argument to be passed to the callback function
155
+ *
156
+ * @return true if success, false otherwise
157
+ * Note: if the hash map has lock, the map will be locked during traverse,
158
+ * keep the callback function as simple as possible.
159
+ */
160
+ bool
161
+ bh_hash_map_traverse(HashMap *map, TraverseCallbackFunc callback,
162
+ void *user_data);
163
+
164
+ #ifdef __cplusplus
165
+ }
166
+ #endif
167
+
168
+ #endif /* endof WASM_HASHMAP_H */
@@ -0,0 +1,77 @@
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_leb128.h"
7
+
8
+ bh_leb_read_status_t
9
+ bh_leb_read(const uint8 *buf, const uint8 *buf_end, uint32 maxbits, bool sign,
10
+ uint64 *p_result, size_t *p_offset)
11
+ {
12
+ uint64 result = 0;
13
+ uint32 shift = 0;
14
+ uint32 offset = 0, bcnt = 0;
15
+ uint64 byte;
16
+
17
+ while (true) {
18
+ /* uN or SN must not exceed ceil(N/7) bytes */
19
+ if (bcnt + 1 > (maxbits + 6) / 7) {
20
+ return BH_LEB_READ_TOO_LONG;
21
+ }
22
+
23
+ if ((uintptr_t)buf + offset + 1 < (uintptr_t)buf
24
+ || (uintptr_t)buf + offset + 1 > (uintptr_t)buf_end) {
25
+ return BH_LEB_READ_UNEXPECTED_END;
26
+ }
27
+ byte = buf[offset];
28
+ offset += 1;
29
+ result |= ((byte & 0x7f) << shift);
30
+ shift += 7;
31
+ bcnt += 1;
32
+ if ((byte & 0x80) == 0) {
33
+ break;
34
+ }
35
+ }
36
+
37
+ if (!sign && maxbits == 32 && shift >= maxbits) {
38
+ /* The top bits set represent values > 32 bits */
39
+ if (((uint8)byte) & 0xf0)
40
+ return BH_LEB_READ_OVERFLOW;
41
+ }
42
+ else if (sign && maxbits == 32) {
43
+ if (shift < maxbits) {
44
+ /* Sign extend, second-highest bit is the sign bit */
45
+ if ((uint8)byte & 0x40)
46
+ result |= (~((uint64)0)) << shift;
47
+ }
48
+ else {
49
+ /* The top bits should be a sign-extension of the sign bit */
50
+ bool sign_bit_set = ((uint8)byte) & 0x8;
51
+ int top_bits = ((uint8)byte) & 0xf0;
52
+ if ((sign_bit_set && top_bits != 0x70)
53
+ || (!sign_bit_set && top_bits != 0))
54
+ return BH_LEB_READ_OVERFLOW;
55
+ }
56
+ }
57
+ else if (sign && maxbits == 64) {
58
+ if (shift < maxbits) {
59
+ /* Sign extend, second-highest bit is the sign bit */
60
+ if ((uint8)byte & 0x40)
61
+ result |= (~((uint64)0)) << shift;
62
+ }
63
+ else {
64
+ /* The top bits should be a sign-extension of the sign bit */
65
+ bool sign_bit_set = ((uint8)byte) & 0x1;
66
+ int top_bits = ((uint8)byte) & 0xfe;
67
+
68
+ if ((sign_bit_set && top_bits != 0x7e)
69
+ || (!sign_bit_set && top_bits != 0))
70
+ return BH_LEB_READ_OVERFLOW;
71
+ }
72
+ }
73
+
74
+ *p_offset = offset;
75
+ *p_result = result;
76
+ return BH_LEB_READ_SUCCESS;
77
+ }
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright (C) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
+ */
5
+
6
+ #ifndef _BH_LEB128_H
7
+ #define _BH_LEB128_H
8
+
9
+ #include "bh_platform.h"
10
+
11
+ typedef enum {
12
+ BH_LEB_READ_SUCCESS,
13
+ BH_LEB_READ_TOO_LONG,
14
+ BH_LEB_READ_OVERFLOW,
15
+ BH_LEB_READ_UNEXPECTED_END,
16
+ } bh_leb_read_status_t;
17
+
18
+ #ifdef __cplusplus
19
+ extern "C" {
20
+ #endif
21
+
22
+ bh_leb_read_status_t
23
+ bh_leb_read(const uint8 *buf, const uint8 *buf_end, uint32 maxbits, bool sign,
24
+ uint64 *p_result, size_t *p_offset);
25
+
26
+ #ifdef __cplusplus
27
+ }
28
+ #endif
29
+
30
+ #endif
@@ -0,0 +1,111 @@
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_list.h"
7
+
8
+ #if BH_DEBUG != 0
9
+ /**
10
+ * Test whether a pointer value has exist in given list.
11
+ *
12
+ * @param list pointer to list.
13
+ * @param elem pointer to elem that will be inserted into list.
14
+ * @return <code>true</code> if the pointer has been in the list;
15
+ * <code>false</code> otherwise.
16
+ */
17
+ static bool
18
+ bh_list_is_elem_exist(bh_list *list, void *elem);
19
+ #endif
20
+
21
+ bh_list_status
22
+ bh_list_init(bh_list *list)
23
+ {
24
+ if (!list)
25
+ return BH_LIST_ERROR;
26
+
27
+ (list->head).next = NULL;
28
+ list->len = 0;
29
+ return BH_LIST_SUCCESS;
30
+ }
31
+
32
+ bh_list_status
33
+ bh_list_insert(bh_list *list, void *elem)
34
+ {
35
+ bh_list_link *p = NULL;
36
+
37
+ if (!list || !elem)
38
+ return BH_LIST_ERROR;
39
+ #if BH_DEBUG != 0
40
+ bh_assert(!bh_list_is_elem_exist(list, elem));
41
+ #endif
42
+ p = (bh_list_link *)elem;
43
+ p->next = (list->head).next;
44
+ (list->head).next = p;
45
+ list->len++;
46
+ return BH_LIST_SUCCESS;
47
+ }
48
+
49
+ bh_list_status
50
+ bh_list_remove(bh_list *list, void *elem)
51
+ {
52
+ bh_list_link *cur = NULL;
53
+ bh_list_link *prev = NULL;
54
+
55
+ if (!list || !elem)
56
+ return BH_LIST_ERROR;
57
+
58
+ cur = (list->head).next;
59
+
60
+ while (cur) {
61
+ if (cur == elem) {
62
+ if (prev)
63
+ prev->next = cur->next;
64
+ else
65
+ (list->head).next = cur->next;
66
+
67
+ list->len--;
68
+ return BH_LIST_SUCCESS;
69
+ }
70
+
71
+ prev = cur;
72
+ cur = cur->next;
73
+ }
74
+
75
+ return BH_LIST_ERROR;
76
+ }
77
+
78
+ uint32
79
+ bh_list_length(bh_list *list)
80
+ {
81
+ return (list ? list->len : 0);
82
+ }
83
+
84
+ void *
85
+ bh_list_first_elem(bh_list *list)
86
+ {
87
+ return (list ? (list->head).next : NULL);
88
+ }
89
+
90
+ void *
91
+ bh_list_elem_next(void *node)
92
+ {
93
+ return (node ? ((bh_list_link *)node)->next : NULL);
94
+ }
95
+
96
+ #if BH_DEBUG != 0
97
+ static bool
98
+ bh_list_is_elem_exist(bh_list *list, void *elem)
99
+ {
100
+ bh_list_link *p = NULL;
101
+
102
+ if (!list || !elem)
103
+ return false;
104
+
105
+ p = (list->head).next;
106
+ while (p && p != elem)
107
+ p = p->next;
108
+
109
+ return (p != NULL);
110
+ }
111
+ #endif
@@ -0,0 +1,109 @@
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_LIST_H
7
+ #define _BH_LIST_H
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ #include "bh_platform.h"
14
+
15
+ /* List user should embedded bh_list_link into list elem data structure
16
+ * definition. And bh_list_link data field should be the first field.
17
+ * For example, if we would like to use bh_list for our own data type A,
18
+ * A must be defined as a structure like below:
19
+ * struct A {
20
+ * bh_list_link l;
21
+ * ...
22
+ * };
23
+ *
24
+ * bh_list_link is defined as a structure (not typedef void*).
25
+ * It will make extend list into bi-direction easy.
26
+ */
27
+ typedef struct bh_list_link {
28
+ struct bh_list_link *next;
29
+ } bh_list_link;
30
+
31
+ typedef struct bh_list {
32
+ bh_list_link head;
33
+ uint32 len;
34
+ } bh_list;
35
+
36
+ /* list operation return value */
37
+ typedef enum bh_list_status {
38
+ BH_LIST_SUCCESS = 0,
39
+ BH_LIST_ERROR = -1
40
+ } bh_list_status;
41
+
42
+ /**
43
+ * Initialize a list.
44
+ *
45
+ * @param list pointer to list.
46
+ * @return <code>BH_LIST_ERROR</code> if OK;
47
+ * <code>BH_LIST_ERROR</code> if list pointer is NULL.
48
+ */
49
+ bh_list_status
50
+ bh_list_init(bh_list *list);
51
+
52
+ /**
53
+ * Insert an elem pointer into list. The list node memory is maintained by list
54
+ * while elem memory is the responsibility of list user.
55
+ *
56
+ * @param list pointer to list.
57
+ * @param elem pointer to elem that will be inserted into list.
58
+ * @return <code>BH_LIST_ERROR</code> if OK;
59
+ * <code>BH_LIST_ERROR</code> if input is invalid or no memory
60
+ * available.
61
+ */
62
+ bh_list_status
63
+ bh_list_insert(bh_list *list, void *elem);
64
+
65
+ /**
66
+ * Remove an elem pointer from list. The list node memory is maintained by list
67
+ * while elem memory is the responsibility of list user.
68
+ *
69
+ * @param list pointer to list.
70
+ * @param elem pointer to elem that will be inserted into list.
71
+ * @return <code>BH_LIST_ERROR</code> if OK;
72
+ * <code>BH_LIST_ERROR</code> if element does not exist in given
73
+ * list.
74
+ */
75
+ bh_list_status
76
+ bh_list_remove(bh_list *list, void *elem);
77
+
78
+ /**
79
+ * Get the list length.
80
+ *
81
+ * @param list pointer to list.
82
+ * @return the length of the list.
83
+ */
84
+ uint32
85
+ bh_list_length(bh_list *list);
86
+
87
+ /**
88
+ * Get the first elem in the list.
89
+ *
90
+ * @param list pointer to list.
91
+ * @return pointer to the first node.
92
+ */
93
+ void *
94
+ bh_list_first_elem(bh_list *list);
95
+
96
+ /**
97
+ * Get the next elem of given list input elem.
98
+ *
99
+ * @param node pointer to list node.
100
+ * @return pointer to next list node.
101
+ */
102
+ void *
103
+ bh_list_elem_next(void *node);
104
+
105
+ #ifdef __cplusplus
106
+ }
107
+ #endif
108
+
109
+ #endif /* #ifndef _BH_LIST_H */
@@ -0,0 +1,111 @@
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_log.h"
7
+
8
+ /**
9
+ * The verbose level of the log system. Only those verbose logs whose
10
+ * levels are less than or equal to this value are output.
11
+ */
12
+ static uint32 log_verbose_level = BH_LOG_LEVEL_WARNING;
13
+
14
+ void
15
+ bh_log_set_verbose_level(uint32 level)
16
+ {
17
+ log_verbose_level = level;
18
+ }
19
+
20
+ #ifndef BH_LOG
21
+ void
22
+ bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...)
23
+ {
24
+ va_list ap;
25
+ korp_tid self;
26
+ char buf[32] = { 0 };
27
+ uint64 usec;
28
+ uint32 t, h, m, s, mills;
29
+
30
+ if ((uint32)log_level > log_verbose_level)
31
+ return;
32
+
33
+ self = os_self_thread();
34
+
35
+ usec = os_time_get_boot_us();
36
+ t = (uint32)(usec / 1000000) % (24 * 60 * 60);
37
+ h = t / (60 * 60);
38
+ t = t % (60 * 60);
39
+ m = t / 60;
40
+ s = t % 60;
41
+ mills = (uint32)((usec % 1000000) / 1000);
42
+
43
+ snprintf(buf, sizeof(buf),
44
+ "%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ":%03" PRIu32, h, m, s,
45
+ mills);
46
+
47
+ #ifndef BH_VPRINTF
48
+ os_printf("[%s - %" PRIXPTR "]: ", buf, (uintptr_t)self);
49
+ #endif
50
+
51
+ if (file)
52
+ os_printf("%s, line %d, ", file, line);
53
+
54
+ va_start(ap, fmt);
55
+ os_vprintf(fmt, ap);
56
+ va_end(ap);
57
+
58
+ os_printf("\n");
59
+ }
60
+ #endif
61
+
62
+ static uint32 last_time_ms = 0;
63
+ static uint32 total_time_ms = 0;
64
+
65
+ void
66
+ bh_print_time(const char *prompt)
67
+ {
68
+ uint32 curr_time_ms;
69
+
70
+ if (log_verbose_level < 3)
71
+ return;
72
+
73
+ curr_time_ms = (uint32)bh_get_tick_ms();
74
+
75
+ if (last_time_ms == 0)
76
+ last_time_ms = curr_time_ms;
77
+
78
+ total_time_ms += curr_time_ms - last_time_ms;
79
+
80
+ os_printf("%-48s time of last stage: %" PRIu32 " ms, total time: %" PRIu32
81
+ " ms\n",
82
+ prompt, curr_time_ms - last_time_ms, total_time_ms);
83
+
84
+ last_time_ms = curr_time_ms;
85
+ }
86
+
87
+ void
88
+ bh_print_proc_mem(const char *prompt)
89
+ {
90
+ char buf[1024] = { 0 };
91
+
92
+ if (log_verbose_level < BH_LOG_LEVEL_DEBUG)
93
+ return;
94
+
95
+ if (os_dumps_proc_mem_info(buf, sizeof(buf)) != 0)
96
+ return;
97
+
98
+ os_printf("%s\n", prompt);
99
+ os_printf("===== memory usage =====\n");
100
+ os_printf("%s", buf);
101
+ os_printf("==========\n");
102
+ return;
103
+ }
104
+
105
+ void
106
+ bh_log_proc_mem(const char *function, uint32 line)
107
+ {
108
+ char prompt[128] = { 0 };
109
+ snprintf(prompt, sizeof(prompt), "[MEM] %s(...) L%" PRIu32, function, line);
110
+ bh_print_proc_mem(prompt);
111
+ }
@@ -0,0 +1,94 @@
1
+ /*
2
+ * Copyright (C) 2019 Intel Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
+ */
5
+ /**
6
+ * @file bh_log.h
7
+ * @date Tue Nov 8 18:19:10 2011
8
+ *
9
+ * @brief This log system supports wrapping multiple outputs into one
10
+ * log message. This is useful for outputting variable-length logs
11
+ * without additional memory overhead (the buffer for concatenating
12
+ * the message), e.g. exception stack trace, which cannot be printed
13
+ * by a single log calling without the help of an additional buffer.
14
+ * Avoiding additional memory buffer is useful for resource-constraint
15
+ * systems. It can minimize the impact of log system on applications
16
+ * and logs can be printed even when no enough memory is available.
17
+ * Functions with prefix "_" are private functions. Only macros that
18
+ * are not start with "_" are exposed and can be used.
19
+ */
20
+
21
+ #ifndef _BH_LOG_H
22
+ #define _BH_LOG_H
23
+
24
+ #include "bh_platform.h"
25
+
26
+ #ifdef __cplusplus
27
+ extern "C" {
28
+ #endif
29
+
30
+ typedef enum {
31
+ BH_LOG_LEVEL_FATAL = 0,
32
+ BH_LOG_LEVEL_ERROR = 1,
33
+ BH_LOG_LEVEL_WARNING = 2,
34
+ BH_LOG_LEVEL_DEBUG = 3,
35
+ BH_LOG_LEVEL_VERBOSE = 4
36
+ } LogLevel;
37
+
38
+ void
39
+ bh_log_set_verbose_level(uint32 level);
40
+
41
+ #ifndef BH_LOG
42
+ void
43
+ bh_log(LogLevel log_level, const char *file, int line, const char *fmt, ...);
44
+ #else
45
+ void
46
+ BH_LOG(uint32 log_level, const char *file, int line, const char *fmt, ...);
47
+ #define bh_log BH_LOG
48
+ #endif
49
+
50
+ #ifdef BH_PLATFORM_NUTTX
51
+
52
+ #undef LOG_FATAL
53
+ #undef LOG_ERROR
54
+ #undef LOG_WARNING
55
+ #undef LOG_VERBOSE
56
+ #undef LOG_DEBUG
57
+
58
+ #endif
59
+
60
+ #if BH_DEBUG != 0
61
+ #define LOG_FATAL(...) \
62
+ bh_log(BH_LOG_LEVEL_FATAL, __FILE__, __LINE__, __VA_ARGS__)
63
+ #else
64
+ #define LOG_FATAL(...) \
65
+ bh_log(BH_LOG_LEVEL_FATAL, __FUNCTION__, __LINE__, __VA_ARGS__)
66
+ #endif
67
+
68
+ #define LOG_ERROR(...) bh_log(BH_LOG_LEVEL_ERROR, NULL, 0, __VA_ARGS__)
69
+ #define LOG_WARNING(...) bh_log(BH_LOG_LEVEL_WARNING, NULL, 0, __VA_ARGS__)
70
+ #define LOG_VERBOSE(...) bh_log(BH_LOG_LEVEL_VERBOSE, NULL, 0, __VA_ARGS__)
71
+
72
+ #if BH_DEBUG != 0
73
+ #define LOG_DEBUG(...) \
74
+ bh_log(BH_LOG_LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
75
+ #else
76
+ #define LOG_DEBUG(...) (void)0
77
+ #endif
78
+
79
+ void
80
+ bh_print_time(const char *prompt);
81
+
82
+ void
83
+ bh_print_proc_mem(const char *prompt);
84
+
85
+ void
86
+ bh_log_proc_mem(const char *function, uint32 line);
87
+
88
+ #define LOG_PROC_MEM(...) bh_log_proc_mem(__FUNCTION__, __LINE__)
89
+
90
+ #ifdef __cplusplus
91
+ }
92
+ #endif
93
+
94
+ #endif /* _BH_LOG_H */