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 26, 2023
1 parent ade73f6 commit 24a2c36
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions build-scripts/config_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ 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")
else()
message (" Libc WASI file descriptor sync flags disabled")
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
6 changes: 6 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,12 @@ 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 (-DWASM_ENABLE_LIBC_WASI_SYNC_FLAGS=1)
else()
add_definitions (-DWASM_ENABLE_LIBC_WASI_SYNC_FLAGS=0)
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 WASM_ENABLE_LIBC_WASI_SYNC_FLAGS == 1
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 WASM_ENABLE_LIBC_WASI_SYNC_FLAGS */

struct path_access pa;
__wasi_errno_t error =
Expand Down
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

0 comments on commit 24a2c36

Please sign in to comment.