Skip to content

Commit

Permalink
deps: update to uvwasi 0.0.9
Browse files Browse the repository at this point in the history
Notable changes:

- A `DEBUG()` macro and `UVWASI_DEBUG_LOG` build option have been
  added to improve debugging.
- Path length restrictions have been removed across the codebase.
- Initial support for `poll_oneoff()` has been added on all
  platforms. The implementation is based on `uv_poll_t`'s.
- A new `uvwasi_size_t` has been introduced across the WASI system
  call API. This provides consistent 32-bit `size_t`'s.
- The cmake test targets are now only generated if uvwasi is the
  root project to avoid conflicts with targets from embedders.
- `uv.h` has been removed from the public headers.
- A serialization/deserialization API has been added to simplify
  the process of working with WASM memory. This also hides many
  WASI <--> WASM interfacing implementation details from
  embedders.
- A memory corruption bug on Windows related to path resolution
  has been fixed.

PR-URL: #33445
Fixes: #33403
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
  • Loading branch information
cjihrig authored and targos committed Jun 2, 2020
1 parent 9d6fd45 commit 8d47e8b
Show file tree
Hide file tree
Showing 14 changed files with 1,619 additions and 584 deletions.
106 changes: 55 additions & 51 deletions deps/uvwasi/include/uvwasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
extern "C" {
#endif

#include "uv.h"
#include "wasi_serdes.h"
#include "wasi_types.h"
#include "fd_table.h"

#define UVWASI_VERSION_MAJOR 0
#define UVWASI_VERSION_MINOR 0
#define UVWASI_VERSION_PATCH 8
#define UVWASI_VERSION_PATCH 9
#define UVWASI_VERSION_HEX ((UVWASI_VERSION_MAJOR << 16) | \
(UVWASI_VERSION_MINOR << 8) | \
(UVWASI_VERSION_PATCH))
Expand All @@ -35,16 +34,18 @@ typedef struct uvwasi_mem_s {
uvwasi_realloc realloc;
} uvwasi_mem_t;

struct uvwasi_fd_table_t;

typedef struct uvwasi_s {
struct uvwasi_fd_table_t fds;
size_t argc;
struct uvwasi_fd_table_t* fds;
uvwasi_size_t argc;
char** argv;
char* argv_buf;
size_t argv_buf_size;
size_t envc;
uvwasi_size_t argv_buf_size;
uvwasi_size_t envc;
char** env;
char* env_buf;
size_t env_buf_size;
uvwasi_size_t env_buf_size;
const uvwasi_mem_t* allocator;
} uvwasi_t;

Expand All @@ -54,12 +55,12 @@ typedef struct uvwasi_preopen_s {
} uvwasi_preopen_t;

