From da3a184b182d5d0b18fd139df9e4259df4378095 Mon Sep 17 00:00:00 2001 From: Achille Roussel Date: Thu, 27 Apr 2023 14:37:55 -0700 Subject: [PATCH] syscall: remove wasip1 O_DIRECTORY workaround Wasmtime used to error when opening a directory without passing the O_DIRECTORY flag, which required doing a stat to determine whether to inject the flag prior to opening any file. The workaround was subject to races since the stat and open calls were not atomic. Wasmtime fixed the issue in v8.0.1. For details see: - https://github.com/bytecodealliance/wasmtime/pull/4967 - https://github.com/bytecodealliance/wasmtime/pull/6163 - https://github.com/bytecodealliance/wasmtime/releases/tag/v8.0.1 Change-Id: I0f9fe6a696024b70fffe63b83e8f61e48acd0c4a Reviewed-on: https://go-review.googlesource.com/c/go/+/489955 Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Johan Brandhorst-Satzkorn Run-TryBot: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov --- src/syscall/fs_wasip1.go | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/syscall/fs_wasip1.go b/src/syscall/fs_wasip1.go index b331629d79..ef04af6966 100644 --- a/src/syscall/fs_wasip1.go +++ b/src/syscall/fs_wasip1.go @@ -432,29 +432,6 @@ func Open(path string, openmode int, perm uint32) (int, error) { oflags |= OFLAG_EXCL } - // Remove when https://github.com/bytecodealliance/wasmtime/pull/4967 is merged. - var fi Stat_t - if errno := path_filestat_get( - dirFd, - LOOKUP_SYMLINK_FOLLOW, - pathPtr, - pathLen, - unsafe.Pointer(&fi), - ); errno != 0 && errno != ENOENT { - return -1, errnoErr(errno) - } - if fi.Filetype == FILETYPE_DIRECTORY { - oflags |= OFLAG_DIRECTORY - // WASM runtimes appear to return EINVAL when passing invalid - // combination of flags to open directories; however, TestOpenError - // in the os package expects EISDIR, so we precheck this condition - // here to emulate the expected behavior. - const invalidFlags = O_WRONLY | O_RDWR | O_CREATE | O_APPEND | O_TRUNC | O_EXCL - if (openmode & invalidFlags) != 0 { - return 0, EISDIR - } - } - var rights rights switch openmode & (O_RDONLY | O_WRONLY | O_RDWR) { case O_RDONLY: -- 2.50.0