Skip to content

Commit

Permalink
Don't support fd sync flags by default
Browse files Browse the repository at this point in the history
It's not yet clear whether these flags should be added to the standard
so disallow use of them by default for the time being. See
WebAssembly/wasi-filesystem#98 for more
details. These changes are also necessary to ensure the rust WASI tests
pass since they assert that path_open returns ENOTSUP when passing
O_DSYNC/O_RSYNC/O_SYNC.
  • Loading branch information
zoraaver committed Sep 27, 2023
1 parent ade73f6 commit a80d071
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
3 changes: 3 additions & 0 deletions build-scripts/config_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ elseif (WAMR_BUILD_LIBC_WASI EQUAL 1)
else ()
message (" Libc WASI disabled")
endif ()
if (WAMR_BUILD_ENABLE_LIBC_WASI_SYNC_FLAGS EQUAL 1)
message (" Libc WASI file descriptor sync flags enabled")
endif()
if ((WAMR_BUILD_FAST_INTERP EQUAL 1) AND (WAMR_BUILD_INTERP EQUAL 1))
add_definitions (-DWASM_ENABLE_FAST_INTERP=1)
message (" Fast interpreter enabled")
Expand Down
4 changes: 4 additions & 0 deletions core/iwasm/libraries/libc-wasi/libc_wasi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ set (LIBC_WASI_DIR ${CMAKE_CURRENT_LIST_DIR})

add_definitions (-DWASM_ENABLE_LIBC_WASI=1)

if (WAMR_BUILD_ENABLE_LIBC_WASI_SYNC_FLAGS EQUAL 1)
add_definitions (-DCONFIG_HAS_LIBC_WASI_SYNC_FLAGS=1)
endif()

include_directories(${LIBC_WASI_DIR}/sandboxed-system-primitives/include
${LIBC_WASI_DIR}/sandboxed-system-primitives/src)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,11 @@ wasmtime_ssp_path_open(wasm_exec_env_t exec_env, struct fd_table *curfds,
// Convert file descriptor flags.
if ((fs_flags & __WASI_FDFLAG_APPEND) != 0)
noflags |= O_APPEND;
if ((fs_flags & __WASI_FDFLAG_NONBLOCK) != 0)
noflags |= O_NONBLOCK;
if (write && (noflags & (O_APPEND | O_TRUNC)) == 0)
needed_inheriting |= __WASI_RIGHT_FD_SEEK;
#if CONFIG_HAS_LIBC_WASI_SYNC_FLAGS != 0
if ((fs_flags & __WASI_FDFLAG_DSYNC) != 0) {
#ifdef O_DSYNC
noflags |= O_DSYNC;
Expand All @@ -1978,8 +1983,6 @@ wasmtime_ssp_path_open(wasm_exec_env_t exec_env, struct fd_table *curfds,
#endif
needed_inheriting |= __WASI_RIGHT_FD_DATASYNC;
}
if ((fs_flags & __WASI_FDFLAG_NONBLOCK) != 0)
noflags |= O_NONBLOCK;
if ((fs_flags & __WASI_FDFLAG_RSYNC) != 0) {
#ifdef O_RSYNC
noflags |= O_RSYNC;
Expand All @@ -1992,8 +1995,16 @@ wasmtime_ssp_path_open(wasm_exec_env_t exec_env, struct fd_table *curfds,
noflags |= O_SYNC;
needed_inheriting |= __WASI_RIGHT_FD_SYNC;
}
if (write && (noflags & (O_APPEND | O_TRUNC)) == 0)
needed_inheriting |= __WASI_RIGHT_FD_SEEK;
#else
// It's not clear whether we want to support these flags in the standard
// yet: https://github.com/WebAssembly/wasi-filesystem/issues/98 so disable
// them by default in the meanwhile.
if (((fs_flags & __WASI_FDFLAG_DSYNC) != 0)
|| ((fs_flags & __WASI_FDFLAG_RSYNC) != 0)
|| ((fs_flags & __WASI_FDFLAG_SYNC) != 0)) {
return __WASI_ENOTSUP;
}
#endif /* end of CONFIG_HAS_LIBC_WASI_SYNC_FLAGS */

struct path_access pa;
__wasi_errno_t error =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,8 @@ not implemented until 4.9. See
#define CONFIG_HAS_D_INO 0
#endif

#ifndef CONFIG_HAS_LIBC_WASI_SYNC_FLAGS
#define CONFIG_HAS_LIBC_WASI_SYNC_FLAGS 0
#endif

#endif
2 changes: 2 additions & 0 deletions doc/build_wamr.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM

- **WAMR_BUILD_LIBC_WASI**=1/0, build the [WASI](https://github.com/WebAssembly/WASI) libc subset for WASM app, default to enable if not set

- **WAMR_BUILD_LIBC_WASI_ENABLE_SYNC_FLAGS**=1/0, enable support for the file descriptor flags [`FDFLAGS_DSYNC`](https://docs.rs/wasi/latest/wasi/constant.FDFLAGS_DSYNC.html), [`FDFLAGS_RSYNC`](https://docs.rs/wasi/latest/wasi/constant.FDFLAGS_RSYNC.html) and [`FDFLAGS_DSYNC`](https://docs.rs/wasi/latest/wasi/constant.FDFLAGS_DSYNC.html), default to disable if not set. If enabled, support is dependent on the host OS.

- **WAMR_BUILD_LIBC_UVWASI**=1/0 (Experiment), build the [WASI](https://github.com/WebAssembly/WASI) libc subset for WASM app based on [uvwasi](https://github.com/nodejs/uvwasi) implementation, default to disable if not set

> Note: for platform which doesn't support **WAMR_BUILD_LIBC_WASI**, e.g. Windows, developer can try using **WAMR_BUILD_LIBC_UVWASI**.
Expand Down
3 changes: 3 additions & 0 deletions product-mini/platforms/nuttx/wamr.mk
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ ifeq ($(CONFIG_INTERPRETERS_WAMR_LIBC_WASI),y)
CFLAGS += -DWASM_ENABLE_LIBC_WASI=1
CFLAGS += -I$(IWASM_ROOT)/libraries/libc-wasi/sandboxed-system-primitives/src
CFLAGS += -I$(IWASM_ROOT)/libraries/libc-wasi/sandboxed-system-primitives/include
ifeq ($(CONFIG_INTERPRETERS_WAMR_LIBC_WASI_SYNC_FLAGS),y)
CFLAGS += -DCONFIG_HAS_LIBC_WASI_SYNC_FLAGS=1
endif
CSRCS += blocking_op.c
CSRCS += posix_socket.c
CSRCS += libc_wasi_wrapper.c
Expand Down

0 comments on commit a80d071

Please sign in to comment.