typedef struct uvwasi_options_s {
size_t fd_table_size;
size_t preopenc;
uvwasi_size_t fd_table_size;
uvwasi_size_t preopenc;
uvwasi_preopen_t* preopens;
size_t argc;
char** argv;
char** envp;
uvwasi_size_t argc;
const char** argv;
const char** envp;
uvwasi_fd_t in;
uvwasi_fd_t out;
uvwasi_fd_t err;
Expand All @@ -69,17 +70,18 @@ typedef struct uvwasi_options_s {
/* Embedder API. */
uvwasi_errno_t uvwasi_init(uvwasi_t* uvwasi, uvwasi_options_t* options);
void uvwasi_destroy(uvwasi_t* uvwasi);
/* Use int instead of uv_file to avoid needing uv.h */
uvwasi_errno_t uvwasi_embedder_remap_fd(uvwasi_t* uvwasi,
const uvwasi_fd_t fd,
uv_file new_host_fd);
int new_host_fd);
const char* uvwasi_embedder_err_code_to_string(uvwasi_errno_t code);


/* WASI system call API. */
uvwasi_errno_t uvwasi_args_get(uvwasi_t* uvwasi, char** argv, char* argv_buf);
uvwasi_errno_t uvwasi_args_sizes_get(uvwasi_t* uvwasi,
size_t* argc,
size_t* argv_buf_size);
uvwasi_size_t* argc,
uvwasi_size_t* argv_buf_size);
uvwasi_errno_t uvwasi_clock_res_get(uvwasi_t* uvwasi,
uvwasi_clockid_t clock_id,
uvwasi_timestamp_t* resolution);
Expand All @@ -91,8 +93,8 @@ uvwasi_errno_t uvwasi_environ_get(uvwasi_t* uvwasi,
char** environment,
char* environ_buf);
uvwasi_errno_t uvwasi_environ_sizes_get(uvwasi_t* uvwasi,
size_t* environ_count,
size_t* environ_buf_size);
uvwasi_size_t* environ_count,
uvwasi_size_t* environ_buf_size);
uvwasi_errno_t uvwasi_fd_advise(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
uvwasi_filesize_t offset,
Expand Down Expand Up @@ -129,33 +131,33 @@ uvwasi_errno_t uvwasi_fd_filestat_set_times(uvwasi_t* uvwasi,
uvwasi_errno_t uvwasi_fd_pread(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
const uvwasi_iovec_t* iovs,
size_t iovs_len,
uvwasi_size_t iovs_len,
uvwasi_filesize_t offset,
size_t* nread);
uvwasi_size_t* nread);
uvwasi_errno_t uvwasi_fd_prestat_get(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
uvwasi_prestat_t* buf);
uvwasi_errno_t uvwasi_fd_prestat_dir_name(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
char* path,
size_t path_len);
uvwasi_size_t path_len);
uvwasi_errno_t uvwasi_fd_pwrite(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
const uvwasi_ciovec_t* iovs,
size_t iovs_len,
uvwasi_size_t iovs_len,
uvwasi_filesize_t offset,
size_t* nwritten);
uvwasi_size_t* nwritten);
uvwasi_errno_t uvwasi_fd_read(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
const uvwasi_iovec_t* iovs,
size_t iovs_len,
size_t* nread);
uvwasi_size_t iovs_len,
uvwasi_size_t* nread);
uvwasi_errno_t uvwasi_fd_readdir(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
void* buf,
size_t buf_len,
uvwasi_size_t buf_len,
uvwasi_dircookie_t cookie,
size_t* bufused);
uvwasi_size_t* bufused);
uvwasi_errno_t uvwasi_fd_renumber(uvwasi_t* uvwasi,
uvwasi_fd_t from,
uvwasi_fd_t to);
Expand All @@ -171,39 +173,39 @@ uvwasi_errno_t uvwasi_fd_tell(uvwasi_t* uvwasi,
uvwasi_errno_t uvwasi_fd_write(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
const uvwasi_ciovec_t* iovs,
size_t iovs_len,
size_t* nwritten);
uvwasi_size_t iovs_len,
uvwasi_size_t* nwritten);
uvwasi_errno_t uvwasi_path_create_directory(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
const char* path,
size_t path_len);
uvwasi_size_t path_len);
uvwasi_errno_t uvwasi_path_filestat_get(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
uvwasi_lookupflags_t flags,
const char* path,
size_t path_len,
uvwasi_size_t path_len,
uvwasi_filestat_t* buf);
uvwasi_errno_t uvwasi_path_filestat_set_times(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
uvwasi_lookupflags_t flags,
const char* path,
size_t path_len,
uvwasi_size_t path_len,
uvwasi_timestamp_t st_atim,
uvwasi_timestamp_t st_mtim,
uvwasi_fstflags_t fst_flags);
uvwasi_errno_t uvwasi_path_link(uvwasi_t* uvwasi,
uvwasi_fd_t old_fd,
uvwasi_lookupflags_t old_flags,
const char* old_path,
size_t old_path_len,
uvwasi_size_t old_path_len,
uvwasi_fd_t new_fd,
const char* new_path,
size_t new_path_len);
uvwasi_size_t new_path_len);
uvwasi_errno_t uvwasi_path_open(uvwasi_t* uvwasi,
uvwasi_fd_t dirfd,
uvwasi_lookupflags_t dirflags,
const char* path,
size_t path_len,
uvwasi_size_t path_len,
uvwasi_oflags_t o_flags,
uvwasi_rights_t fs_rights_base,
uvwasi_rights_t fs_rights_inheriting,
Expand All @@ -212,53 +214,55 @@ uvwasi_errno_t uvwasi_path_open(uvwasi_t* uvwasi,
uvwasi_errno_t uvwasi_path_readlink(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
const char* path,
size_t path_len,
uvwasi_size_t path_len,
char* buf,
size_t buf_len,
size_t* bufused);
uvwasi_size_t buf_len,
uvwasi_size_t* bufused);
uvwasi_errno_t uvwasi_path_remove_directory(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
const char* path,
size_t path_len);
uvwasi_size_t path_len);
uvwasi_errno_t uvwasi_path_rename(uvwasi_t* uvwasi,
uvwasi_fd_t old_fd,
const char* old_path,
size_t old_path_len,
uvwasi_size_t old_path_len,
uvwasi_fd_t new_fd,
const char* new_path,
size_t new_path_len);
uvwasi_size_t new_path_len);
uvwasi_errno_t uvwasi_path_symlink(uvwasi_t* uvwasi,
const char* old_path,
size_t old_path_len,
uvwasi_size_t old_path_len,
uvwasi_fd_t fd,
const char* new_path,
size_t new_path_len);
uvwasi_size_t new_path_len);
uvwasi_errno_t uvwasi_path_unlink_file(uvwasi_t* uvwasi,
uvwasi_fd_t fd,
const char* path,
size_t path_len);
uvwasi_size_t path_len);
uvwasi_errno_t uvwasi_poll_oneoff(uvwasi_t* uvwasi,
const uvwasi_subscription_t* in,
uvwasi_event_t* out,
size_t nsubscriptions,
size_t* nevents);
uvwasi_size_t nsubscriptions,
uvwasi_size_t* nevents);
uvwasi_errno_t uvwasi_proc_exit(uvwasi_t* uvwasi, uvwasi_exitcode_t rval);
uvwasi_errno_t uvwasi_proc_raise(uvwasi_t* uvwasi, uvwasi_signal_t sig);
uvwasi_errno_t uvwasi_random_get(uvwasi_t* uvwasi, void* buf, size_t buf_len);
uvwasi_errno_t uvwasi_random_get(uvwasi_t* uvwasi,
void* buf,
uvwasi_size_t buf_len);
uvwasi_errno_t uvwasi_sched_yield(uvwasi_t* uvwasi);
uvwasi_errno_t uvwasi_sock_recv(uvwasi_t* uvwasi,
uvwasi_fd_t sock,
const uvwasi_iovec_t* ri_data,
size_t ri_data_len,
uvwasi_size_t ri_data_len,
uvwasi_riflags_t ri_flags,
size_t* ro_datalen,
uvwasi_size_t* ro_datalen,
uvwasi_roflags_t* ro_flags);
uvwasi_errno_t uvwasi_sock_send(uvwasi_t* uvwasi,
uvwasi_fd_t sock,
const uvwasi_ciovec_t* si_data,
size_t si_data_len,
uvwasi_size_t si_data_len,
uvwasi_siflags_t si_flags,
size_t* so_datalen);
uvwasi_size_t* so_datalen);
uvwasi_errno_t uvwasi_sock_shutdown(uvwasi_t* uvwasi,
uvwasi_fd_t sock,
uvwasi_sdflags_t how);
Expand Down
145 changes: 145 additions & 0 deletions deps/uvwasi/include/wasi_serdes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#ifndef __UVWASI_SERDES_H__
#define __UVWASI_SERDES_H__

