Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path_open not working with wasi-sdk #4361

Closed
yagehu opened this issue Dec 18, 2023 · 5 comments · May be fixed by #4363
Closed

path_open not working with wasi-sdk #4361

yagehu opened this issue Dec 18, 2023 · 5 comments · May be fixed by #4363
Labels
❓ question I've a question!

Comments

@yagehu
Copy link
Contributor

yagehu commented Dec 18, 2023

Describe the bug

This following simple C program compiled with wasi-sdk does not work with Wasmer.

$ wasmer -vV; rustc -vV
wasmer 4.2.4 (1abcd2c 2023-12-16)
binary: wasmer-cli
commit-hash: 1abcd2cc63deeca13af6506add6029edaba4d657
commit-date: 2023-12-16
host: x86_64-unknown-linux-gnu
compiler: singlepass,cranelift
rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

Steps to reproduce

Compile with wasi-sdk and run with Wasmer.

$ clang wasmer-creat.c
$ mkdir -p tmptest
$ wasmer run --dir . a.out
#include <fcntl.h>
#include <stdio.h>

int main(void) {
  int fd = open("tmptest/a", O_CREAT | O_RDWR);
  if (fd == -1) {
    perror("open");
    return 1;
  }

  return 0;
}

Expected behavior

This snippet should create a file a in the tmptest directory.

Actual behavior

open: No such file or directory

Additional context

It seems the parent directory is resolved to the virtual root in the path_open handler. I'll be able to submit a patch.

Copy link

linear bot commented Dec 18, 2023

yagehu added a commit to yagehu/wasmer that referenced this issue Dec 18, 2023
This commit fixes the bug where preopening `.` causes the WASI runner to
map it to the virtual root, causing `path_open` to fail.

fixes wasmerio#4361
yagehu added a commit to yagehu/wasmer that referenced this issue Dec 18, 2023
This commit fixes the bug where preopening `.` causes the WASI runner to
map it to the virtual root, causing `path_open` to fail.

fixes wasmerio#4361
yagehu added a commit to yagehu/wasmer that referenced this issue Dec 18, 2023
This commit fixes the bug where preopening `.` causes the WASI runner to
map it to the virtual root, causing `path_open` to fail.

fixes wasmerio#4361
yagehu added a commit to yagehu/wasmer that referenced this issue Dec 18, 2023
This commit fixes the bug where preopening `.` causes the WASI runner to
map it to the virtual root, causing `path_open` to fail.

fixes wasmerio#4361
yagehu added a commit to yagehu/wasmer that referenced this issue Dec 18, 2023
This commit fixes the bug where preopening `.` causes the WASI runner to
map it to the virtual root, causing `path_open` to fail.

fixes wasmerio#4361
yagehu added a commit to yagehu/wasmer that referenced this issue Dec 18, 2023
This commit fixes the bug where preopening `.` causes the WASI runner to
map it to the virtual root, causing `path_open` to fail.

fixes wasmerio#4361
yagehu added a commit to yagehu/wasmer that referenced this issue Dec 18, 2023
This commit fixes the bug where preopening `.` is not reflected in the
virtual filesystem, causing `path_open` to fail to find files.

fixes wasmerio#4361
@theduke
Copy link
Contributor

theduke commented Dec 19, 2023

The file system is sandboxed by default.

You need to mount host directories into the WASM context by using --mapdir <GUEST_PATH>:<HOST_PATH>.

In your example: --mapdir tmptest:tmptest.

@theduke theduke added the ❓ question I've a question! label Dec 19, 2023
@theduke
Copy link
Contributor

theduke commented Dec 19, 2023

Feel free to comment/reopen if you run into additional issues.

@theduke theduke closed this as completed Dec 19, 2023
@yagehu
Copy link
Contributor Author

yagehu commented Dec 19, 2023

@theduke I'm aware. I am mounting a directory with --dir .. I've raised a PR that fixes this. #4363

@yagehu
Copy link
Contributor Author

yagehu commented Dec 19, 2023

I believe this is just an error with mapping . whichthe PR fixes.

yagehu added a commit to yagehu/wasmer that referenced this issue Dec 22, 2023
This commit fixes a bug where creating a file with an implicit relative
path returns `0` indicating success, but no file is created on the host.
Here, implicit relative means a relative path that does not begin with
`./`. For example, calling `open("somefile", O_CREAT | O_WRONLY)` will
try to create a file called `somefile` in the current working directory.

The fix is to change the current directory if the user has explicitly
mounted any host directory to `.` in guest.  In this case, the user's
intention is clear: the current directory *is* the mounted host
directory.

fixes wasmerio#4361
yagehu added a commit to yagehu/wasmer that referenced this issue Dec 22, 2023
This commit fixes a bug where creating a file with an implicit relative
path returns `0` indicating success, but no file is created on the host.
Here, implicit relative means a relative path that does not begin with
`./`. For example, calling `open("somefile", O_CREAT | O_WRONLY)` will
try to create a file called `somefile` in the current working directory.

The fix is to change the current directory if the user has explicitly
mounted any host directory to `.` in guest.  In this case, the user's
intention is clear: the current directory *is* the mounted host
directory.

fixes wasmerio#4361
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question I've a question!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants