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,1676 @@
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_API_EXTENSION_H
7
+ #define PLATFORM_API_EXTENSION_H
8
+
9
+ #include "platform_common.h"
10
+ #include "platform_wasi_types.h"
11
+ /**
12
+ * The related data structures should be defined
13
+ * in platform_internal.h
14
+ **/
15
+ #include "platform_internal.h"
16
+
17
+ #ifdef __cplusplus
18
+ extern "C" {
19
+ #endif
20
+
21
+ /***************************************************
22
+ * *
23
+ * Extension interface *
24
+ * *
25
+ ***************************************************/
26
+
27
+ /****************************************************
28
+ * Section 1 *
29
+ * Multi thread support *
30
+ ****************************************************/
31
+
32
+ /**
33
+ * NOTES:
34
+ * 1. If you are building VM core only, it must be implemented to
35
+ * enable multi-thread support, otherwise no need to implement it
36
+ * 2. To build the app-mgr and app-framework, you must implement it
37
+ */
38
+
39
+ /**
40
+ * Creates a thread
41
+ *
42
+ * @param p_tid [OUTPUT] the pointer of tid
43
+ * @param start main routine of the thread
44
+ * @param arg argument passed to main routine
45
+ * @param stack_size bytes of stack size
46
+ *
47
+ * @return 0 if success.
48
+ */
49
+ int
50
+ os_thread_create(korp_tid *p_tid, thread_start_routine_t start, void *arg,
51
+ unsigned int stack_size);
52
+
53
+ /**
54
+ * Creates a thread with priority
55
+ *
56
+ * @param p_tid [OUTPUT] the pointer of tid
57
+ * @param start main routine of the thread
58
+ * @param arg argument passed to main routine
59
+ * @param stack_size bytes of stack size
60
+ * @param prio the priority
61
+ *
62
+ * @return 0 if success.
63
+ */
64
+ int
65
+ os_thread_create_with_prio(korp_tid *p_tid, thread_start_routine_t start,
66
+ void *arg, unsigned int stack_size, int prio);
67
+
68
+ /**
69
+ * Waits for the thread specified by thread to terminate
70
+ *
71
+ * @param thread the thread to wait
72
+ * @param retval if not NULL, output the exit status of the terminated thread
73
+ *
74
+ * @return return 0 if success
75
+ */
76
+ int
77
+ os_thread_join(korp_tid thread, void **retval);
78
+
79
+ /**
80
+ * Detach the thread specified by thread
81
+ *
82
+ * @param thread the thread to detach
83
+ *
84
+ * @return return 0 if success
85
+ */
86
+ int os_thread_detach(korp_tid);
87
+
88
+ /**
89
+ * Exit current thread
90
+ *
91
+ * @param retval the return value of the current thread
92
+ */
93
+ void
94
+ os_thread_exit(void *retval);
95
+
96
+ /* Try to define os_atomic_thread_fence if it isn't defined in
97
+ platform's platform_internal.h */
98
+ #ifndef os_atomic_thread_fence
99
+
100
+ #if !defined(__GNUC_PREREQ) && (defined(__GNUC__) || defined(__GNUG__)) \
101
+ && !defined(__clang__) && defined(__GNUC_MINOR__)
102
+ #define __GNUC_PREREQ(maj, min) \
103
+ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
104
+ #endif
105
+
106
+ /* Clang's __GNUC_PREREQ macro has a different meaning than GCC one,
107
+ so we have to handle this case specially(except the CCAC compiler
108
+ provided by MetaWare, which doesn't support atomic operations) */
109
+ #if defined(__clang__) && !defined(__CCAC__)
110
+ /* Clang provides stdatomic.h since 3.6.0
111
+ See https://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html */
112
+ #if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 6)
113
+ #define BH_HAS_STD_ATOMIC
114
+ #endif
115
+ #elif defined(__GNUC_PREREQ)
116
+ /* Even though older versions of GCC support C11, atomics were
117
+ not implemented until 4.9. See
118
+ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58016 */
119
+ #if __GNUC_PREREQ(4, 9)
120
+ #define BH_HAS_STD_ATOMIC
121
+ #elif __GNUC_PREREQ(4, 7)
122
+ #define os_memory_order_acquire __ATOMIC_ACQUIRE
123
+ #define os_memory_order_release __ATOMIC_RELEASE
124
+ #define os_memory_order_seq_cst __ATOMIC_SEQ_CST
125
+ #define os_atomic_thread_fence __atomic_thread_fence
126
+ #endif /* end of __GNUC_PREREQ(4, 9) */
127
+ #endif /* end of defined(__GNUC_PREREQ) */
128
+
129
+ #if defined(BH_HAS_STD_ATOMIC) && !defined(__cplusplus)
130
+ #include <stdatomic.h>
131
+ #define os_memory_order_acquire memory_order_acquire
132
+ #define os_memory_order_release memory_order_release
133
+ #define os_memory_order_seq_cst memory_order_seq_cst
134
+ #define os_atomic_thread_fence atomic_thread_fence
135
+ #define os_atomic_cmpxchg atomic_compare_exchange_strong
136
+ #endif
137
+
138
+ #endif /* end of os_atomic_thread_fence */
139
+
140
+ /**
141
+ * Initialize current thread environment if current thread
142
+ * is created by developer but not runtime
143
+ *
144
+ * @return 0 if success, -1 otherwise
145
+ */
146
+ int
147
+ os_thread_env_init(void);
148
+
149
+ /**
150
+ * Destroy current thread environment
151
+ */
152
+ void
153
+ os_thread_env_destroy(void);
154
+
155
+ /**
156
+ * Whether the thread environment is initialized
157
+ */
158
+ bool
159
+ os_thread_env_inited(void);
160
+
161
+ /**
162
+ * Suspend execution of the calling thread for (at least)
163
+ * usec microseconds
164
+ *
165
+ * @return 0 if success, -1 otherwise
166
+ */
167
+ int
168
+ os_usleep(uint32 usec);
169
+
170
+ /**
171
+ * Creates a recursive mutex
172
+ *
173
+ * @param mutex [OUTPUT] pointer to mutex initialized.
174
+ *
175
+ * @return 0 if success
176
+ */
177
+ int
178
+ os_recursive_mutex_init(korp_mutex *mutex);
179
+
180
+ /**
181
+ * This function creates a condition variable
182
+ *
183
+ * @param cond [OUTPUT] pointer to condition variable
184
+ *
185
+ * @return 0 if success
186
+ */
187
+ int
188
+ os_cond_init(korp_cond *cond);
189
+
190
+ /**
191
+ * This function destroys condition variable
192
+ *
193
+ * @param cond pointer to condition variable
194
+ *
195
+ * @return 0 if success
196
+ */
197
+ int
198
+ os_cond_destroy(korp_cond *cond);
199
+
200
+ /**
201
+ * Wait a condition variable.
202
+ *
203
+ * @param cond pointer to condition variable
204
+ * @param mutex pointer to mutex to protect the condition variable
205
+ *
206
+ * @return 0 if success
207
+ */
208
+ int
209
+ os_cond_wait(korp_cond *cond, korp_mutex *mutex);
210
+
211
+ /**
212
+ * Wait a condition variable or return if time specified passes.
213
+ *
214
+ * @param cond pointer to condition variable
215
+ * @param mutex pointer to mutex to protect the condition variable
216
+ * @param useconds microseconds to wait
217
+ *
218
+ * @return 0 if success
219
+ */
220
+ int
221
+ os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, uint64 useconds);
222
+
223
+ /**
224
+ * Signals the condition variable
225
+ *
226
+ * @param cond condition variable
227
+ *
228
+ * @return 0 if success
229
+ */
230
+ int
231
+ os_cond_signal(korp_cond *cond);
232
+
233
+ /**
234
+ * Broadcast the condition variable
235
+ *
236
+ * @param cond condition variable
237
+ *
238
+ * @return 0 if success
239
+ */
240
+ int
241
+ os_cond_broadcast(korp_cond *cond);
242
+
243
+ /**
244
+ * Initialize readwrite lock object
245
+ *
246
+ * @param cond [OUTPUT] pointer to a lock object variable
247
+ *
248
+ * @return 0 if success
249
+ */
250
+ int
251
+ os_rwlock_init(korp_rwlock *lock);
252
+
253
+ /**
254
+ * Acquire the read lock
255
+ *
256
+ * @param lock lock variable
257
+ *
258
+ * @return 0 if success
259
+ */
260
+ int
261
+ os_rwlock_rdlock(korp_rwlock *lock);
262
+
263
+ /**
264
+ * Acquire the write lock
265
+ *
266
+ * @param lock lock variable
267
+ *
268
+ * @return 0 if success
269
+ */
270
+ int
271
+ os_rwlock_wrlock(korp_rwlock *lock);
272
+
273
+ /**
274
+ * Unlocks the lock object
275
+ *
276
+ * @param lock lock variable
277
+ *
278
+ * @return 0 if success
279
+ */
280
+ int
281
+ os_rwlock_unlock(korp_rwlock *lock);
282
+
283
+ /**
284
+ * Destroy a lock object
285
+ *
286
+ * @param lock lock variable
287
+ *
288
+ * @return 0 if success
289
+ */
290
+ int
291
+ os_rwlock_destroy(korp_rwlock *lock);
292
+
293
+ /**
294
+ * Creates a new POSIX-like semaphore or opens an existing
295
+ * semaphore. The semaphore is identified by name. For details of
296
+ * the construction of name, please refer to
297
+ * https://man7.org/linux/man-pages/man3/sem_open.3.html.
298
+ *
299
+ * @param name semaphore name
300
+ * @param oflasg specifies flags that control the operation of the call
301
+ * @param mode permission flags
302
+ * @param val initial value of the named semaphore.
303
+ *
304
+ * @return korp_sem * if success, NULL otherwise
305
+ */
306
+ korp_sem *
307
+ os_sem_open(const char *name, int oflags, int mode, int val);
308
+
309
+ /**
310
+ * Closes the named semaphore referred to by sem,
311
+ * allowing any resources that the system has allocated to the
312
+ * calling process for this semaphore to be freed.
313
+ *
314
+ * @param sem
315
+ *
316
+ * @return 0 if success
317
+ */
318
+ int
319
+ os_sem_close(korp_sem *sem);
320
+
321
+ /**
322
+ * Decrements (locks) the semaphore pointed to by sem.
323
+ * If the semaphore's value is greater than zero, then the decrement
324
+ * proceeds, and the function returns, immediately. If the
325
+ * semaphore currently has the value zero, then the call blocks
326
+ * until either it becomes possible to perform the decrement (i.e.,
327
+ * the semaphore value rises above zero), or a signal handler
328
+ * interrupts the call.
329
+ *
330
+ * @return 0 if success
331
+ */
332
+ int
333
+ os_sem_wait(korp_sem *sem);
334
+
335
+ /**
336
+ * Is the same as sem_wait(), except that if the
337
+ * decrement cannot be immediately performed, then call returns an
338
+ * error (errno set to EAGAIN) instead of blocking.
339
+ *
340
+ * @return 0 if success
341
+ */
342
+ int
343
+ os_sem_trywait(korp_sem *sem);
344
+
345
+ /**
346
+ * Increments (unlocks) the semaphore pointed to by sem.
347
+ * If the semaphore's value consequently becomes greater than zero,
348
+ * then another process or thread blocked in a sem_wait(3) call will
349
+ * be woken up and proceed to lock the semaphore.
350
+ *
351
+ * @return 0 if success
352
+ */
353
+ int
354
+ os_sem_post(korp_sem *sem);
355
+
356
+ /**
357
+ * Places the current value of the semaphore pointed
358
+ * to sem into the integer pointed to by sval.
359
+ *
360
+ * @return 0 if success
361
+ */
362
+ int
363
+ os_sem_getvalue(korp_sem *sem, int *sval);
364
+
365
+ /**
366
+ * Remove the named semaphore referred to by name.
367
+ * The semaphore name is removed immediately. The semaphore is
368
+ * destroyed once all other processes that have the semaphore open
369
+ * close it.
370
+ *
371
+ * @param name semaphore name
372
+ *
373
+ * @return 0 if success
374
+ */
375
+ int
376
+ os_sem_unlink(const char *name);
377
+
378
+ /**
379
+ * Initialize process-global state for os_wakeup_blocking_op.
380
+ */
381
+ int
382
+ os_blocking_op_init(void);
383
+
384
+ /**
385
+ * Start accepting os_wakeup_blocking_op requests for the calling thread.
386
+ */
387
+ void
388
+ os_begin_blocking_op(void);
389
+
390
+ /**
391
+ * Stop accepting os_wakeup_blocking_op requests for the calling thread.
392
+ */
393
+ void
394
+ os_end_blocking_op(void);
395
+
396
+ /**
397
+ * Wake up the specified thread.
398
+ *
399
+ * For example, on posix-like platforms, this can be implemented by
400
+ * sending a signal (w/o SA_RESTART) which interrupts a blocking
401
+ * system call.
402
+ */
403
+ int
404
+ os_wakeup_blocking_op(korp_tid tid);
405
+
406
+ /****************************************************
407
+ * Section 2 *
408
+ * Socket support *
409
+ ****************************************************/
410
+
411
+ /**
412
+ * NOTES:
413
+ * Socket APIs are required by source debugging feature.
414
+ * If you don't need source debugging feature, then no
415
+ * need to implement these APIs
416
+ */
417
+
418
+ typedef union {
419
+ uint32 ipv4;
420
+ uint16 ipv6[8];
421
+ uint8 data[1];
422
+ } bh_ip_addr_buffer_t;
423
+
424
+ typedef struct {
425
+ bh_ip_addr_buffer_t addr_buffer;
426
+ uint16 port;
427
+ bool is_ipv4;
428
+ } bh_sockaddr_t;
429
+
430
+ /**
431
+ * Create a socket
432
+ *
433
+ * @param sock [OUTPUT] the pointer of socket
434
+ * @param is_ipv4 true for IPv4, false for IPv6
435
+ * @param is_tcp true for tcp, false for udp
436
+ *
437
+ * @return 0 if success, -1 otherwise
438
+ */
439
+ int
440
+ os_socket_create(bh_socket_t *sock, bool is_ipv4, bool is_tcp);
441
+
442
+ /**
443
+ * Assign the address and port to the socket
444
+ *
445
+ * @param socket the socket to bind
446
+ * @param addr the ip address, only IPv4 supported currently
447
+ * @param port [INPUT/OUTPUT] the port number, if the value is 0,
448
+ * it will use a port assigned by OS. On return it will
449
+ * contain the actual bound port number
450
+ *
451
+ * @return 0 if success, -1 otherwise
452
+ */
453
+ int
454
+ os_socket_bind(bh_socket_t socket, const char *addr, int *port);
455
+
456
+ /**
457
+ * Set timeout for the given socket
458
+ *
459
+ * @param socket the socket to set timeout
460
+ * @param timeout_us timeout in microseconds
461
+ *
462
+ * @return 0 if success, -1 otherwise
463
+ */
464
+ int
465
+ os_socket_settimeout(bh_socket_t socket, uint64 timeout_us);
466
+
467
+ /**
468
+ * Make the socket as a passive socket to accept incoming connection requests
469
+ *
470
+ * @param socket the socket to listen
471
+ * @param max_client maximum clients
472
+ *
473
+ * @return 0 if success, -1 otherwise
474
+ */
475
+ int
476
+ os_socket_listen(bh_socket_t socket, int max_client);
477
+
478
+ /**
479
+ * Accept an incoming connection
480
+ *
481
+ * @param server_sock the socket to accept new connections
482
+ * @param sock [OUTPUT] the connected socket
483
+ * @param addr [OUTPUT] the address of the peer socket. If addr is NULL,
484
+ * nothing is filled in, and addrlen will not be used
485
+ * @param addrlen [INPUT/OUTPUT] the size (in bytes) of the structure
486
+ * pointed to by addr, on return it will contain the actual
487
+ * size of the peer address
488
+ *
489
+ * @return 0 if success, -1 otherwise
490
+ */
491
+ int
492
+ os_socket_accept(bh_socket_t server_sock, bh_socket_t *sock, void *addr,
493
+ unsigned int *addrlen);
494
+
495
+ /**
496
+ * initiate a connection on a socket
497
+ *
498
+ * @param socket the socket to connect with
499
+ * @param addr the ip address, only IPv4 supported currently
500
+ *
501
+ * @return 0 if success, -1 otherwise
502
+ */
503
+ int
504
+ os_socket_connect(bh_socket_t socket, const char *addr, int port);
505
+
506
+ /**
507
+ * Blocking receive message from a socket.
508
+ *
509
+ * @param socket the socket to receive message from
510
+ * @param buf the buffer to store the data
511
+ * @param len length of the buffer, this API does not guarantee that
512
+ * [len] bytes are received
513
+ *
514
+ * @return number of bytes received if success, -1 otherwise
515
+ */
516
+ int
517
+ os_socket_recv(bh_socket_t socket, void *buf, unsigned int len);
518
+
519
+ /**
520
+ * Blocking receive message from a socket.
521
+ *
522
+ * @param socket the socket to send message
523
+ * @param buf the buffer to store the data
524
+ * @param len length of the buffer, this API does not guarantee that
525
+ * [len] bytes are received
526
+ * @param flags control the operation
527
+ * @param src_addr source address
528
+ *
529
+ * @return number of bytes sent if success, -1 otherwise
530
+ */
531
+ int
532
+ os_socket_recv_from(bh_socket_t socket, void *buf, unsigned int len, int flags,
533
+ bh_sockaddr_t *src_addr);
534
+
535
+ /**
536
+ * Blocking send message on a socket
537
+ *
538
+ * @param socket the socket to send message
539
+ * @param buf the buffer of data to be sent
540
+ * @param len length of the buffer
541
+ *
542
+ * @return number of bytes sent if success, -1 otherwise
543
+ */
544
+ int
545
+ os_socket_send(bh_socket_t socket, const void *buf, unsigned int len);
546
+
547
+ /**
548
+ * Blocking send message on a socket to the target address
549
+ *
550
+ * @param socket the socket to send message
551
+ * @param buf the buffer of data to be sent
552
+ * @param len length of the buffer
553
+ * @param flags control the operation
554
+ * @param dest_addr target address
555
+ *
556
+ * @return number of bytes sent if success, -1 otherwise
557
+ */
558
+ int
559
+ os_socket_send_to(bh_socket_t socket, const void *buf, unsigned int len,
560
+ int flags, const bh_sockaddr_t *dest_addr);
561
+
562
+ /**
563
+ * Close a socket
564
+ *
565
+ * @param socket the socket to be closed
566
+ *
567
+ * @return always return 0
568
+ */
569
+ int
570
+ os_socket_close(bh_socket_t socket);
571
+
572
+ /**
573
+ * Shutdown a socket
574
+ *
575
+ * @param socket the socket to be shutdown
576
+ *
577
+ * @return returns corresponding error code
578
+ */
579
+ __wasi_errno_t
580
+ os_socket_shutdown(bh_socket_t socket);
581
+
582
+ /**
583
+ * converts cp into a number in host byte order suitable for use as
584
+ * an Internet network address
585
+ *
586
+ * @param is_ipv4 a flag that indicates whether the string is an IPv4 or
587
+ * IPv6 address
588
+ *
589
+ * @param cp a string in IPv4 numbers-and-dots notation or IPv6
590
+ * numbers-and-colons notation
591
+ *
592
+ * @param out an output buffer to store binary address
593
+ *
594
+ * @return On success, the function returns 0.
595
+ * If the input is invalid, -1 is returned
596
+ */
597
+ int
598
+ os_socket_inet_network(bool is_ipv4, const char *cp, bh_ip_addr_buffer_t *out);
599
+
600
+ typedef struct {
601
+ bh_sockaddr_t sockaddr;
602
+ uint8_t is_tcp;
603
+ } bh_addr_info_t;
604
+
605
+ /**
606
+ * Resolve a host a hostname and a service to one or more IP addresses
607
+ *
608
+ * @param host a host to resolve
609
+ *
610
+ * @param service a service to find a port for
611
+ *
612
+ * @param hint_is_tcp an optional flag that determines a preferred socket type
613
+ (TCP or UDP).
614
+ *
615
+ * @param hint_is_ipv4 an optional flag that determines a preferred address
616
+ family (IPv4 or IPv6)
617
+ *
618
+ * @param addr_info a buffer for resolved addresses
619
+ *
620
+ * @param addr_info_size a size of the buffer for resolved addresses
621
+
622
+ * @param max_info_size a maximum number of addresses available (can be bigger
623
+ or smaller than buffer size)
624
+
625
+ * @return On success, the function returns 0; otherwise, it returns -1
626
+ */
627
+ int
628
+ os_socket_addr_resolve(const char *host, const char *service,
629
+ uint8_t *hint_is_tcp, uint8_t *hint_is_ipv4,
630
+ bh_addr_info_t *addr_info, size_t addr_info_size,
631
+ size_t *max_info_size);
632
+
633
+ /**
634
+ * Returns an binary address and a port of the local socket
635
+ *
636
+ * @param socket the local socket
637
+ *
638
+ * @param sockaddr a buffer for storing the address
639
+ *
640
+ * @return On success, returns 0; otherwise, it returns -1.
641
+ */
642
+ int
643
+ os_socket_addr_local(bh_socket_t socket, bh_sockaddr_t *sockaddr);
644
+
645
+ /**
646
+ * Returns an binary address and a port of the remote socket
647
+ *
648
+ * @param socket the remote socket
649
+ *
650
+ * @param sockaddr a buffer for storing the address
651
+ *
652
+ * @return On success, returns 0; otherwise, it returns -1.
653
+ */
654
+ int
655
+ os_socket_addr_remote(bh_socket_t socket, bh_sockaddr_t *sockaddr);
656
+
657
+ /**
658
+ * Set the maximum send buffer size.
659
+ *
660
+ * @param socket the socket to set
661
+ * @param bufsiz requested kernel buffer size
662
+ *
663
+ * @return 0 if success, -1 otherwise
664
+ */
665
+ int
666
+ os_socket_set_send_buf_size(bh_socket_t socket, size_t bufsiz);
667
+
668
+ /**
669
+ * Get the maximum send buffer size.
670
+ *
671
+ * @param socket the socket to set
672
+ * @param bufsiz the returned kernel buffer size
673
+ *
674
+ * @return 0 if success, -1 otherwise
675
+ */
676
+ int
677
+ os_socket_get_send_buf_size(bh_socket_t socket, size_t *bufsiz);
678
+
679
+ /**
680
+ * Set the maximum receive buffer size.
681
+ *
682
+ * @param socket the socket to set
683
+ * @param bufsiz requested kernel buffer size
684
+ *
685
+ * @return 0 if success, -1 otherwise
686
+ */
687
+ int
688
+ os_socket_set_recv_buf_size(bh_socket_t socket, size_t bufsiz);
689
+
690
+ /**
691
+ * Get the maximum receive buffer size.
692
+ *
693
+ * @param socket the socket to set
694
+ * @param bufsiz the returned kernel buffer size
695
+ *
696
+ * @return 0 if success, -1 otherwise
697
+ */
698
+ int
699
+ os_socket_get_recv_buf_size(bh_socket_t socket, size_t *bufsiz);
700
+
701
+ /**
702
+ * Enable sending of keep-alive messages on connection-oriented sockets
703
+ *
704
+ * @param socket the socket to set the flag
705
+ * @param is_enabled 1 to enable or 0 to disable
706
+ *
707
+ * @return 0 if success, -1 otherwise
708
+ */
709
+ int
710
+ os_socket_set_keep_alive(bh_socket_t socket, bool is_enabled);
711
+
712
+ /**
713
+ * Get if sending of keep-alive messages on connection-oriented sockets is
714
+ * enabled
715
+ *
716
+ * @param socket the socket to check
717
+ * @param is_enabled 1 if enabled or 0 if disabled
718
+ *
719
+ * @return 0 if success, -1 otherwise
720
+ */
721
+ int
722
+ os_socket_get_keep_alive(bh_socket_t socket, bool *is_enabled);
723
+
724
+ /**
725
+ * Set the send timeout until reporting an error
726
+ *
727
+ * @param socket the socket to set
728
+ * @param time_us microseconds until timeout
729
+ *
730
+ * @return 0 if success, -1 otherwise
731
+ */
732
+ int
733
+ os_socket_set_send_timeout(bh_socket_t socket, uint64 timeout_us);
734
+
735
+ /**
736
+ * Get the send timeout until reporting an error
737
+ *
738
+ * @param socket the socket to set
739
+ * @param time_us the returned microseconds until timeout
740
+ *
741
+ * @return 0 if success, -1 otherwise
742
+ */
743
+ int
744
+ os_socket_get_send_timeout(bh_socket_t socket, uint64 *timeout_us);
745
+
746
+ /**
747
+ * Set the recv timeout until reporting an error
748
+ *
749
+ * @param socket the socket to set
750
+ * @param time_us microseconds until timeout
751
+ *
752
+ * @return 0 if success, -1 otherwise
753
+ */
754
+ int
755
+ os_socket_set_recv_timeout(bh_socket_t socket, uint64 timeout_us);
756
+
757
+ /**
758
+ * Get the recv timeout until reporting an error
759
+ *
760
+ * @param socket the socket to set
761
+ * @param time_us the returned microseconds until timeout
762
+ *
763
+ * @return 0 if success, -1 otherwise
764
+ */
765
+ int
766
+ os_socket_get_recv_timeout(bh_socket_t socket, uint64 *timeout_us);
767
+
768
+ /**
769
+ * Enable reuse of local addresses
770
+ *
771
+ * @param socket the socket to set
772
+ * @param is_enabled 1 to enable or 0 to disable
773
+ *
774
+ * @return 0 if success, -1 otherwise
775
+ */
776
+ int
777
+ os_socket_set_reuse_addr(bh_socket_t socket, bool is_enabled);
778
+
779
+ /**
780
+ * Get whether reuse of local addresses is enabled
781
+ *
782
+ * @param socket the socket to set
783
+ * @param is_enabled 1 for enabled or 0 for disabled
784
+ *
785
+ * @return 0 if success, -1 otherwise
786
+ */
787
+ int
788
+ os_socket_get_reuse_addr(bh_socket_t socket, bool *is_enabled);
789
+
790
+ /**
791
+ * Enable reuse of local ports
792
+ *
793
+ * @param socket the socket to set
794
+ * @param is_enabled 1 to enable or 0 to disable
795
+ *
796
+ * @return 0 if success, -1 otherwise
797
+ */
798
+ int
799
+ os_socket_set_reuse_port(bh_socket_t socket, bool is_enabled);
800
+
801
+ /**
802
+ * Get whether reuse of local ports is enabled
803
+ *
804
+ * @param socket the socket to set
805
+ * @param is_enabled 1 for enabled or 0 for disabled
806
+ *
807
+ * @return 0 if success, -1 otherwise
808
+ */
809
+ int
810
+ os_socket_get_reuse_port(bh_socket_t socket, bool *is_enabled);
811
+
812
+ /**
813
+ * Set the linger options for the given socket
814
+ *
815
+ * @param socket the socket to set
816
+ * @param is_enabled whether linger is enabled
817
+ * @param linger_s linger time (seconds)
818
+ * @return 0 if success, -1 otherwise
819
+ */
820
+ int
821
+ os_socket_set_linger(bh_socket_t socket, bool is_enabled, int linger_s);
822
+
823
+ /**
824
+ * Get the linger options for the given socket
825
+ *
826
+ * @param socket the socket to get
827
+ * @param is_enabled whether linger is enabled
828
+ * @param linger_s linger time (seconds)
829
+ * @return 0 if success, -1 otherwise
830
+ */
831
+ int
832
+ os_socket_get_linger(bh_socket_t socket, bool *is_enabled, int *linger_s);
833
+
834
+ /**
835
+ * Set no delay TCP
836
+ * If set, disable the Nagle algorithm.
837
+ * This means that segments are always sent as soon as possible,
838
+ * even if there is only a small amount of data
839
+ *
840
+ * @param socket the socket to set the flag
841
+ * @param is_enabled 1 to enable or 0 to disable
842
+ *
843
+ * @return 0 if success, -1 otherwise
844
+ */
845
+ int
846
+ os_socket_set_tcp_no_delay(bh_socket_t socket, bool is_enabled);
847
+
848
+ /**
849
+ * Get no delay TCP
850
+ * If set, disable the Nagle algorithm.
851
+ * This means that segments are always sent as soon as possible,
852
+ * even if there is only a small amount of data
853
+ *
854
+ * @param socket the socket to check
855
+ * @param is_enabled 1 if enabled or 0 if disabled
856
+ *
857
+ * @return 0 if success, -1 otherwise
858
+ */
859
+ int
860
+ os_socket_get_tcp_no_delay(bh_socket_t socket, bool *is_enabled);
861
+
862
+ /**
863
+ * Enable/Disable tcp quickack mode
864
+ * In quickack mode, acks are sent immediately, rather than delayed if needed in
865
+ * accordance to normal TCP operation
866
+ *
867
+ * @param socket the socket to set the flag
868
+ * @param is_enabled 1 to enable or 0 to disable
869
+ *
870
+ * @return 0 if success, -1 otherwise
871
+ */
872
+ int
873
+ os_socket_set_tcp_quick_ack(bh_socket_t socket, bool is_enabled);
874
+
875
+ /**
876
+ * Enable/Disable tcp quickack mode
877
+ * In quickack mode, acks are sent immediately, rather than delayed if needed in
878
+ * accordance to normal TCP operation
879
+ *
880
+ * @param socket the socket to check
881
+ * @param is_enabled 1 if enabled or 0 if disabled
882
+ *
883
+ * @return 0 if success, -1 otherwise
884
+ */
885
+ int
886
+ os_socket_get_tcp_quick_ack(bh_socket_t socket, bool *is_enabled);
887
+
888
+ /**
889
+ * Set the time the connection needs to remain idle before sending keepalive
890
+ * probes
891
+ *
892
+ * @param socket the socket to set
893
+ * @param time_s seconds until keepalive probes are sent
894
+ *
895
+ * @return 0 if success, -1 otherwise
896
+ */
897
+ int
898
+ os_socket_set_tcp_keep_idle(bh_socket_t socket, uint32_t time_s);
899
+
900
+ /**
901
+ * Gets the time the connection needs to remain idle before sending keepalive
902
+ * probes
903
+ *
904
+ * @param socket the socket to check
905
+ * @param time_s seconds until keepalive probes are sent
906
+ *
907
+ * @return 0 if success, -1 otherwise
908
+ */
909
+ int
910
+ os_socket_get_tcp_keep_idle(bh_socket_t socket, uint32_t *time_s);
911
+
912
+ /**
913
+ * Set the time between individual keepalive probes
914
+ *
915
+ * @param socket the socket to set
916
+ * @param time_us seconds between individual keepalive probes
917
+ *
918
+ * @return 0 if success, -1 otherwise
919
+ */
920
+ int
921
+ os_socket_set_tcp_keep_intvl(bh_socket_t socket, uint32_t time_s);
922
+
923
+ /**
924
+ * Get the time between individual keepalive probes
925
+ *
926
+ * @param socket the socket to get
927
+ * @param time_s seconds between individual keepalive probes
928
+ *
929
+ * @return 0 if success, -1 otherwise
930
+ */
931
+ int
932
+ os_socket_get_tcp_keep_intvl(bh_socket_t socket, uint32_t *time_s);
933
+
934
+ /**
935
+ * Set use of TCP Fast Open
936
+ *
937
+ * @param socket the socket to set
938
+ * @param is_enabled 1 to enable or 0 to disable
939
+ *
940
+ * @return 0 if success, -1 otherwise
941
+ */
942
+ int
943
+ os_socket_set_tcp_fastopen_connect(bh_socket_t socket, bool is_enabled);
944
+
945
+ /**
946
+ * Get whether use of TCP Fast Open is enabled
947
+ *
948
+ * @param socket the socket to get
949
+ * @param is_enabled 1 to enabled or 0 to disabled
950
+ *
951
+ * @return 0 if success, -1 otherwise
952
+ */
953
+ int
954
+ os_socket_get_tcp_fastopen_connect(bh_socket_t socket, bool *is_enabled);
955
+
956
+ /**
957
+ * Set enable or disable IPv4 or IPv6 multicast loopback.
958
+ *
959
+ * @param socket the socket to set
960
+ * @param ipv6 true to set ipv6 loopback or false for ipv4
961
+ * @param is_enabled 1 to enable or 0 to disable
962
+ *
963
+ * @return 0 if success, -1 otherwise
964
+ */
965
+ int
966
+ os_socket_set_ip_multicast_loop(bh_socket_t socket, bool ipv6, bool is_enabled);
967
+
968
+ /**
969
+ * Get enable or disable IPv4 or IPv6 multicast loopback.
970
+ *
971
+ * @param socket the socket to check
972
+ * @param ipv6 true to set ipv6 loopback or false for ipv4
973
+ * @param is_enabled 1 for enabled or 0 for disabled
974
+ *
975
+ * @return 0 if success, -1 otherwise
976
+ */
977
+ int
978
+ os_socket_get_ip_multicast_loop(bh_socket_t socket, bool ipv6,
979
+ bool *is_enabled);
980
+
981
+ /**
982
+ * Add membership to a group
983
+ *
984
+ * @param socket the socket to add membership to
985
+ * @param imr_multiaddr the group multicast address (IPv4 or IPv6)
986
+ * @param imr_interface the interface to join on
987
+ * @param is_ipv6 whether the imr_multiaddr is IPv4 or IPv6 (true for IPv6)
988
+ *
989
+ * @return 0 if success, -1 otherwise
990
+ */
991
+ int
992
+ os_socket_set_ip_add_membership(bh_socket_t socket,
993
+ bh_ip_addr_buffer_t *imr_multiaddr,
994
+ uint32_t imr_interface, bool is_ipv6);
995
+
996
+ /**
997
+ * Drop membership of a group
998
+ *
999
+ * @param socket the socket to drop membership to
1000
+ * @param imr_multiaddr the group multicast address (IPv4 or IPv6)
1001
+ * @param imr_interface the interface to join on
1002
+ * @param is_ipv6 whether the imr_multiaddr is IPv4 or IPv6 (true for IPv6)
1003
+ *
1004
+ * @return 0 if success, -1 otherwise
1005
+ */
1006
+ int
1007
+ os_socket_set_ip_drop_membership(bh_socket_t socket,
1008
+ bh_ip_addr_buffer_t *imr_multiaddr,
1009
+ uint32_t imr_interface, bool is_ipv6);
1010
+
1011
+ /**
1012
+ * Set the current time-to-live field that is
1013
+ * used in every packet sent from this socket.
1014
+ * @param socket the socket to set the flag
1015
+ * @param ttl_s time to live (seconds)
1016
+ *
1017
+ * @return 0 if success, -1 otherwise
1018
+ */
1019
+ int
1020
+ os_socket_set_ip_ttl(bh_socket_t socket, uint8_t ttl_s);
1021
+
1022
+ /**
1023
+ * Retrieve the current time-to-live field that is
1024
+ * used in every packet sent from this socket.
1025
+ * @param socket the socket to set the flag
1026
+ * @param ttl_s time to live (seconds)
1027
+ *
1028
+ * @return 0 if success, -1 otherwise
1029
+ */
1030
+ int
1031
+ os_socket_get_ip_ttl(bh_socket_t socket, uint8_t *ttl_s);
1032
+
1033
+ /**
1034
+ * Set the time-to-live value of outgoing multicast
1035
+ * packets for this socket
1036
+ * @param socket the socket to set the flag
1037
+ * @param ttl_s time to live (seconds)
1038
+ *
1039
+ * @return 0 if success, -1 otherwise
1040
+ */
1041
+ int
1042
+ os_socket_set_ip_multicast_ttl(bh_socket_t socket, uint8_t ttl_s);
1043
+
1044
+ /**
1045
+ * Read the time-to-live value of outgoing multicast
1046
+ * packets for this socket
1047
+ * @param socket the socket to set the flag
1048
+ * @param ttl_s time to live (seconds)
1049
+ *
1050
+ * @return 0 if success, -1 otherwise
1051
+ */
1052
+ int
1053
+ os_socket_get_ip_multicast_ttl(bh_socket_t socket, uint8_t *ttl_s);
1054
+
1055
+ /**
1056
+ * Restrict to sending and receiving IPv6 packets only
1057
+ *
1058
+ * @param socket the socket to set
1059
+ * @param is_enabled 1 to enable or 0 to disable
1060
+ *
1061
+ * @return 0 if success, -1 otherwise
1062
+ */
1063
+ int
1064
+ os_socket_set_ipv6_only(bh_socket_t socket, bool is_enabled);
1065
+
1066
+ /**
1067
+ * Get whether only sending and receiving IPv6 packets
1068
+ *
1069
+ * @param socket the socket to check
1070
+ * @param is_enabled 1 for enabled or 0 for disabled
1071
+ *
1072
+ * @return 0 if success, -1 otherwise
1073
+ */
1074
+ int
1075
+ os_socket_get_ipv6_only(bh_socket_t socket, bool *is_enabled);
1076
+
1077
+ /**
1078
+ * Set whether broadcast is enabled
1079
+ * When enabled, datagram sockets are allowed
1080
+ * to send packets to a broadcast address.
1081
+ *
1082
+ * @param socket the socket to set the flag
1083
+ * @param is_enabled 1 to enable or 0 to disable
1084
+ *
1085
+ * @return 0 if success, -1 otherwise
1086
+ */
1087
+ int
1088
+ os_socket_set_broadcast(bh_socket_t socket, bool is_enabled);
1089
+
1090
+ /**
1091
+ * Get whether broadcast is enabled
1092
+ * When enabled, datagram sockets are allowed
1093
+ * to send packets to a broadcast address.
1094
+ *
1095
+ * @param socket the socket to check
1096
+ * @param is_enabled 1 if enabled or 0 if disabled
1097
+ *
1098
+ * @return 0 if success, -1 otherwise
1099
+ */
1100
+ int
1101
+ os_socket_get_broadcast(bh_socket_t socket, bool *is_enabled);
1102
+
1103
+ /**
1104
+ * Dump memory information of the current process
1105
+ * It may have variant implementations in different platforms
1106
+ *
1107
+ * @param out the output buffer. It is for sure the return content
1108
+ * is a c-string which ends up with '\0'
1109
+ * @param size the size of the output buffer
1110
+ *
1111
+ * @return 0 if success, -1 otherwise
1112
+ */
1113
+ int
1114
+ os_dumps_proc_mem_info(char *out, unsigned int size);
1115
+
1116
+ /****************************************************
1117
+ * Section 3 *
1118
+ * Filesystem support *
1119
+ ****************************************************/
1120
+
1121
+ /**
1122
+ * NOTES:
1123
+ * Filesystem APIs are required for WASI libc support. If you don't need to
1124
+ * support WASI libc, there is no need to implement these APIs. With a
1125
+ * few exceptions, each filesystem function has been named after the equivalent
1126
+ * POSIX filesystem function with an os_ prefix.
1127
+ *
1128
+ * Filesystem types
1129
+ *
1130
+ * os_raw_file_handle: the underlying OS file handle type e.g. int on POSIX
1131
+ * systems and HANDLE on Windows. This type exists to allow embedders to provide
1132
+ * custom file handles for stdout/stdin/stderr.
1133
+ *
1134
+ * os_file_handle: the file handle type used in the WASI libc fd
1135
+ * table. Filesystem implementations can use it as a means to store any
1136
+ * necessary platform-specific information which may not be directly available
1137
+ * through the raw OS file handle. Similar to POSIX file descriptors, file
1138
+ * handles may also refer to sockets, directories, symbolic links or character
1139
+ * devices and any of the filesystem operations which make sense for these
1140
+ * resource types should be supported as far as possible.
1141
+ *
1142
+ * os_dir_stream: a directory stream type in which filesystem implementations
1143
+ * can store any necessary state to iterate over the entries in a directory.
1144
+ */
1145
+
1146
+ /**
1147
+ * Obtain information about an open file associated with the given handle.
1148
+ *
1149
+ * @param handle the handle for which to obtain file information
1150
+ * @param buf a buffer in which to store the information
1151
+ */
1152
+ __wasi_errno_t
1153
+ os_fstat(os_file_handle handle, struct __wasi_filestat_t *buf);
1154
+
1155
+ /**
1156
+ * Obtain information about an open file or directory.
1157
+ * @param handle the directory handle from which to resolve the file/directory
1158
+ * path
1159
+ * @param path the relative path of the file or directory for which to obtain
1160
+ * information
1161
+ * @param buf a buffer in which to store the information
1162
+ * @param follow_symlink whether to follow symlinks when resolving the path
1163
+ */
1164
+ __wasi_errno_t
1165
+ os_fstatat(os_file_handle handle, const char *path,
1166
+ struct __wasi_filestat_t *buf, __wasi_lookupflags_t lookup_flags);
1167
+
1168
+ /**
1169
+ * Obtain the file status flags for the provided handle. This is similar to the
1170
+ * POSIX function fcntl called with the F_GETFL command.
1171
+ *
1172
+ * @param handle the handle for which to obtain the file status flags
1173
+ * @param flags a pointer in which to store the output
1174
+ */
1175
+ __wasi_errno_t
1176
+ os_file_get_fdflags(os_file_handle handle, __wasi_fdflags_t *flags);
1177
+
1178
+ /**
1179
+ * Set the file status flags for the provided handle. This is similar to the
1180
+ * POSIX function fcntl called with the F_SETFL command.
1181
+ *
1182
+ * @param handle the handle for which to set the file status flags
1183
+ * @param flags the flags to set
1184
+ */
1185
+ __wasi_errno_t
1186
+ os_file_set_fdflags(os_file_handle handle, __wasi_fdflags_t flags);
1187
+
1188
+ /**
1189
+ * Synchronize the data of a file to disk.
1190
+ *
1191
+ * @param handle
1192
+ */
1193
+ __wasi_errno_t
1194
+ os_fdatasync(os_file_handle handle);
1195
+
1196
+ /**
1197
+ * Synchronize the data and metadata of a file to disk.
1198
+ *
1199
+ * @param handle
1200
+ */
1201
+ __wasi_errno_t
1202
+ os_fsync(os_file_handle handle);
1203
+
1204
+ /**
1205
+ * Open a preopen directory. The path provided must refer to a directory and the
1206
+ * returned handle will allow only readonly operations.
1207
+ *
1208
+ * @param path the path of the preopen directory to open
1209
+ * @param out a pointer in which to store the newly opened handle
1210
+ */
1211
+ __wasi_errno_t
1212
+ os_open_preopendir(const char *path, os_file_handle *out);
1213
+
1214
+ typedef uint8 wasi_libc_file_access_mode;
1215
+ #define WASI_LIBC_ACCESS_MODE_READ_ONLY 0
1216
+ #define WASI_LIBC_ACCESS_MODE_WRITE_ONLY 1
1217
+ #define WASI_LIBC_ACCESS_MODE_READ_WRITE 2
1218
+
1219
+ /**
1220
+ * Open a file or directory at the given path.
1221
+ *
1222
+ * @param handle a handle to the directory in which to open the new file or
1223
+ * directory
1224
+ * @param path the relative path of the file or directory to open
1225
+ * @param oflags the flags to determine how the file or directory is opened
1226
+ * @param fd_flags the flags to set on the returned handle
1227
+ * @param lookup_flags whether to follow symlinks when resolving the path
1228
+ * @param access_mode whether the file is opened as read only, write only or
1229
+ * both
1230
+ * @param out a pointer in which to store the newly opened handle
1231
+ */
1232
+ __wasi_errno_t
1233
+ os_openat(os_file_handle handle, const char *path, __wasi_oflags_t oflags,
1234
+ __wasi_fdflags_t fd_flags, __wasi_lookupflags_t lookup_flags,
1235
+ wasi_libc_file_access_mode access_mode, os_file_handle *out);
1236
+
1237
+ /**
1238
+ * Obtain the file access mode for the provided handle. This is similar to the
1239
+ * POSIX function fcntl called with the F_GETFL command combined with the
1240
+ * O_ACCMODE mask.
1241
+ *
1242
+ * @param handle the handle for which to obtain the access mode
1243
+ * @param access_mode a pointer in which to store the access mode
1244
+ */
1245
+ __wasi_errno_t
1246
+ os_file_get_access_mode(os_file_handle handle,
1247
+ wasi_libc_file_access_mode *access_mode);
1248
+
1249
+ /**
1250
+ * Close the provided handle. If is_stdio is true, the raw file handle
1251
+ * associated with the given file handle will not be closed.
1252
+ *
1253
+ * @param handle the handle to close
1254
+ * @param is_stdio whether the provided handle refers to a stdio device
1255
+ */
1256
+ __wasi_errno_t
1257
+ os_close(os_file_handle handle, bool is_stdio);
1258
+
1259
+ /**
1260
+ * Read data from the provided handle at the given offset into multiple buffers.
1261
+ *
1262
+ * @param handle the handle to read from
1263
+ * @param iov the buffers to read into
1264
+ * @param iovcnt the number of buffers to read into
1265
+ * @param offset the offset to read from
1266
+ * @param nread a pointer in which to store the number of bytes read
1267
+ */
1268
+ __wasi_errno_t
1269
+ os_preadv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
1270
+ __wasi_filesize_t offset, size_t *nread);
1271
+
1272
+ /**
1273
+ * Write data from multiple buffers at the given offset to the provided handle.
1274
+ *
1275
+ * @param handle the handle to write to
1276
+ * @param iov the buffers to write from
1277
+ * @param iovcnt the number of buffers to write from
1278
+ * @param offset the offset to write from
1279
+ * @param nwritten a pointer in which to store the number of bytes written
1280
+ */
1281
+ __wasi_errno_t
1282
+ os_pwritev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
1283
+ __wasi_filesize_t offset, size_t *nwritten);
1284
+
1285
+ /**
1286
+ * Read data from the provided handle into multiple buffers.
1287
+ *
1288
+ * @param handle the handle to read from
1289
+ * @param iov the buffers to read into
1290
+ * @param iovcnt the number of buffers to read into
1291
+ * @param nread a pointer in which to store the number of bytes read
1292
+ */
1293
+ __wasi_errno_t
1294
+ os_readv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt,
1295
+ size_t *nread);
1296
+
1297
+ /**
1298
+ * Write data from multiple buffers to the provided handle.
1299
+ *
1300
+ * @param handle the handle to write to
1301
+ * @param iov the buffers to write from
1302
+ * @param iovcnt the number of buffers to write from
1303
+ * @param nwritten a pointer in which to store the number of bytes written
1304
+ */
1305
+ __wasi_errno_t
1306
+ os_writev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt,
1307
+ size_t *nwritten);
1308
+
1309
+ /**
1310
+ * Allocate storage space for the file associated with the provided handle. This
1311
+ * is similar to the POSIX function posix_fallocate.
1312
+ *
1313
+ * @param handle the handle to allocate space for
1314
+ * @param offset the offset to allocate space at
1315
+ * @param length the amount of space to allocate
1316
+ */
1317
+ __wasi_errno_t
1318
+ os_fallocate(os_file_handle handle, __wasi_filesize_t offset,
1319
+ __wasi_filesize_t length);
1320
+
1321
+ /**
1322
+ * Adjust the size of an open file.
1323
+ *
1324
+ * @param handle the associated file handle for which to adjust the size
1325
+ * @param size the new size of the file
1326
+ */
1327
+ __wasi_errno_t
1328
+ os_ftruncate(os_file_handle handle, __wasi_filesize_t size);
1329
+
1330
+ /**
1331
+ * Set file access and modification times on an open file or directory.
1332
+ *
1333
+ * @param handle the associated file handle for which to adjust the
1334
+ * access/modification times
1335
+ * @param access_time the timestamp for the new access time
1336
+ * @param modification_time the timestamp for the new modification time
1337
+ * @param fstflags a bitmask to indicate which timestamps to adjust
1338
+ */
1339
+ __wasi_errno_t
1340
+ os_futimens(os_file_handle handle, __wasi_timestamp_t access_time,
1341
+ __wasi_timestamp_t modification_time, __wasi_fstflags_t fstflags);
1342
+
1343
+ /**
1344
+ * Set file access and modification times on an open file or directory.
1345
+ *
1346
+ * @param handle the directory handle from which to resolve the path
1347
+ * @param path the relative path of the file or directory for which to adjust
1348
+ * the access/modification times
1349
+ * @param access_time the timestamp for the new access time
1350
+ * @param modification_time the timestamp for the new modification time
1351
+ * @param fstflags a bitmask to indicate which timestamps to adjust
1352
+ * @param lookup_flags whether to follow symlinks when resolving the path
1353
+ */
1354
+ __wasi_errno_t
1355
+ os_utimensat(os_file_handle handle, const char *path,
1356
+ __wasi_timestamp_t access_time,
1357
+ __wasi_timestamp_t modification_time, __wasi_fstflags_t fstflags,
1358
+ __wasi_lookupflags_t lookup_flags);
1359
+
1360
+ /**
1361
+ * Read the contents of a symbolic link relative to the provided directory
1362
+ * handle.
1363
+ *
1364
+ * @param handle the directory handle
1365
+ * @param path the relative path of the symbolic link from which to read
1366
+ * @param buf the buffer to read the link contents into
1367
+ * @param bufsize the size of the provided buffer
1368
+ * @param nread a pointer in which to store the number of bytes read into the
1369
+ * buffer
1370
+ */
1371
+ __wasi_errno_t
1372
+ os_readlinkat(os_file_handle handle, const char *path, char *buf,
1373
+ size_t bufsize, size_t *nread);
1374
+
1375
+ /**
1376
+ * Create a link from one path to another path.
1377
+ *
1378
+ * @param from_handle the directory handle from which to resolve the origin path
1379
+ * @param from_path the origin path to link from
1380
+ * @param to_handle the directory handle from which to resolve the destination
1381
+ * path
1382
+ * @param to_path the destination path at which to create the link
1383
+ * @param lookup_flags whether to follow symlinks when resolving the origin path
1384
+ */
1385
+ __wasi_errno_t
1386
+ os_linkat(os_file_handle from_handle, const char *from_path,
1387
+ os_file_handle to_handle, const char *to_path,
1388
+ __wasi_lookupflags_t lookup_flags);
1389
+
1390
+ /**
1391
+ * Create a symbolic link from one path to another path.
1392
+ *
1393
+ * @param old_path the symbolic link contents
1394
+ * @param handle the directory handle from which to resolve the destination path
1395
+ * @param new_path the destination path at which to create the symbolic link
1396
+ */
1397
+ __wasi_errno_t
1398
+ os_symlinkat(const char *old_path, os_file_handle handle, const char *new_path);
1399
+
1400
+ /**
1401
+ * Create a directory relative to the provided directory handle.
1402
+ *
1403
+ * @param handle the directory handle
1404
+ * @param path the relative path of the directory to create
1405
+ */
1406
+ __wasi_errno_t
1407
+ os_mkdirat(os_file_handle handle, const char *path);
1408
+
1409
+ /**
1410
+ * Rename a file or directory.
1411
+ *
1412
+ * @param old_handle the directory handle from which to resolve the old path
1413
+ * @param old_path the source path to rename
1414
+ * @param new_handle the directory handle from which to resolve the destination
1415
+ * path
1416
+ * @param new_path the destination path to which to rename the file or directory
1417
+ */
1418
+ __wasi_errno_t
1419
+ os_renameat(os_file_handle old_handle, const char *old_path,
1420
+ os_file_handle new_handle, const char *new_path);
1421
+
1422
+ /**
1423
+ * Unlink a file or directory.
1424
+ *
1425
+ * @param handle the directory handle from which to resolve the path
1426
+ * @param path the relative path of the file or directory to unlink
1427
+ * @param is_dir whether the provided handle refers to a directory or file
1428
+ */
1429
+ __wasi_errno_t
1430
+ os_unlinkat(os_file_handle handle, const char *path, bool is_dir);
1431
+
1432
+ /**
1433
+ * Move the read/write offset of an open file.
1434
+ *
1435
+ * @param handle the associated file handle for which to adjust the offset
1436
+ * @param offset the number of bytes to adjust the offset by
1437
+ * @param whence the position whence to adjust the offset
1438
+ * @param new_offset a pointer in which to store the new offset
1439
+ */
1440
+ __wasi_errno_t
1441
+ os_lseek(os_file_handle handle, __wasi_filedelta_t offset,
1442
+ __wasi_whence_t whence, __wasi_filesize_t *new_offset);
1443
+
1444
+ /**
1445
+ * Provide file advisory information for the given handle. This is similar to
1446
+ * the POSIX function posix_fadvise.
1447
+ *
1448
+ * @param handle the associated file handle for which to provide advisory
1449
+ * information
1450
+ * @param offset the offset within the file to which the advisory
1451
+ * information applies
1452
+ * @param length the length of the region for which the advisory information
1453
+ * applies
1454
+ * @param advice the advice to provide
1455
+ */
1456
+ __wasi_errno_t
1457
+ os_fadvise(os_file_handle handle, __wasi_filesize_t offset,
1458
+ __wasi_filesize_t length, __wasi_advice_t advice);
1459
+
1460
+ /**
1461
+ * Determine if the given handle refers to a terminal device. __WASI_ESUCCESS
1462
+ * will be returned if the handle is associated with a terminal device,
1463
+ * otherwise an appropriate error code will be returned.
1464
+ *
1465
+ * @param handle
1466
+ */
1467
+ __wasi_errno_t
1468
+ os_isatty(os_file_handle handle);
1469
+
1470
+ /**
1471
+ * Converts a raw file handle to STDIN to a corresponding file handle to STDIN.
1472
+ * If the provided raw file handle is invalid, the platform-default raw handle
1473
+ * for STDIN will be used.
1474
+ *
1475
+ * @param raw_stdin a raw file handle to STDIN
1476
+ *
1477
+ * @return a handle to STDIN
1478
+ */
1479
+ os_file_handle
1480
+ os_convert_stdin_handle(os_raw_file_handle raw_stdin);
1481
+
1482
+ /**
1483
+ * Converts a raw file handle to STDOUT to a corresponding file handle to
1484
+ * STDOUT. If the provided raw file handle is invalid, the platform-default raw
1485
+ * handle for STDOUT will be used.
1486
+ *
1487
+ * @param raw_stdout a raw file handle to STDOUT
1488
+ *
1489
+ * @return a handle to STDOUT
1490
+ */
1491
+ os_file_handle
1492
+ os_convert_stdout_handle(os_raw_file_handle raw_stdout);
1493
+
1494
+ /**
1495
+ * Converts a raw file handle to STDERR to a corresponding file handle to
1496
+ * STDERR. If the provided raw file handle is invalid, the platform-default raw
1497
+ * handle for STDERR will be used.
1498
+ *
1499
+ * @param raw_stderr a raw file handle to STDERR
1500
+ *
1501
+ * @return a handle to STDERR
1502
+ */
1503
+ os_file_handle
1504
+ os_convert_stderr_handle(os_raw_file_handle raw_stderr);
1505
+
1506
+ /**
1507
+ *
1508
+ * @param fd a file handle
1509
+ *
1510
+ * @return true if it is stdin
1511
+ */
1512
+ bool
1513
+ os_is_stdin_handle(os_file_handle fd);
1514
+
1515
+ /**
1516
+ *
1517
+ * @param fd a file handle
1518
+ *
1519
+ * @return true if it is stdout
1520
+ */
1521
+ bool
1522
+ os_is_stdout_handle(os_file_handle fd);
1523
+
1524
+ /**
1525
+ *
1526
+ * @param fd a file handle
1527
+ *
1528
+ * @return true if it is stderr
1529
+ */
1530
+ bool
1531
+ os_is_stderr_handle(os_file_handle fd);
1532
+
1533
+ /**
1534
+ * Open a directory stream for the provided directory handle. The returned
1535
+ * directory stream will be positioned at the first entry in the directory.
1536
+ *
1537
+ * @param handle the directory handle
1538
+ * @param dir_stream a pointer in which to store the new directory stream
1539
+ */
1540
+ __wasi_errno_t
1541
+ os_fdopendir(os_file_handle handle, os_dir_stream *dir_stream);
1542
+
1543
+ /**
1544
+ * Reset the position of a directory stream to the beginning of the directory.
1545
+ *
1546
+ * @param dir_stream the directory stream for which to reset the position
1547
+ */
1548
+ __wasi_errno_t
1549
+ os_rewinddir(os_dir_stream dir_stream);
1550
+
1551
+ /**
1552
+ * Set the position of the given directory stream.
1553
+ *
1554
+ * @param dir_stream the directory stream for which to set the position
1555
+ * @param position the position to set
1556
+ */
1557
+ __wasi_errno_t
1558
+ os_seekdir(os_dir_stream dir_stream, __wasi_dircookie_t position);
1559
+
1560
+ /**
1561
+ * Read a directory entry from the given directory stream. The directory name
1562
+ * will be NULL if the end of the directory is reached or an error is
1563
+ * encountered.
1564
+ *
1565
+ * @param dir_stream the directory stream from which to read the entry
1566
+ * @param entry a pointer in which to store the directory entry
1567
+ * @param d_name a pointer in which to store the directory entry name
1568
+ */
1569
+ __wasi_errno_t
1570
+ os_readdir(os_dir_stream dir_stream, __wasi_dirent_t *entry,
1571
+ const char **d_name);
1572
+
1573
+ /**
1574
+ * Close the given directory stream. The handle associated with the directory
1575
+ * stream will also be closed.
1576
+ *
1577
+ * @param dir_stream the directory stream to close
1578
+ */
1579
+ __wasi_errno_t
1580
+ os_closedir(os_dir_stream dir_stream);
1581
+
1582
+ /**
1583
+ * Returns an invalid directory stream that is guaranteed to cause failure when
1584
+ * called with any directory filesystem operation.
1585
+ *
1586
+ * @return the invalid directory stream
1587
+ */
1588
+ os_dir_stream
1589
+ os_get_invalid_dir_stream(void);
1590
+
1591
+ /**
1592
+ * Checks whether the given directory stream is valid. An invalid directory
1593
+ * stream is guaranteed to cause failure when called with any directory
1594
+ * filesystem operation.
1595
+ *
1596
+ * @param dir_stream a pointer to a directory stream
1597
+ */
1598
+ bool
1599
+ os_is_dir_stream_valid(os_dir_stream *dir_stream);
1600
+
1601
+ /**
1602
+ * Returns an invalid handle that is guaranteed to cause failure when
1603
+ * called with any filesystem operation.
1604
+ *
1605
+ * @return the invalid handle
1606
+ */
1607
+ os_file_handle
1608
+ os_get_invalid_handle(void);
1609
+
1610
+ /**
1611
+ * Returns an invalid raw file handle that is guaranteed to cause failure when
1612
+ * called with any filesystem operation.
1613
+ *
1614
+ * @return the invalid raw file handle
1615
+ */
1616
+ os_raw_file_handle
1617
+ os_invalid_raw_handle(void);
1618
+
1619
+ /**
1620
+ * Checks whether the given file handle is valid. An invalid handle is
1621
+ * guaranteed to cause failure when called with any filesystem operation.
1622
+ *
1623
+ * @param handle a pointer to a file handle
1624
+ */
1625
+ bool
1626
+ os_is_handle_valid(os_file_handle *handle);
1627
+
1628
+ /**
1629
+ * Resolve a pathname. The generated pathname will be stored as a
1630
+ * null-terminated string, with a maximum length of PATH_MAX bytes.
1631
+ *
1632
+ * @param path the path to resolve
1633
+ * @param resolved_path the buffer to store the resolved path in
1634
+ *
1635
+ * @return the resolved path if success, NULL otherwise
1636
+ */
1637
+ char *
1638
+ os_realpath(const char *path, char *resolved_path);
1639
+
1640
+ /****************************************************
1641
+ * Section 4 *
1642
+ * Clock functions *
1643
+ ****************************************************/
1644
+
1645
+ /**
1646
+ * NOTES:
1647
+ * Clock functions are required for WASI libc support. If you don't need to
1648
+ * support WASI libc, there is no need to implement these APIs.
1649
+ */
1650
+
1651
+ /**
1652
+ * Get the resolution of the specified clock.
1653
+ *
1654
+ * @param clock_id clock identifier
1655
+ * @param resolution output variable to store the clock resolution
1656
+ */
1657
+ __wasi_errno_t
1658
+ os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution);
1659
+
1660
+ /**
1661
+ * Get the current time of the specified clock.
1662
+ *
1663
+ * @param clock_id clock identifier
1664
+ * @param precision the maximum lag that the returned time value may have,
1665
+ * compared to its actual value.
1666
+ * @param time output variable to store the clock time
1667
+ */
1668
+ __wasi_errno_t
1669
+ os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision,
1670
+ __wasi_timestamp_t *time);
1671
+
1672
+ #ifdef __cplusplus
1673
+ }
1674
+ #endif
1675
+
1676
+ #endif /* #ifndef PLATFORM_API_EXTENSION_H */