From 90a38a618b024908b1cf8045abe800e33a4ab68e Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 11 May 2023 20:16:18 -0500 Subject: [PATCH] fixed: WASI `__dir_open` permission issue --- CHANGELOG | 3 ++- core/builtin.onyx | 2 +- core/runtime/platform/wasi/wasi_fs.onyx | 26 +++++++++++++++---------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1d076c9e..a7ecc1ea 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -Release XXX +Release v0.1.1 ----------- Additions: @@ -22,6 +22,7 @@ Bugfixes: - Fixes `Optional.reset` and `Optional.hash` * Fixed missing newline in `onyx help build` documentation. * Fixed WASI compilation due to misconfigured environment code. +* Fixed WASI `__dir_open` permissions. diff --git a/core/builtin.onyx b/core/builtin.onyx index c04f2d75..05dec3c5 100644 --- a/core/builtin.onyx +++ b/core/builtin.onyx @@ -527,7 +527,7 @@ Link_Options :: struct { // Controls if/how the WASM function table will be exported. export_func_table := true; - export_func_table_name := "func_table"; + export_func_table_name := "__indirect_function_table"; // Controls the minimum and maximum number of pages for WASM memory. memory_min_size := 1024; diff --git a/core/runtime/platform/wasi/wasi_fs.onyx b/core/runtime/platform/wasi/wasi_fs.onyx index d4a8bdf4..011b1231 100644 --- a/core/runtime/platform/wasi/wasi_fs.onyx +++ b/core/runtime/platform/wasi/wasi_fs.onyx @@ -270,22 +270,28 @@ DirectoryData :: &WasiDirectory; __dir_open :: (path: str, dir: &DirectoryData) -> bool { dir_fd: FileDescriptor; - err := wasi.path_open(4, .SymLinkFollow, path, .Directory, ~~0xffffffff, ~~0xffffffff, .Sync, &dir_fd); - if err != .Success { - return false; - } - d := new(WasiDirectory); - d.dir_fd = dir_fd; - d.last_cookie = 0; + DIR_PERMS := Rights.PathOpen | .ReadDir | .PathReadlink | .FilestatGet | .PathFilestatGet; + FILE_PERMS := Rights.Read | .Seek | .Tell | .FilestatGet | .PollFDReadWrite; - *dir = d; - return true; + for .[3, 4] { + err := wasi.path_open(it, .SymLinkFollow, path, .Directory, DIR_PERMS, FILE_PERMS, .Sync, &dir_fd); + if err != .Success do continue; + + d := new(WasiDirectory); + d.dir_fd = dir_fd; + d.last_cookie = 0; + + *dir = d; + return true; + } + + return false; } __dir_close :: (dir: DirectoryData) { wasi.fd_close(dir.dir_fd); - cfree(dir); + if dir do cfree(dir); } __dir_read :: (dir: DirectoryData, out_entry: &os.DirectoryEntry) -> bool { -- 2.25.1