Apply clang-format for core/iwasm compilation and libraries (#784)

Apply clang-format for core/iwasm/compilation and core/iwasm/libraries files.
Add wasm-c-api empty_imports sample to workflow test.
And enable triggering workflow when core/config.h changes.
This commit is contained in:
Wenyong Huang
2021-10-13 15:13:00 +08:00
committed by GitHub
parent dc65d2910a
commit fb4afc7ca4
87 changed files with 9321 additions and 9829 deletions

View File

@ -10,6 +10,7 @@
void
wasm_runtime_set_exception(wasm_module_inst_t module, const char *exception);
/* clang-format off */
#define get_module_inst(exec_env) \
wasm_runtime_get_module_inst(exec_env)
@ -33,6 +34,7 @@ wasm_runtime_set_exception(wasm_module_inst_t module, const char *exception);
#define module_free(offset) \
wasm_runtime_module_free(module_inst, offset)
/* clang-format on */
typedef struct wasi_prestat_app {
wasi_preopentype_t pr_type;
@ -52,14 +54,13 @@ typedef struct WASIContext {
char **argv_list;
char *env_buf;
char **env_list;
} *wasi_ctx_t;
} * wasi_ctx_t;
wasi_ctx_t
wasm_runtime_get_wasi_ctx(wasm_module_inst_t module_inst);
static inline struct fd_table *
wasi_ctx_get_curfds(wasm_module_inst_t module_inst,
wasi_ctx_t wasi_ctx)
wasi_ctx_get_curfds(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
{
if (!wasi_ctx)
return NULL;
@ -67,8 +68,7 @@ wasi_ctx_get_curfds(wasm_module_inst_t module_inst,
}
static inline struct argv_environ_values *
wasi_ctx_get_argv_environ(wasm_module_inst_t module_inst,
wasi_ctx_t wasi_ctx)
wasi_ctx_get_argv_environ(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
{
if (!wasi_ctx)
return NULL;
@ -76,8 +76,7 @@ wasi_ctx_get_argv_environ(wasm_module_inst_t module_inst,
}
static inline struct fd_prestats *
wasi_ctx_get_prestats(wasm_module_inst_t module_inst,
wasi_ctx_t wasi_ctx)
wasi_ctx_get_prestats(wasm_module_inst_t module_inst, wasi_ctx_t wasi_ctx)
{
if (!wasi_ctx)
return NULL;
@ -90,7 +89,7 @@ wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct argv_environ_values *argv_environ =
wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
size_t argc, argv_buf_size, i;
char **argv;
uint64 total_size;
@ -110,7 +109,7 @@ wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
|| !validate_native_addr(argv_buf, (uint32)argv_buf_size))
return (wasi_errno_t)-1;
total_size = sizeof(char*) * ((uint64)argc + 1);
total_size = sizeof(char *) * ((uint64)argc + 1);
if (total_size >= UINT32_MAX
|| !(argv = wasm_runtime_malloc((uint32)total_size)))
return (wasi_errno_t)-1;
@ -130,8 +129,8 @@ wasi_args_get(wasm_exec_env_t exec_env, uint32 *argv_offsets, char *argv_buf)
}
static wasi_errno_t
wasi_args_sizes_get(wasm_exec_env_t exec_env,
uint32 *argc_app, uint32 *argv_buf_size_app)
wasi_args_sizes_get(wasm_exec_env_t exec_env, uint32 *argc_app,
uint32 *argv_buf_size_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -148,8 +147,7 @@ wasi_args_sizes_get(wasm_exec_env_t exec_env,
argv_environ = wasi_ctx->argv_environ;
err = wasmtime_ssp_args_sizes_get(argv_environ,
&argc, &argv_buf_size);
err = wasmtime_ssp_args_sizes_get(argv_environ, &argc, &argv_buf_size);
if (err)
return err;
@ -173,7 +171,7 @@ wasi_clock_res_get(wasm_exec_env_t exec_env,
static wasi_errno_t
wasi_clock_time_get(wasm_exec_env_t exec_env,
wasi_clockid_t clock_id, /* uint32 clock_id */
wasi_clockid_t clock_id, /* uint32 clock_id */
wasi_timestamp_t precision, /* uint64 precision */
wasi_timestamp_t *time /* uint64 *time */)
{
@ -186,13 +184,13 @@ wasi_clock_time_get(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_environ_get(wasm_exec_env_t exec_env,
uint32 *environ_offsets, char *environ_buf)
wasi_environ_get(wasm_exec_env_t exec_env, uint32 *environ_offsets,
char *environ_buf)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct argv_environ_values *argv_environ =
wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
size_t environ_count, environ_buf_size, i;
uint64 total_size;
char **environs;
@ -201,8 +199,8 @@ wasi_environ_get(wasm_exec_env_t exec_env,
if (!wasi_ctx)
return (wasi_errno_t)-1;
err = wasmtime_ssp_environ_sizes_get(argv_environ,
&environ_count, &environ_buf_size);
err = wasmtime_ssp_environ_sizes_get(argv_environ, &environ_count,
&environ_buf_size);
if (err)
return err;
@ -213,7 +211,7 @@ wasi_environ_get(wasm_exec_env_t exec_env,
|| !validate_native_addr(environ_buf, (uint32)environ_buf_size))
return (wasi_errno_t)-1;
total_size = sizeof(char*) * (((uint64)environ_count + 1));
total_size = sizeof(char *) * (((uint64)environ_count + 1));
if (total_size >= UINT32_MAX
|| !(environs = wasm_runtime_malloc((uint32)total_size)))
@ -234,13 +232,13 @@ wasi_environ_get(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_environ_sizes_get(wasm_exec_env_t exec_env,
uint32 *environ_count_app, uint32 *environ_buf_size_app)
wasi_environ_sizes_get(wasm_exec_env_t exec_env, uint32 *environ_count_app,
uint32 *environ_buf_size_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
struct argv_environ_values *argv_environ =
wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
wasi_ctx_get_argv_environ(module_inst, wasi_ctx);
size_t environ_count, environ_buf_size;
wasi_errno_t err;
@ -251,8 +249,8 @@ wasi_environ_sizes_get(wasm_exec_env_t exec_env,
|| !validate_native_addr(environ_buf_size_app, sizeof(uint32)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_environ_sizes_get(argv_environ,
&environ_count, &environ_buf_size);
err = wasmtime_ssp_environ_sizes_get(argv_environ, &environ_count,
&environ_buf_size);
if (err)
return err;
@ -263,8 +261,8 @@ wasi_environ_sizes_get(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_fd_prestat_get(wasm_exec_env_t exec_env,
wasi_fd_t fd, wasi_prestat_app_t *prestat_app)
wasi_fd_prestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
wasi_prestat_app_t *prestat_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -288,8 +286,8 @@ wasi_fd_prestat_get(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_fd_prestat_dir_name(wasm_exec_env_t exec_env,
wasi_fd_t fd, char *path, uint32 path_len)
wasi_fd_prestat_dir_name(wasm_exec_env_t exec_env, wasi_fd_t fd, char *path,
uint32 path_len)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -298,8 +296,7 @@ wasi_fd_prestat_dir_name(wasm_exec_env_t exec_env,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_prestat_dir_name(prestats,
fd, path, path_len);
return wasmtime_ssp_fd_prestat_dir_name(prestats, fd, path, path_len);
}
static wasi_errno_t
@ -330,9 +327,8 @@ wasi_fd_datasync(wasm_exec_env_t exec_env, wasi_fd_t fd)
}
static wasi_errno_t
wasi_fd_pread(wasm_exec_env_t exec_env,
wasi_fd_t fd, iovec_app_t *iovec_app, uint32 iovs_len,
wasi_filesize_t offset, uint32 *nread_app)
wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app,
uint32 iovs_len, wasi_filesize_t offset, uint32 *nread_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -364,12 +360,12 @@ wasi_fd_pread(wasm_exec_env_t exec_env,
err = (wasi_errno_t)-1;
goto fail;
}
iovec->buf = (void*)addr_app_to_native(iovec_app->buf_offset);
iovec->buf = (void *)addr_app_to_native(iovec_app->buf_offset);
iovec->buf_len = iovec_app->buf_len;
}
err = wasmtime_ssp_fd_pread(curfds, fd, iovec_begin,
iovs_len, offset, &nread);
err = wasmtime_ssp_fd_pread(curfds, fd, iovec_begin, iovs_len, offset,
&nread);
if (err)
goto fail;
@ -384,8 +380,8 @@ fail:
}
static wasi_errno_t
wasi_fd_pwrite(wasm_exec_env_t exec_env,
wasi_fd_t fd, const iovec_app_t *iovec_app, uint32 iovs_len,
wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd,
const iovec_app_t *iovec_app, uint32 iovs_len,
wasi_filesize_t offset, uint32 *nwritten_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
@ -403,7 +399,7 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env,
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
if (!validate_native_addr(nwritten_app, (uint32)sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr((void*)iovec_app, (uint32)total_size))
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
@ -418,12 +414,12 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env,
err = (wasi_errno_t)-1;
goto fail;
}
ciovec->buf = (char*)addr_app_to_native(iovec_app->buf_offset);
ciovec->buf = (char *)addr_app_to_native(iovec_app->buf_offset);
ciovec->buf_len = iovec_app->buf_len;
}
err = wasmtime_ssp_fd_pwrite(curfds, fd, ciovec_begin,
iovs_len, offset, &nwritten);
err = wasmtime_ssp_fd_pwrite(curfds, fd, ciovec_begin, iovs_len, offset,
&nwritten);
if (err)
goto fail;
@ -438,9 +434,8 @@ fail:
}
static wasi_errno_t
wasi_fd_read(wasm_exec_env_t exec_env,
wasi_fd_t fd, const iovec_app_t *iovec_app, uint32 iovs_len,
uint32 *nread_app)
wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd,
const iovec_app_t *iovec_app, uint32 iovs_len, uint32 *nread_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -457,7 +452,7 @@ wasi_fd_read(wasm_exec_env_t exec_env,
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
if (!validate_native_addr(nread_app, (uint32)sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr((void*)iovec_app, (uint32)total_size))
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_iovec_t) * (uint64)iovs_len;
@ -472,12 +467,11 @@ wasi_fd_read(wasm_exec_env_t exec_env,
err = (wasi_errno_t)-1;
goto fail;
}
iovec->buf = (void*)addr_app_to_native(iovec_app->buf_offset);
iovec->buf = (void *)addr_app_to_native(iovec_app->buf_offset);
iovec->buf_len = iovec_app->buf_len;
}
err = wasmtime_ssp_fd_read(curfds, fd,
iovec_begin, iovs_len, &nread);
err = wasmtime_ssp_fd_read(curfds, fd, iovec_begin, iovs_len, &nread);
if (err)
goto fail;
@ -506,9 +500,8 @@ wasi_fd_renumber(wasm_exec_env_t exec_env, wasi_fd_t from, wasi_fd_t to)
}
static wasi_errno_t
wasi_fd_seek(wasm_exec_env_t exec_env,
wasi_fd_t fd, wasi_filedelta_t offset, wasi_whence_t whence,
wasi_filesize_t *newoffset)
wasi_fd_seek(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filedelta_t offset,
wasi_whence_t whence, wasi_filesize_t *newoffset)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -524,8 +517,7 @@ wasi_fd_seek(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_fd_tell(wasm_exec_env_t exec_env,
wasi_fd_t fd, wasi_filesize_t *newoffset)
wasi_fd_tell(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t *newoffset)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -541,8 +533,8 @@ wasi_fd_tell(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_fd_fdstat_get(wasm_exec_env_t exec_env,
wasi_fd_t fd, wasi_fdstat_t *fdstat_app)
wasi_fd_fdstat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
wasi_fdstat_t *fdstat_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -565,8 +557,8 @@ wasi_fd_fdstat_get(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env,
wasi_fd_t fd, wasi_fdflags_t flags)
wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env, wasi_fd_t fd,
wasi_fdflags_t flags)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -579,8 +571,7 @@ wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env,
wasi_fd_t fd,
wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env, wasi_fd_t fd,
wasi_rights_t fs_rights_base,
wasi_rights_t fs_rights_inheriting)
{
@ -591,8 +582,8 @@ wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_fdstat_set_rights(curfds, fd,
fs_rights_base, fs_rights_inheriting);
return wasmtime_ssp_fd_fdstat_set_rights(curfds, fd, fs_rights_base,
fs_rights_inheriting);
}
static wasi_errno_t
@ -628,7 +619,7 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
total_size = sizeof(iovec_app_t) * (uint64)iovs_len;
if (!validate_native_addr(nwritten_app, (uint32)sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr((void*)iovec_app, (uint32)total_size))
|| !validate_native_addr((void *)iovec_app, (uint32)total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_ciovec_t) * (uint64)iovs_len;
@ -643,12 +634,11 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd,
err = (wasi_errno_t)-1;
goto fail;
}
ciovec->buf = (char*)addr_app_to_native(iovec_app->buf_offset);
ciovec->buf = (char *)addr_app_to_native(iovec_app->buf_offset);
ciovec->buf_len = iovec_app->buf_len;
}
err = wasmtime_ssp_fd_write(curfds, fd,
ciovec_begin, iovs_len, &nwritten);
err = wasmtime_ssp_fd_write(curfds, fd, ciovec_begin, iovs_len, &nwritten);
if (err)
goto fail;
@ -663,11 +653,8 @@ fail:
}
static wasi_errno_t
wasi_fd_advise(wasm_exec_env_t exec_env,
wasi_fd_t fd,
wasi_filesize_t offset,
wasi_filesize_t len,
wasi_advice_t advice)
wasi_fd_advise(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
wasi_filesize_t len, wasi_advice_t advice)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -680,9 +667,7 @@ wasi_fd_advise(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_fd_allocate(wasm_exec_env_t exec_env,
wasi_fd_t fd,
wasi_filesize_t offset,
wasi_fd_allocate(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset,
wasi_filesize_t len)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
@ -696,8 +681,8 @@ wasi_fd_allocate(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_path_create_directory(wasm_exec_env_t exec_env,
wasi_fd_t fd, const char *path, uint32 path_len)
wasi_path_create_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
const char *path, uint32 path_len)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -706,17 +691,14 @@ wasi_path_create_directory(wasm_exec_env_t exec_env,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_path_create_directory(curfds, fd,
path, path_len);
return wasmtime_ssp_path_create_directory(curfds, fd, path, path_len);
}
static wasi_errno_t
wasi_path_link(wasm_exec_env_t exec_env,
wasi_fd_t old_fd,
wasi_lookupflags_t old_flags,
const char *old_path, uint32 old_path_len,
wasi_fd_t new_fd,
const char *new_path, uint32 new_path_len)
wasi_path_link(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
wasi_lookupflags_t old_flags, const char *old_path,
uint32 old_path_len, wasi_fd_t new_fd, const char *new_path,
uint32 new_path_len)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -726,20 +708,15 @@ wasi_path_link(wasm_exec_env_t exec_env,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_path_link(curfds, prestats,
old_fd, old_flags, old_path, old_path_len,
new_fd, new_path, new_path_len);
return wasmtime_ssp_path_link(curfds, prestats, old_fd, old_flags, old_path,
old_path_len, new_fd, new_path, new_path_len);
}
static wasi_errno_t
wasi_path_open(wasm_exec_env_t exec_env,
wasi_fd_t dirfd,
wasi_lookupflags_t dirflags,
const char *path, uint32 path_len,
wasi_oflags_t oflags,
wasi_rights_t fs_rights_base,
wasi_rights_t fs_rights_inheriting,
wasi_fdflags_t fs_flags,
wasi_path_open(wasm_exec_env_t exec_env, wasi_fd_t dirfd,
wasi_lookupflags_t dirflags, const char *path, uint32 path_len,
wasi_oflags_t oflags, wasi_rights_t fs_rights_base,
wasi_rights_t fs_rights_inheriting, wasi_fdflags_t fs_flags,
wasi_fd_t *fd_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
@ -754,25 +731,17 @@ wasi_path_open(wasm_exec_env_t exec_env,
if (!validate_native_addr(fd_app, sizeof(wasi_fd_t)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_path_open(curfds,
dirfd, dirflags,
path, path_len,
oflags,
fs_rights_base,
fs_rights_inheriting,
fs_flags,
&fd);
err = wasmtime_ssp_path_open(curfds, dirfd, dirflags, path, path_len,
oflags, fs_rights_base, fs_rights_inheriting,
fs_flags, &fd);
*fd_app = fd;
return err;
}
static wasi_errno_t
wasi_fd_readdir(wasm_exec_env_t exec_env,
wasi_fd_t fd,
void *buf, uint32 buf_len,
wasi_dircookie_t cookie,
uint32 *bufused_app)
wasi_fd_readdir(wasm_exec_env_t exec_env, wasi_fd_t fd, void *buf,
uint32 buf_len, wasi_dircookie_t cookie, uint32 *bufused_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -786,8 +755,7 @@ wasi_fd_readdir(wasm_exec_env_t exec_env,
if (!validate_native_addr(bufused_app, sizeof(uint32)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_fd_readdir(curfds, fd,
buf, buf_len, cookie, &bufused);
err = wasmtime_ssp_fd_readdir(curfds, fd, buf, buf_len, cookie, &bufused);
if (err)
return err;
@ -796,10 +764,8 @@ wasi_fd_readdir(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_path_readlink(wasm_exec_env_t exec_env,
wasi_fd_t fd,
const char *path, uint32 path_len,
char *buf, uint32 buf_len,
wasi_path_readlink(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
uint32 path_len, char *buf, uint32 buf_len,
uint32 *bufused_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
@ -814,9 +780,8 @@ wasi_path_readlink(wasm_exec_env_t exec_env,
if (!validate_native_addr(bufused_app, sizeof(uint32)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_path_readlink(curfds, fd,
path, path_len,
buf, buf_len, &bufused);
err = wasmtime_ssp_path_readlink(curfds, fd, path, path_len, buf, buf_len,
&bufused);
if (err)
return err;
@ -825,9 +790,9 @@ wasi_path_readlink(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_path_rename(wasm_exec_env_t exec_env,
wasi_fd_t old_fd, const char *old_path, uint32 old_path_len,
wasi_fd_t new_fd, const char *new_path, uint32 new_path_len)
wasi_path_rename(wasm_exec_env_t exec_env, wasi_fd_t old_fd,
const char *old_path, uint32 old_path_len, wasi_fd_t new_fd,
const char *new_path, uint32 new_path_len)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -836,14 +801,13 @@ wasi_path_rename(wasm_exec_env_t exec_env,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_path_rename(curfds,
old_fd, old_path, old_path_len,
return wasmtime_ssp_path_rename(curfds, old_fd, old_path, old_path_len,
new_fd, new_path, new_path_len);
}
static wasi_errno_t
wasi_fd_filestat_get(wasm_exec_env_t exec_env,
wasi_fd_t fd, wasi_filestat_t *filestat)
wasi_fd_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
wasi_filestat_t *filestat)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -859,10 +823,8 @@ wasi_fd_filestat_get(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_fd_filestat_set_times(wasm_exec_env_t exec_env,
wasi_fd_t fd,
wasi_timestamp_t st_atim,
wasi_timestamp_t st_mtim,
wasi_fd_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
wasi_timestamp_t st_atim, wasi_timestamp_t st_mtim,
wasi_fstflags_t fstflags)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
@ -872,13 +834,12 @@ wasi_fd_filestat_set_times(wasm_exec_env_t exec_env,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_fd_filestat_set_times(curfds, fd,
st_atim, st_mtim, fstflags);
return wasmtime_ssp_fd_filestat_set_times(curfds, fd, st_atim, st_mtim,
fstflags);
}
static wasi_errno_t
wasi_fd_filestat_set_size(wasm_exec_env_t exec_env,
wasi_fd_t fd,
wasi_fd_filestat_set_size(wasm_exec_env_t exec_env, wasi_fd_t fd,
wasi_filesize_t st_size)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
@ -892,11 +853,9 @@ wasi_fd_filestat_set_size(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_path_filestat_get(wasm_exec_env_t exec_env,
wasi_fd_t fd,
wasi_lookupflags_t flags,
const char *path, uint32 path_len,
wasi_filestat_t *filestat)
wasi_path_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd,
wasi_lookupflags_t flags, const char *path,
uint32 path_len, wasi_filestat_t *filestat)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -908,18 +867,15 @@ wasi_path_filestat_get(wasm_exec_env_t exec_env,
if (!validate_native_addr(filestat, sizeof(wasi_filestat_t)))
return (wasi_errno_t)-1;
return wasmtime_ssp_path_filestat_get(curfds, fd,
flags, path, path_len, filestat);
return wasmtime_ssp_path_filestat_get(curfds, fd, flags, path, path_len,
filestat);
}
static wasi_errno_t
wasi_path_filestat_set_times(wasm_exec_env_t exec_env,
wasi_fd_t fd,
wasi_lookupflags_t flags,
const char *path, uint32 path_len,
wasi_timestamp_t st_atim,
wasi_timestamp_t st_mtim,
wasi_fstflags_t fstflags)
wasi_path_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd,
wasi_lookupflags_t flags, const char *path,
uint32 path_len, wasi_timestamp_t st_atim,
wasi_timestamp_t st_mtim, wasi_fstflags_t fstflags)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -928,15 +884,14 @@ wasi_path_filestat_set_times(wasm_exec_env_t exec_env,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_path_filestat_set_times(curfds, fd,
flags, path, path_len,
st_atim, st_mtim, fstflags);
return wasmtime_ssp_path_filestat_set_times(
curfds, fd, flags, path, path_len, st_atim, st_mtim, fstflags);
}
static wasi_errno_t
wasi_path_symlink(wasm_exec_env_t exec_env,
const char *old_path, uint32 old_path_len,
wasi_fd_t fd, const char *new_path, uint32 new_path_len)
wasi_path_symlink(wasm_exec_env_t exec_env, const char *old_path,
uint32 old_path_len, wasi_fd_t fd, const char *new_path,
uint32 new_path_len)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -946,14 +901,13 @@ wasi_path_symlink(wasm_exec_env_t exec_env,
if (!wasi_ctx)
return (wasi_errno_t)-1;
return wasmtime_ssp_path_symlink(curfds, prestats,
old_path, old_path_len, fd,
new_path, new_path_len);
return wasmtime_ssp_path_symlink(curfds, prestats, old_path, old_path_len,
fd, new_path, new_path_len);
}
static wasi_errno_t
wasi_path_unlink_file(wasm_exec_env_t exec_env,
wasi_fd_t fd, const char *path, uint32 path_len)
wasi_path_unlink_file(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path,
uint32 path_len)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -966,8 +920,8 @@ wasi_path_unlink_file(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_path_remove_directory(wasm_exec_env_t exec_env,
wasi_fd_t fd, const char *path, uint32 path_len)
wasi_path_remove_directory(wasm_exec_env_t exec_env, wasi_fd_t fd,
const char *path, uint32 path_len)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -980,9 +934,8 @@ wasi_path_remove_directory(wasm_exec_env_t exec_env,
}
static wasi_errno_t
wasi_poll_oneoff(wasm_exec_env_t exec_env,
const wasi_subscription_t *in, wasi_event_t *out,
uint32 nsubscriptions, uint32 *nevents_app)
wasi_poll_oneoff(wasm_exec_env_t exec_env, const wasi_subscription_t *in,
wasi_event_t *out, uint32 nsubscriptions, uint32 *nevents_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -993,13 +946,12 @@ wasi_poll_oneoff(wasm_exec_env_t exec_env,
if (!wasi_ctx)
return (wasi_errno_t)-1;
if (!validate_native_addr((void*)in, sizeof(wasi_subscription_t))
if (!validate_native_addr((void *)in, sizeof(wasi_subscription_t))
|| !validate_native_addr(out, sizeof(wasi_event_t))
|| !validate_native_addr(nevents_app, sizeof(uint32)))
return (wasi_errno_t)-1;
err = wasmtime_ssp_poll_oneoff(curfds, in, out,
nsubscriptions, &nevents);
err = wasmtime_ssp_poll_oneoff(curfds, in, out, nsubscriptions, &nevents);
if (err)
return err;
@ -1035,12 +987,9 @@ wasi_random_get(wasm_exec_env_t exec_env, void *buf, uint32 buf_len)
}
static wasi_errno_t
wasi_sock_recv(wasm_exec_env_t exec_env,
wasi_fd_t sock,
iovec_app_t *ri_data, uint32 ri_data_len,
wasi_riflags_t ri_flags,
uint32 *ro_datalen_app,
wasi_roflags_t *ro_flags)
wasi_sock_recv(wasm_exec_env_t exec_env, wasi_fd_t sock, iovec_app_t *ri_data,
uint32 ri_data_len, wasi_riflags_t ri_flags,
uint32 *ro_datalen_app, wasi_roflags_t *ro_flags)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -1073,18 +1022,16 @@ wasi_sock_recv(wasm_exec_env_t exec_env,
err = (wasi_errno_t)-1;
goto fail;
}
iovec->buf = (void*)addr_app_to_native(ri_data->buf_offset);
iovec->buf = (void *)addr_app_to_native(ri_data->buf_offset);
iovec->buf_len = ri_data->buf_len;
}
err = wasmtime_ssp_sock_recv(curfds, sock,
iovec_begin, ri_data_len,
ri_flags, &ro_datalen,
ro_flags);
err = wasmtime_ssp_sock_recv(curfds, sock, iovec_begin, ri_data_len,
ri_flags, &ro_datalen, ro_flags);
if (err)
goto fail;
*(uint32*)ro_datalen_app = (uint32)ro_datalen;
*(uint32 *)ro_datalen_app = (uint32)ro_datalen;
/* success */
err = 0;
@ -1095,11 +1042,9 @@ fail:
}
static wasi_errno_t
wasi_sock_send(wasm_exec_env_t exec_env,
wasi_fd_t sock,
wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock,
const iovec_app_t *si_data, uint32 si_data_len,
wasi_siflags_t si_flags,
uint32 *so_datalen_app)
wasi_siflags_t si_flags, uint32 *so_datalen_app)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -1116,7 +1061,7 @@ wasi_sock_send(wasm_exec_env_t exec_env,
total_size = sizeof(iovec_app_t) * (uint64)si_data_len;
if (!validate_native_addr(so_datalen_app, sizeof(uint32))
|| total_size >= UINT32_MAX
|| !validate_native_addr((void*)si_data, (uint32)total_size))
|| !validate_native_addr((void *)si_data, (uint32)total_size))
return (wasi_errno_t)-1;
total_size = sizeof(wasi_ciovec_t) * (uint64)si_data_len;
@ -1131,12 +1076,11 @@ wasi_sock_send(wasm_exec_env_t exec_env,
err = (wasi_errno_t)-1;
goto fail;
}
ciovec->buf = (char*)addr_app_to_native(si_data->buf_offset);
ciovec->buf = (char *)addr_app_to_native(si_data->buf_offset);
ciovec->buf_len = si_data->buf_len;
}
err = wasmtime_ssp_sock_send(curfds, sock,
ciovec_begin, si_data_len,
err = wasmtime_ssp_sock_send(curfds, sock, ciovec_begin, si_data_len,
si_flags, &so_datalen);
if (err)
goto fail;
@ -1152,8 +1096,7 @@ fail:
}
static wasi_errno_t
wasi_sock_shutdown(wasm_exec_env_t exec_env,
wasi_fd_t sock, wasi_sdflags_t how)
wasi_sock_shutdown(wasm_exec_env_t exec_env, wasi_fd_t sock, wasi_sdflags_t how)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasi_ctx_t wasi_ctx = get_wasi_ctx(module_inst);
@ -1171,8 +1114,10 @@ wasi_sched_yield(wasm_exec_env_t exec_env)
return wasmtime_ssp_sched_yield();
}
#define REG_NATIVE_FUNC(func_name, signature) \
/* clang-format off */
#define REG_NATIVE_FUNC(func_name, signature) \
{ #func_name, wasi_##func_name, signature, NULL }
/* clang-format on */
static NativeSymbol native_symbols_libc_wasi[] = {
REG_NATIVE_FUNC(args_get, "(**)i"),
@ -1228,4 +1173,3 @@ get_libc_wasi_export_apis(NativeSymbol **p_libc_wasi_apis)
*p_libc_wasi_apis = native_symbols_libc_wasi;
return sizeof(native_symbols_libc_wasi) / sizeof(NativeSymbol);
}

View File

@ -1,6 +1,8 @@
/*
* Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
* Part of the Wasmtime Project, under the Apache License v2.0 with
* LLVM Exceptions. See
* https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE
* for license information.
*
* This file declares an interface similar to WASI, but augmented to expose
* some implementation details such as the curfds arguments that we pass
@ -13,6 +15,8 @@
#include <stddef.h>
#include <stdint.h>
/* clang-format off */
#ifdef __cplusplus
#ifndef _Static_assert
#define _Static_assert static_assert
@ -28,7 +32,6 @@
extern "C" {
#endif
_Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout");
_Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout");
_Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout");
@ -891,5 +894,6 @@ __wasi_errno_t wasmtime_ssp_sched_yield(void)
#undef WASMTIME_SSP_SYSCALL_NAME
#endif
/* clang-format on */
#endif /* end of WASMTIME_SSP_H */

View File

@ -1,5 +1,7 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
// information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
@ -32,13 +34,13 @@
#define LOCKS_SHARED(...) LOCK_ANNOTATE(shared_lock_function(__VA_ARGS__))
#define TRYLOCKS_EXCLUSIVE(...) \
LOCK_ANNOTATE(exclusive_trylock_function(__VA_ARGS__))
LOCK_ANNOTATE(exclusive_trylock_function(__VA_ARGS__))
#define TRYLOCKS_SHARED(...) LOCK_ANNOTATE(shared_trylock_function(__VA_ARGS__))
#define UNLOCKS(...) LOCK_ANNOTATE(unlock_function(__VA_ARGS__))
#define REQUIRES_EXCLUSIVE(...) \
LOCK_ANNOTATE(exclusive_locks_required(__VA_ARGS__))
LOCK_ANNOTATE(exclusive_locks_required(__VA_ARGS__))
#define REQUIRES_SHARED(...) LOCK_ANNOTATE(shared_locks_required(__VA_ARGS__))
#define REQUIRES_UNLOCKED(...) LOCK_ANNOTATE(locks_excluded(__VA_ARGS__))
@ -50,8 +52,10 @@ struct LOCKABLE mutex {
pthread_mutex_t object;
};
/* clang-format off */
#define MUTEX_INITIALIZER \
{ PTHREAD_MUTEX_INITIALIZER }
{ PTHREAD_MUTEX_INITIALIZER }
/* clang-format on */
static inline bool
mutex_init(struct mutex *lock) REQUIRES_UNLOCKED(*lock)
@ -117,14 +121,15 @@ rwlock_destroy(struct rwlock *lock) UNLOCKS(*lock) NO_LOCK_ANALYSIS
struct LOCKABLE cond {
pthread_cond_t object;
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK || \
!CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
|| !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
clockid_t clock;
#endif
};
static inline bool
cond_init_monotonic(struct cond *cond) {
cond_init_monotonic(struct cond *cond)
{
bool ret = false;
#if CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK
pthread_condattr_t attr;
@ -147,8 +152,8 @@ fail:
ret = true;
#endif
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK || \
!CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
|| !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
cond->clock = CLOCK_MONOTONIC;
#endif
return ret;
@ -159,28 +164,29 @@ cond_init_realtime(struct cond *cond)
{
if (pthread_cond_init(&cond->object, NULL) != 0)
return false;
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK || \
!CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \
|| !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
cond->clock = CLOCK_REALTIME;
#endif
return true;
}
static inline void
cond_destroy(struct cond *cond) {
cond_destroy(struct cond *cond)
{
pthread_cond_destroy(&cond->object);
}
static inline void
cond_signal(struct cond *cond) {
cond_signal(struct cond *cond)
{
pthread_cond_signal(&cond->object);
}
#if !CONFIG_HAS_CLOCK_NANOSLEEP
static inline bool
cond_timedwait(struct cond *cond, struct mutex *lock,
uint64_t timeout, bool abstime)
REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout,
bool abstime) REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS
{
int ret;
struct timespec ts = {
@ -220,8 +226,8 @@ cond_timedwait(struct cond *cond, struct mutex *lock,
else {
#if CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
/* Implementation supports relative timeouts. */
ret = pthread_cond_timedwait_relative_np(&cond->object,
&lock->object, &ts);
ret = pthread_cond_timedwait_relative_np(&cond->object, &lock->object,
&ts);
bh_assert((ret == 0 || ret == ETIMEDOUT)
&& "pthread_cond_timedwait_relative_np() failed");
return ret == ETIMEDOUT;

View File

@ -1,5 +1,7 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
// information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
@ -12,29 +14,29 @@
#ifndef COMMON_LIMITS_H
#define COMMON_LIMITS_H
#define NUMERIC_MIN(t) \
_Generic((t)0, char \
: CHAR_MIN, signed char \
: SCHAR_MIN, unsigned char : 0, short \
: SHRT_MIN, unsigned short : 0, int \
: INT_MIN, unsigned int : 0, long \
: LONG_MIN, unsigned long : 0, long long \
: LLONG_MIN, unsigned long long : 0, default \
: (void)0)
#define NUMERIC_MIN(t) \
_Generic((t)0, char \
: CHAR_MIN, signed char \
: SCHAR_MIN, unsigned char : 0, short \
: SHRT_MIN, unsigned short : 0, int \
: INT_MIN, unsigned int : 0, long \
: LONG_MIN, unsigned long : 0, long long \
: LLONG_MIN, unsigned long long : 0, default \
: (void)0)
#define NUMERIC_MAX(t) \
_Generic((t)0, char \
: CHAR_MAX, signed char \
: SCHAR_MAX, unsigned char \
: UCHAR_MAX, short \
: SHRT_MAX, unsigned short \
: USHRT_MAX, int \
: INT_MAX, unsigned int \
: UINT_MAX, long \
: LONG_MAX, unsigned long \
: ULONG_MAX, long long \
: LLONG_MAX, unsigned long long \
: ULLONG_MAX, default \
: (void)0)
#define NUMERIC_MAX(t) \
_Generic((t)0, char \
: CHAR_MAX, signed char \
: SCHAR_MAX, unsigned char \
: UCHAR_MAX, short \
: SHRT_MAX, unsigned short \
: USHRT_MAX, int \
: INT_MAX, unsigned int \
: UINT_MAX, long \
: LONG_MAX, unsigned long \
: ULONG_MAX, long long \
: LLONG_MAX, unsigned long long \
: ULLONG_MAX, default \
: (void)0)
#endif

View File

@ -1,5 +1,7 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
// information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
@ -20,41 +22,48 @@ struct fd_prestat;
struct syscalls;
struct fd_table {
struct rwlock lock;
struct fd_entry *entries;
size_t size;
size_t used;
struct rwlock lock;
struct fd_entry *entries;
size_t size;
size_t used;
};
struct fd_prestats {
struct rwlock lock;
struct fd_prestat *prestats;
size_t size;
size_t used;
struct rwlock lock;
struct fd_prestat *prestats;
size_t size;
size_t used;
};
struct argv_environ_values {
const char *argv_buf;
size_t argv_buf_size;
char **argv_list;
size_t argc;
char *environ_buf;
size_t environ_buf_size;
char **environ_list;
size_t environ_count;
const char *argv_buf;
size_t argv_buf_size;
char **argv_list;
size_t argc;
char *environ_buf;
size_t environ_buf_size;
char **environ_list;
size_t environ_count;
};
bool fd_table_init(struct fd_table *);
bool fd_table_insert_existing(struct fd_table *, __wasi_fd_t, int);
bool fd_prestats_init(struct fd_prestats *);
bool fd_prestats_insert(struct fd_prestats *, const char *, __wasi_fd_t);
bool argv_environ_init(struct argv_environ_values *argv_environ,
char *argv_buf, size_t argv_buf_size,
char **argv_list, size_t argc,
char *environ_buf, size_t environ_buf_size,
char **environ_list, size_t environ_count);
void argv_environ_destroy(struct argv_environ_values *argv_environ);
void fd_table_destroy(struct fd_table *ft);
void fd_prestats_destroy(struct fd_prestats *pt);
bool
fd_table_init(struct fd_table *);
bool
fd_table_insert_existing(struct fd_table *, __wasi_fd_t, int);
bool
fd_prestats_init(struct fd_prestats *);
bool
fd_prestats_insert(struct fd_prestats *, const char *, __wasi_fd_t);
bool
argv_environ_init(struct argv_environ_values *argv_environ, char *argv_buf,
size_t argv_buf_size, char **argv_list, size_t argc,
char *environ_buf, size_t environ_buf_size,
char **environ_list, size_t environ_count);
void
argv_environ_destroy(struct argv_environ_values *argv_environ);
void
fd_table_destroy(struct fd_table *ft);
void
fd_prestats_destroy(struct fd_prestats *pt);
#endif

View File

@ -1,5 +1,7 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
// information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
@ -15,76 +17,82 @@
// LIST: Double-linked list.
#define LIST_HEAD(name, type) \
struct name { \
struct type *l_first; \
}
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
struct name { \
struct type *l_first; \
}
#define LIST_ENTRY(type) \
struct { \
struct type *l_next; \
struct type **l_prev; \
}
/* clang-format off */
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
/* clang-format on */
#define LIST_ENTRY(type) \
struct { \
struct type *l_next; \
struct type **l_prev; \
}
#define LIST_FOREACH(var, head, field) \
for ((var) = (head)->l_first; (var) != NULL; (var) = (var)->field.l_next)
#define LIST_INIT(head) \
do { \
(head)->l_first = NULL; \
} while (0)
#define LIST_INSERT_HEAD(head, element, field) \
do { \
(element)->field.l_next = (head)->l_first; \
if ((head)->l_first != NULL) \
(head)->l_first->field.l_prev = &(element)->field.l_next; \
(head)->l_first = (element); \
(element)->field.l_prev = &(head)->l_first; \
} while (0)
#define LIST_REMOVE(element, field) \
do { \
if ((element)->field.l_next != NULL) \
(element)->field.l_next->field.l_prev = (element)->field.l_prev; \
*(element)->field.l_prev = (element)->field.l_next; \
} while (0)
for ((var) = (head)->l_first; (var) != NULL; (var) = (var)->field.l_next)
#define LIST_INIT(head) \
do { \
(head)->l_first = NULL; \
} while (0)
#define LIST_INSERT_HEAD(head, element, field) \
do { \
(element)->field.l_next = (head)->l_first; \
if ((head)->l_first != NULL) \
(head)->l_first->field.l_prev = &(element)->field.l_next; \
(head)->l_first = (element); \
(element)->field.l_prev = &(head)->l_first; \
} while (0)
#define LIST_REMOVE(element, field) \
do { \
if ((element)->field.l_next != NULL) \
(element)->field.l_next->field.l_prev = (element)->field.l_prev; \
*(element)->field.l_prev = (element)->field.l_next; \
} while (0)
// TAILQ: Double-linked list with tail pointer.
#define TAILQ_HEAD(name, type) \
struct name { \
struct type *t_first; \
struct type **t_last; \
}
struct name { \
struct type *t_first; \
struct type **t_last; \
}
#define TAILQ_ENTRY(type) \
struct { \
struct type *t_next; \
struct type **t_prev; \
}
#define TAILQ_ENTRY(type) \
struct { \
struct type *t_next; \
struct type **t_prev; \
}
#define TAILQ_EMPTY(head) ((head)->t_first == NULL)
#define TAILQ_FIRST(head) ((head)->t_first)
#define TAILQ_FOREACH(var, head, field) \
for ((var) = (head)->t_first; (var) != NULL; (var) = (var)->field.t_next)
#define TAILQ_INIT(head) \
do { \
(head)->t_first = NULL; \
(head)->t_last = &(head)->t_first; \
} while (0)
#define TAILQ_INSERT_TAIL(head, elm, field) \
do { \
(elm)->field.t_next = NULL; \
(elm)->field.t_prev = (head)->t_last; \
*(head)->t_last = (elm); \
(head)->t_last = &(elm)->field.t_next; \
} while (0)
#define TAILQ_REMOVE(head, element, field) \
do { \
if ((element)->field.t_next != NULL) \
(element)->field.t_next->field.t_prev = (element)->field.t_prev; \
else \
(head)->t_last = (element)->field.t_prev; \
*(element)->field.t_prev = (element)->field.t_next; \
} while (0)
for ((var) = (head)->t_first; (var) != NULL; (var) = (var)->field.t_next)
#define TAILQ_INIT(head) \
do { \
(head)->t_first = NULL; \
(head)->t_last = &(head)->t_first; \
} while (0)
#define TAILQ_INSERT_TAIL(head, elm, field) \
do { \
(elm)->field.t_next = NULL; \
(elm)->field.t_prev = (head)->t_last; \
*(head)->t_last = (elm); \
(head)->t_last = &(elm)->field.t_next; \
} while (0)
#define TAILQ_REMOVE(head, element, field) \
do { \
if ((element)->field.t_next != NULL) \
(element)->field.t_next->field.t_prev = (element)->field.t_prev; \
else \
(head)->t_last = (element)->field.t_prev; \
*(element)->field.t_prev = (element)->field.t_next; \
} while (0)
#endif

View File

@ -1,5 +1,7 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
// information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
@ -15,8 +17,10 @@
#if CONFIG_HAS_ARC4RANDOM_BUF
void random_buf(void *buf, size_t len) {
arc4random_buf(buf, len);
void
random_buf(void *buf, size_t len)
{
arc4random_buf(buf, len);
}
#elif CONFIG_HAS_GETRANDOM
@ -25,42 +29,48 @@ void random_buf(void *buf, size_t len) {
#include <sys/random.h>
#endif
void random_buf(void *buf, size_t len) {
for (;;) {
ssize_t x = getrandom(buf, len, 0);
if (x < 0) {
if (errno == EINTR)
continue;
os_printf("getrandom failed: %s", strerror(errno));
abort();
}
if ((size_t)x == len)
return;
buf = (void *)((unsigned char *)buf + x);
len -= (size_t)x;
}
void
random_buf(void *buf, size_t len)
{
for (;;) {
ssize_t x = getrandom(buf, len, 0);
if (x < 0) {
if (errno == EINTR)
continue;
os_printf("getrandom failed: %s", strerror(errno));
abort();
}
if ((size_t)x == len)
return;
buf = (void *)((unsigned char *)buf + x);
len -= (size_t)x;
}
}
#else
static int urandom;
static void open_urandom(void) {
urandom = open("/dev/urandom", O_RDONLY);
if (urandom < 0) {
os_printf("Failed to open /dev/urandom\n");
abort();
}
static void
open_urandom(void)
{
urandom = open("/dev/urandom", O_RDONLY);
if (urandom < 0) {
os_printf("Failed to open /dev/urandom\n");
abort();
}
}
void random_buf(void *buf, size_t len) {
static pthread_once_t open_once = PTHREAD_ONCE_INIT;
pthread_once(&open_once, open_urandom);
void
random_buf(void *buf, size_t len)
{
static pthread_once_t open_once = PTHREAD_ONCE_INIT;
pthread_once(&open_once, open_urandom);
if ((size_t)read(urandom, buf, len) != len) {
os_printf("Short read on /dev/urandom\n");
abort();
}
if ((size_t)read(urandom, buf, len) != len) {
os_printf("Short read on /dev/urandom\n");
abort();
}
}
#endif
@ -72,15 +82,17 @@ void random_buf(void *buf, size_t len) {
// arc4random() until it lies within the range [2^k % upper, 2^k). As
// this range has length k * upper, we can safely obtain a number
// without any modulo bias.
uintmax_t random_uniform(uintmax_t upper) {
// Compute 2^k % upper
// == (2^k - upper) % upper
// == -upper % upper.
uintmax_t lower = -upper % upper;
for (;;) {
uintmax_t value;
random_buf(&value, sizeof(value));
if (value >= lower)
return value % upper;
}
uintmax_t
random_uniform(uintmax_t upper)
{
// Compute 2^k % upper
// == (2^k - upper) % upper
// == -upper % upper.
uintmax_t lower = -upper % upper;
for (;;) {
uintmax_t value;
random_buf(&value, sizeof(value));
if (value >= lower)
return value % upper;
}
}

View File

@ -1,5 +1,7 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
// information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
@ -12,7 +14,8 @@
#ifndef RANDOM_H
#define RANDOM_H
void random_buf(void *, size_t);
void
random_buf(void *, size_t);
uintmax_t random_uniform(uintmax_t);
#endif

View File

@ -1,5 +1,7 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
// information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
@ -46,8 +48,8 @@ refcount_acquire(struct refcount *r) PRODUCES(*r)
static inline bool
refcount_release(struct refcount *r) CONSUMES(*r)
{
int old = (int)atomic_fetch_sub_explicit(&r->count, 1,
memory_order_release);
int old =
(int)atomic_fetch_sub_explicit(&r->count, 1, memory_order_release);
bh_assert(old != 0 && "Reference count becoming negative");
return old == 1;
}

View File

@ -1,5 +1,7 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
// information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
@ -12,6 +14,8 @@
#ifndef RIGHTS_H
#define RIGHTS_H
/* clang-format off */
#define RIGHTS_ALL \
(__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_READ | \
__WASI_RIGHT_FD_SEEK | __WASI_RIGHT_FD_FDSTAT_SET_FLAGS | \
@ -80,4 +84,6 @@
__WASI_RIGHT_POLL_FD_READWRITE)
#define RIGHTS_TTY_INHERITING 0
/* clang-format on */
#endif

View File

@ -1,5 +1,7 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
// information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
@ -12,6 +14,7 @@
#ifndef SIGNALS_H
#define SIGNALS_H
void signals_init(void);
void
signals_init(void);
#endif

View File

@ -1,5 +1,7 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
// information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
@ -14,7 +16,8 @@
#include <stdlib.h>
#if defined(__FreeBSD__) || defined(__APPLE__) || (defined(ANDROID) && __ANDROID_API__ < 28)
#if defined(__FreeBSD__) || defined(__APPLE__) \
|| (defined(ANDROID) && __ANDROID_API__ < 28)
#define CONFIG_HAS_ARC4RANDOM_BUF 1
#else
#define CONFIG_HAS_ARC4RANDOM_BUF 0
@ -22,10 +25,9 @@
// On Linux, prefer to use getrandom, though it isn't available in
// GLIBC before 2.25.
#if defined(__linux__) && \
(!defined(__GLIBC__) || \
__GLIBC__ > 2 || \
(__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
#if defined(__linux__) \
&& (!defined(__GLIBC__) || __GLIBC__ > 2 \
|| (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
#define CONFIG_HAS_GETRANDOM 1
#else
#define CONFIG_HAS_GETRANDOM 0

View File

@ -1,5 +1,7 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
// information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
@ -27,7 +29,8 @@ bh_strndup(const char *s, size_t n)
}
char *
str_nullterminate(const char *s, size_t len) {
str_nullterminate(const char *s, size_t len)
{
/* Copy string */
char *ret = bh_strndup(s, len);
@ -40,5 +43,5 @@ str_nullterminate(const char *s, size_t len) {
errno = EILSEQ;
return NULL;
}
return ret;
return ret;
}

View File

@ -1,5 +1,7 @@
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license information.
// Part of the Wasmtime Project, under the Apache License v2.0 with LLVM
// Exceptions. See
// https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE for license
// information.
//
// Significant parts of this file are derived from cloudabi-utils. See
// https://github.com/bytecodealliance/wasmtime/blob/main/lib/wasi/sandboxed-system-primitives/src/LICENSE
@ -14,6 +16,7 @@
#include "ssp_config.h"
char *str_nullterminate(const char *, size_t);
char *
str_nullterminate(const char *, size_t);
#endif