#include "wasi_types.h"

/* Basic uint{8,16,32,64}_t read/write functions. */

#define BASIC_TYPE_(name, type) \
void uvwasi_serdes_write_##name(void* ptr, size_t offset, type value); \
type uvwasi_serdes_read_##name(const void* ptr, size_t offset); \

#define BASIC_TYPE(type) BASIC_TYPE_(type, type)
#define BASIC_TYPE_UVWASI(type) BASIC_TYPE_(type, uvwasi_##type)

#define UVWASI_SERDES_SIZE_uint8_t sizeof(uint8_t)
BASIC_TYPE(uint8_t)
#define UVWASI_SERDES_SIZE_uint16_t sizeof(uint16_t)
BASIC_TYPE(uint16_t)
#define UVWASI_SERDES_SIZE_uint32_t sizeof(uint32_t)
BASIC_TYPE(uint32_t)
#define UVWASI_SERDES_SIZE_uint64_t sizeof(uint64_t)
BASIC_TYPE(uint64_t)

#define UVWASI_SERDES_SIZE_advice_t sizeof(uvwasi_advice_t)
BASIC_TYPE_UVWASI(advice_t)
#define UVWASI_SERDES_SIZE_clockid_t sizeof(uvwasi_clockid_t)
BASIC_TYPE_UVWASI(clockid_t)
#define UVWASI_SERDES_SIZE_device_t sizeof(uvwasi_device_t)
BASIC_TYPE_UVWASI(device_t)
#define UVWASI_SERDES_SIZE_dircookie_t sizeof(uvwasi_dircookie_t)
BASIC_TYPE_UVWASI(dircookie_t)
#define UVWASI_SERDES_SIZE_eventrwflags_t sizeof(uvwasi_eventrwflags_t)
BASIC_TYPE_UVWASI(eventrwflags_t)
#define UVWASI_SERDES_SIZE_eventtype_t sizeof(uvwasi_eventtype_t)
BASIC_TYPE_UVWASI(eventtype_t)
#define UVWASI_SERDES_SIZE_exitcode_t sizeof(uvwasi_exitcode_t)
BASIC_TYPE_UVWASI(exitcode_t)
#define UVWASI_SERDES_SIZE_fd_t sizeof(uvwasi_fd_t)
BASIC_TYPE_UVWASI(fd_t)
#define UVWASI_SERDES_SIZE_fdflags_t sizeof(uvwasi_fdflags_t)
BASIC_TYPE_UVWASI(fdflags_t)
#define UVWASI_SERDES_SIZE_filesize_t sizeof(uvwasi_filesize_t)
BASIC_TYPE_UVWASI(filesize_t)
#define UVWASI_SERDES_SIZE_fstflags_t sizeof(uvwasi_fstflags_t)
BASIC_TYPE_UVWASI(fstflags_t)
#define UVWASI_SERDES_SIZE_inode_t sizeof(uvwasi_inode_t)
BASIC_TYPE_UVWASI(inode_t)
#define UVWASI_SERDES_SIZE_linkcount_t sizeof(uvwasi_linkcount_t)
BASIC_TYPE_UVWASI(linkcount_t)
#define UVWASI_SERDES_SIZE_lookupflags_t sizeof(uvwasi_lookupflags_t)
BASIC_TYPE_UVWASI(lookupflags_t)
#define UVWASI_SERDES_SIZE_oflags_t sizeof(uvwasi_oflags_t)
BASIC_TYPE_UVWASI(oflags_t)
#define UVWASI_SERDES_SIZE_preopentype_t sizeof(uvwasi_preopentype_t)
BASIC_TYPE_UVWASI(preopentype_t)
#define UVWASI_SERDES_SIZE_riflags_t sizeof(uvwasi_riflags_t)
BASIC_TYPE_UVWASI(riflags_t)
#define UVWASI_SERDES_SIZE_rights_t sizeof(uvwasi_rights_t)
BASIC_TYPE_UVWASI(rights_t)
#define UVWASI_SERDES_SIZE_roflags_t sizeof(uvwasi_roflags_t)
BASIC_TYPE_UVWASI(roflags_t)
#define UVWASI_SERDES_SIZE_sdflags_t sizeof(uvwasi_sdflags_t)
BASIC_TYPE_UVWASI(sdflags_t)
#define UVWASI_SERDES_SIZE_siflags_t sizeof(uvwasi_siflags_t)
BASIC_TYPE_UVWASI(siflags_t)
#define UVWASI_SERDES_SIZE_size_t sizeof(uvwasi_size_t)
BASIC_TYPE_UVWASI(size_t)
#define UVWASI_SERDES_SIZE_inode_t sizeof(uvwasi_inode_t)
BASIC_TYPE_UVWASI(inode_t)
#define UVWASI_SERDES_SIZE_signal_t sizeof(uvwasi_signal_t)
BASIC_TYPE_UVWASI(signal_t)
#define UVWASI_SERDES_SIZE_subclockflags_t sizeof(uvwasi_subclockflags_t)
BASIC_TYPE_UVWASI(subclockflags_t)
#define UVWASI_SERDES_SIZE_timestamp_t sizeof(uvwasi_timestamp_t)
BASIC_TYPE_UVWASI(timestamp_t)
#define UVWASI_SERDES_SIZE_userdata_t sizeof(uvwasi_userdata_t)
BASIC_TYPE_UVWASI(userdata_t)
#define UVWASI_SERDES_SIZE_whence_t sizeof(uvwasi_whence_t)
BASIC_TYPE_UVWASI(whence_t)

