Skip to content

Commit 0b97d0c

Browse files
lum1n0uslucasAbadFrsrberarddkouba-atym
authored
Merge dev/zephyr_file_socket into main (#4347)
zephyr: Enable WASI support for file system and sockets on zephyr (#3633) This work also implements the WASI support on Zephyr. * Added os_is_* methods for stdin/stdout/stderr. Fixed issues in os_renameat * Zephyr platform fixes for WASI sockets Addressed numerous of build warnings on Zephyr * Updated `os_writev` to use `fwrite` for STDOUT/STDERR * Temporarily reverted change to `writev` to work around an issue. * Fixes: fstat, fstatat, and unlink * Add initial support for directories in os_openat. Partial implementation — just avoids a hard fault. * Directory support WIP. readdir works but I think we have a memory leak somewhere * Fix: always use standard stream fds. Fix unlinkat and renameat. fd 0, 1, and 2 will always be supplied for standard streams. Unlinkat and renameat work exclusively based on supplied paths. * Fix: use macro for free() * Added a temporary workaround for issue identified in PR#4377 * Fixed reference to file descriptor and cleaned up dead/commented code. Note that some comments haven't been addressed and will be fixed in the further patches. Signed-off-by: Stephen Berard <[email protected]> Co-authored-by: Lucas Abad <[email protected]> Co-authored-by: Stephen Berard <[email protected]> Co-authored-by: Dan Kouba <[email protected]>
1 parent ddd3500 commit 0b97d0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+9956
-150
lines changed

core/iwasm/common/wasm_application.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,10 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
712712
}
713713
case VALUE_TYPE_F32:
714714
{
715-
os_printf("%.7g:f32", *(float32 *)(argv1 + k));
715+
// Explicit cast to double to avoid warning.
716+
// Float arguments are promoted to double in variadic
717+
// functions per section 6.5.2.2 of the C99 standard.
718+
os_printf("%.7g:f32", (double)*(float32 *)(argv1 + k));
716719
k++;
717720
break;
718721
}

core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,12 +1016,10 @@ update_clock_subscription_data(wasi_subscription_t *in, uint32 nsubscriptions,
10161016
}
10171017

10181018
static wasi_errno_t
1019-
execute_interruptible_poll_oneoff(
1020-
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
1021-
struct fd_table *curfds,
1022-
#endif
1023-
const __wasi_subscription_t *in, __wasi_event_t *out, size_t nsubscriptions,
1024-
size_t *nevents, wasm_exec_env_t exec_env)
1019+
execute_interruptible_poll_oneoff(struct fd_table *curfds,
1020+
const __wasi_subscription_t *in,
1021+
__wasi_event_t *out, size_t nsubscriptions,
1022+
size_t *nevents, wasm_exec_env_t exec_env)
10251023
{
10261024
if (nsubscriptions == 0) {
10271025
*nevents = 0;
@@ -2118,15 +2116,16 @@ wasi_sock_recv(wasm_exec_env_t exec_env, wasi_fd_t sock, iovec_app_t *ri_data,
21182116
wasi_roflags_t *ro_flags)
21192117
{
21202118
wasm_module_inst_t module_inst = get_module_inst(exec_env);
2121-
__wasi_addr_t src_addr;
21222119
wasi_errno_t error;
21232120

21242121
if (!validate_native_addr(ro_flags, (uint64)sizeof(wasi_roflags_t)))
21252122
return __WASI_EINVAL;
21262123

2124+
// We call `recvfrom` with NULL source address as `recv` doesn't
2125+
// return the source address and this parameter is not used.
2126+
*ro_data_len = 0;
21272127
error = wasi_sock_recv_from(exec_env, sock, ri_data, ri_data_len, ri_flags,
2128-
&src_addr, ro_data_len);
2129-
*ro_flags = ri_flags;
2128+
NULL, ro_data_len);
21302129

21312130
return error;
21322131
}

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle,
175175
#ifndef BH_PLATFORM_WINDOWS
176176
/* REVISIT: apply the os_file_handle style abstraction for pollfd? */
177177
__wasi_errno_t
178-
blocking_op_poll(wasm_exec_env_t exec_env, struct pollfd *pfds, nfds_t nfds,
179-
int timeout_ms, int *retp)
178+
blocking_op_poll(wasm_exec_env_t exec_env, os_poll_file_handle *pfds,
179+
os_nfds_t nfds, int timeout_ms, int *retp)
180180
{
181181
int ret;
182182
if (!wasm_runtime_begin_blocking_op(exec_env)) {
183183
return __WASI_EINTR;
184184
}
185-
ret = poll(pfds, nfds, timeout_ms);
185+
ret = os_poll(pfds, nfds, timeout_ms);
186186
wasm_runtime_end_blocking_op(exec_env);
187187
if (ret == -1) {
188188
return convert_errno(errno);

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle,
5757

5858
#ifndef BH_PLATFORM_WINDOWS
5959
__wasi_errno_t
60-
blocking_op_poll(wasm_exec_env_t exec_env, struct pollfd *pfds, nfds_t nfds,
61-
int timeout, int *retp);
60+
blocking_op_poll(wasm_exec_env_t exec_env, os_poll_file_handle *pfds,
61+
os_nfds_t nfds, int timeout, int *retp);
6262
#endif
6363

6464
#endif /* end of _BLOCKING_OP_H_ */

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,12 @@ static inline bool
196196
cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
197197
bool abstime) REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
198198
{
199+
#if defined(BH_PLATFORM_ZEPHYR)
200+
// TODO: Implement this for Zephyr
201+
return false;
202+
#else
199203
int ret;
200-
struct timespec ts = {
204+
os_timespec ts = {
201205
.tv_sec = (time_t)(timeout / 1000000000),
202206
.tv_nsec = (long)(timeout % 1000000000),
203207
};
@@ -210,8 +214,8 @@ cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
210214
* realtime clock.
211215
*/
212216
if (cond->clock != CLOCK_REALTIME) {
213-
struct timespec ts_monotonic;
214-
struct timespec ts_realtime;
217+
os_timespec ts_monotonic;
218+
os_timespec ts_realtime;
215219

216220
clock_gettime(cond->clock, &ts_monotonic);
217221
ts.tv_sec -= ts_monotonic.tv_sec;
@@ -229,7 +233,7 @@ cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
229233
++ts.tv_sec;
230234
}
231235
}
232-
#endif
236+
#endif /* !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK */
233237
}
234238
else {
235239
#if CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
@@ -241,7 +245,7 @@ cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
241245
return ret == ETIMEDOUT;
242246
#else
243247
/* Convert to absolute timeout. */
244-
struct timespec ts_now;
248+
os_timespec ts_now;
245249
#if CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK
246250
clock_gettime(cond->clock, &ts_now);
247251
#else
@@ -253,13 +257,14 @@ cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
253257
ts.tv_nsec -= 1000000000;
254258
++ts.tv_sec;
255259
}
256-
#endif
260+
#endif /* CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP */
257261
}
258262

259263
ret = pthread_cond_timedwait(&cond->object, &lock->object, &ts);
260264
bh_assert((ret == 0 || ret == ETIMEDOUT)
261265
&& "pthread_cond_timedwait() failed");
262266
return ret == ETIMEDOUT;
267+
#endif /* BH_PLATFORM_ZEPHYR */
263268
}
264269
#endif
265270

0 commit comments

Comments
 (0)