Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/iwasm/common/wasm_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
if (exec_env) {
wasm_runtime_dump_mem_consumption(exec_env);
(WASMModuleInstance *)module_inst->cur_exception
}
#endif

Expand Down Expand Up @@ -712,7 +713,10 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
}
case VALUE_TYPE_F32:
{
os_printf("%.7g:f32", *(float32 *)(argv1 + k));
// Explicit cast to double to avoid warning.
// Float arguments are promoted to double in variadic
// functions per section 6.5.2.2 of the C99 standard.
os_printf("%.7g:f32", (double)*(float32 *)(argv1 + k));
k++;
break;
}
Expand Down
17 changes: 8 additions & 9 deletions core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,12 +1004,10 @@ update_clock_subscription_data(wasi_subscription_t *in, uint32 nsubscriptions,
}

static wasi_errno_t
execute_interruptible_poll_oneoff(
#if !defined(WASMTIME_SSP_STATIC_CURFDS)
struct fd_table *curfds,
#endif
const __wasi_subscription_t *in, __wasi_event_t *out, size_t nsubscriptions,
size_t *nevents, wasm_exec_env_t exec_env)
execute_interruptible_poll_oneoff(struct fd_table *curfds,
const __wasi_subscription_t *in,
__wasi_event_t *out, size_t nsubscriptions,
size_t *nevents, wasm_exec_env_t exec_env)
{
if (nsubscriptions == 0) {
*nevents = 0;
Expand Down Expand Up @@ -2106,15 +2104,16 @@ wasi_sock_recv(wasm_exec_env_t exec_env, wasi_fd_t sock, iovec_app_t *ri_data,
wasi_roflags_t *ro_flags)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
__wasi_addr_t src_addr;
wasi_errno_t error;

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

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

return error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1904,10 +1904,10 @@ convert_timestamp(__wasi_timestamp_t in, os_timespec *out)
#else
out->tv_nsec = (long)(in % 1000000000);
#endif
in /= 1000000000;
__wasi_timestamp_t temp = in / 1000000000;

// Clamp to the maximum in case it would overflow our system's time_t.
out->tv_sec = (time_t)in < BH_TIME_T_MAX ? (time_t)in : BH_TIME_T_MAX;
out->tv_sec = (time_t)temp < BH_TIME_T_MAX ? (time_t)temp : BH_TIME_T_MAX;
}

__wasi_errno_t
Expand Down Expand Up @@ -2094,7 +2094,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
size_t nsubscriptions,
size_t *nevents) NO_LOCK_ANALYSIS
{
#if defined(BH_PLATFORM_WINDOWS) || defined(BH_PLATFORM_ZEPHYR)
#if defined(BH_PLATFORM_WINDOWS)
return __WASI_ENOSYS;
#else
// Sleeping.
Expand Down Expand Up @@ -2212,7 +2212,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds,
if (error == 0) {
// Proper file descriptor on which we can poll().
pfds[i] = (os_poll_file_handle){
.fd = fos[i]->file_handle,
.fd = fos[i]->file_handle->fd,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file_handle's type is os_file_handle which is typedef int os_file_handle. So a compilation error will be raised: error: invalid type argument of ‘->’ (have ‘os_file_handle’ {aka ‘int’}).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #3633, @lucasAbadFr changed for Zephyr to be the following:

typedef struct zephyr_handle *os_file_handle;

I'll see what I can do to unify this better to align with the POSIX/Linux implementation.

.events = s->u.type == __WASI_EVENTTYPE_FD_READ
? POLLIN
: POLLOUT,
Expand Down Expand Up @@ -2845,23 +2845,37 @@ wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds,
{
struct fd_object *fo;
__wasi_errno_t error;
bh_sockaddr_t sockaddr;
bh_sockaddr_t sockaddr, *sockaddr_ptr = NULL;
int ret;

error = fd_object_get(curfds, &fo, sock, __WASI_RIGHT_FD_READ, 0);
if (error != 0) {
return error;
}

// If the source address is not NULL, the caller is requesting the source
// address to be returned if the protocol supports it. As such, we convert
// the format of the structure pass in prior to the call to the OS
// implementation. If the value is NULL, the POSIX standard states that
// the address is not returned.
if (src_addr != NULL) {
sockaddr_ptr = &sockaddr;
wasi_addr_to_bh_sockaddr(src_addr, &sockaddr);
Comment thread
lum1n0us marked this conversation as resolved.
}

/* Consume bh_sockaddr_t instead of __wasi_addr_t */
ret = blocking_op_socket_recv_from(exec_env, fo->file_handle, buf, buf_len,
0, &sockaddr);
0, sockaddr_ptr);
fd_object_release(exec_env, fo);
if (-1 == ret) {
return convert_errno(errno);
}

bh_sockaddr_to_wasi_addr(&sockaddr, src_addr);
// If the source address is not NULL, we need to convert the sockaddr
// back to __wasi_addr_t format.
if (src_addr != NULL) {
bh_sockaddr_to_wasi_addr(sockaddr_ptr, src_addr);
}

*recv_len = (size_t)ret;
return __WASI_ESUCCESS;
Expand Down
2 changes: 2 additions & 0 deletions core/shared/mem-alloc/ems/ems_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include "ems_gc.h"
#include "ems_gc_internal.h"

#ifndef GB // Some platforms define already, causing build warnings.
#define GB (1 << 30UL)
#endif

#define MARK_NODE_OBJ_CNT 256

Expand Down
40 changes: 30 additions & 10 deletions core/shared/platform/zephyr/platform_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@
#define BH_PLATFORM_ZEPHYR
#endif

#include <limits.h>

#ifndef PATH_MAX
#define PATH_MAX 256
#endif

#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif

#ifndef STDOUT_FILENO
#define STDOUT_FILENO 1
#endif

#ifndef STDERR_FILENO
#define STDERR_FILENO 2
#endif

/* Synchronization primitives for usermode.
* The macros are prefixed with 'z' because when building
* with WAMR_BUILD_LIBC_WASI the same functions are defined,
Expand Down Expand Up @@ -222,6 +240,8 @@ set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func,
typedef int os_dir_stream;
typedef int os_raw_file_handle;

#define OS_DIR_STREAM_INVALID 0

// handle for file system descriptor
typedef struct zephyr_fs_desc {
char *path;
Expand Down Expand Up @@ -259,20 +279,20 @@ typedef unsigned int os_nfds_t;

#define FIONREAD ZFD_IOCTL_FIONREAD

typedef struct {
time_t tv_sec;
long tv_nsec;
} os_timespec;
typedef struct timespec os_timespec;

#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 1
#endif

#define CLOCK_MONOTONIC 4

// TODO: use it in sandboxed posix.c.
// int os_sched_yield(void)
// {
// k_yield();
// return 0;
// }
static inline int
os_sched_yield(void)
{
k_yield();
return 0;
}

static inline os_file_handle
os_get_invalid_handle(void)
Expand Down
Loading
Loading