#undef BASIC_TYPE_UVWASI
#undef BASIC_TYPE
#undef BASIC_TYPE_

/* WASI structure read/write functions. */

#define STRUCT(name) \
void uvwasi_serdes_write_##name(void* ptr, \
size_t offset, \
const uvwasi_##name* value); \
void uvwasi_serdes_read_##name(const void* ptr, \
size_t offset, \
uvwasi_##name* value);

/* iovs currently only need to be read from WASM memory. */
#define IOVS_STRUCT(name) \
uvwasi_errno_t uvwasi_serdes_read_##name(const void* ptr, \
size_t end, \
size_t offset, \
uvwasi_##name* value);

#define UVWASI_SERDES_SIZE_ciovec_t 8
IOVS_STRUCT(ciovec_t)

#define UVWASI_SERDES_SIZE_iovec_t 8
IOVS_STRUCT(iovec_t)

#define UVWASI_SERDES_SIZE_fdstat_t 24
STRUCT(fdstat_t)

#define UVWASI_SERDES_SIZE_filestat_t 64
STRUCT(filestat_t)

#define UVWASI_SERDES_SIZE_prestat_t 8
STRUCT(prestat_t)

#define UVWASI_SERDES_SIZE_event_t 32
STRUCT(event_t)

#define UVWASI_SERDES_SIZE_subscription_t 48
STRUCT(subscription_t)

#undef STRUCT
#undef IOVS_STRUCT

uvwasi_errno_t uvwasi_serdes_readv_ciovec_t(const void* ptr,
size_t end,
size_t offset,
uvwasi_ciovec_t* iovs,
uvwasi_size_t iovs_len);

uvwasi_errno_t uvwasi_serdes_readv_iovec_t(const void* ptr,
size_t end,
size_t offset,
uvwasi_iovec_t* iovs,
uvwasi_size_t iovs_len);

/* Helper functions for memory bounds checking. */
int uvwasi_serdes_check_bounds(size_t offset, size_t end, size_t size);
int uvwasi_serdes_check_array_bounds(size_t offset,
size_t end,
size_t size,
size_t count);

#endif /* __UVWASI_SERDES_H__ */
Loading

0 comments on commit 8d47e8b

Please sign in to comment.