fixed: WASI `__dir_open` permission issue
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 12 May 2023 01:16:18 +0000 (20:16 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 12 May 2023 01:16:18 +0000 (20:16 -0500)
CHANGELOG
core/builtin.onyx
core/runtime/platform/wasi/wasi_fs.onyx

index 1d076c9e25ab6a40d12dfaf31e4c684ecab6c91f..a7ecc1eace07974e207ffa4c0fd43a4b9a92a094 100644 (file)
--- 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.
 
 
 
index c04f2d75ce5a8abdf6847543b2c33f630f6a9811..05dec3c5532da1a0cd82b050ccfdd48aea1cb606 100644 (file)
@@ -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;
index d4a8bdf436491cac540bacb7e5ea5ea75a24eb35..011b1231f5ca9dc603d2e583a874e8f86126c417 100644 (file)
@@ -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 {