wasmerio/wasmer

`fd_prestat_get` doesn't return the mapped directory since v4.2.6

Opened this issue · 0 comments

ktock commented

Describe the bug

fd_prestat_get doesn't return the mapped directory since wasmer v4.2.6 but it was returned with v4.2.5.
I've tried it with the latest (v4.2.8) but the result is the same as v4.2.6.

wasmer -vV; rustc -vV
wasmer 4.2.8 (f135527 2024-04-05)
binary: wasmer-cli
commit-hash: f1355275fb6beaf196a65943e0cd293c69363dbd
commit-date: 2024-04-05
host: x86_64-unknown-linux-gnu
compiler: singlepass,cranelift,llvm
bash: rustc: command not found

Steps to reproduce

sample C program:

#include
 
int main(int argc, char **argv)
{
  for (__wasi_fd_t fd = 3; fd != 0; ++fd) {
    __wasi_prestat_t prestat;
    __wasi_errno_t ret = __wasi_fd_prestat_get(fd, &prestat);
    if (ret != __WASI_ERRNO_SUCCESS) {
      printf("preopen: fd:%d ret:%d\n", fd, ret);
      return -1;
    }
    if (prestat.tag == __WASI_PREOPENTYPE_DIR) {
      char *prefix = (char *) malloc(prestat.u.dir.pr_name_len + 1);
      if (prefix == NULL) {
        printf("error: malloc\n");
        return -1;
      }
      if (__wasi_fd_prestat_dir_name(fd, (uint8_t *)prefix, prestat.u.dir.pr_name_len) != __WASI_ERRNO_SUCCESS) {
        printf("error: __wasi_fd_prestat_dir_name\n");
        return -1;
      }
      prefix[prestat.u.dir.pr_name_len] = '\0';
      printf("preopen(dir): fd:%d ret:%d, prefix:%s\n", fd, ret, prefix);
    } else {
      printf("preopen(nondir): fd:%d ret:%d\n", fd, ret);
    }
  }
  return 0;
}

I built this using wasi-sdk 19.0. (${WASI_SDK_PATH}/bin/clang --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot -o out.wasm main.c).

Then prepare a directory to map.

$ mkdir /tmp/mnt

wasmer v4.2.8 (The same output is observed since v4.2.6)

$ wasmer run --mapdir=/mapped:/tmp/mnt -- /app/out.wasm
preopen(dir): fd:3 ret:0, prefix:/
preopen(dir): fd:4 ret:0, prefix:/
preopen(dir): fd:5 ret:0, prefix:.
preopen: fd:6 ret:8

v4.2.5

$ wasmer run --mapdir=/mapped:/tmp/mnt -- /app/out.wasm
preopen(dir): fd:3 ret:0, prefix:/
preopen(dir): fd:4 ret:0, prefix:/mapped
preopen(dir): fd:5 ret:0, prefix:/
preopen(dir): fd:6 ret:0, prefix:.
preopen: fd:7 ret:8

Expected behavior

The mapped directory should be returned from fd_prestat_get, same as v4.2.5.

Actual behavior

The mapped directory isn't returned from fd_prestat_get.

Additional context