[bug] Calling `wasi_snapshot_preview1` `path_open` without "extra steps" returns BADF (error 8)
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript, wasm
- Domain
- operating-systems
Research direction
Start with the wasi_snapshot_preview1 path_open implementation used by @vscode/wasm-wasi and compare its handling of the repro.wat call with node:wasi and Wasmtime. Reproduce the fd=3 call through createProcess and verify that direct path_open succeeds without breaking the existing C fopen("test.txt", "r") case.
Written by the indexing model from the issue text.
Description
When the following is compiled with WASI SDK to test.wasm:
#include <stdio.h>
int main(int argc, const char **argv)
{
FILE *file = fopen("test.txt", "r");
if (file == NULL)
{
return 1;
}
char buffer[1024];
while (fgets(buffer, sizeof(buffer), file) != NULL)
{
fputs(buffer, stdout);
}
fclose(file);
return 0;
}
and executed using this setup:
import { Wasm } from "@vscode/wasm-wasi";
// ...
const wasm: Wasm = await Wasm.api();
const pty = wasm.createPseudoterminal();
const terminal = vscode.window.createTerminal({
name: "test",
pty,
isTransient: true,
});
terminal.show(true);
try {
const process = await wasm.createProcess(
"test.wasm",
currentCompilerModule,
{
stdio: pty.stdio,
mountPoints: [
{
kind: "vscodeFileSystem",
uri: workspaceUri,
mountPoint: "/",
},
],
}
);
const exitCode = await process.run();
if (exitCode !== 0) {
vscode.window.showErrorMessage(
`Process exited with code: ${exitCode}`
);
}
} catch (error) {
vscode.window.showErrorMessage((error as Error).message);
terminal.dispose();
}
VSCode properly reads test.txt file from the current workspace and print it to created terminal.
However:
Trying to call wasi_snapshot_preview1 path_open function with fd=3, path="test.txt" directly always returns EBADF (code 8).
Minimal reproduction:
(; repro.wat ;)
(module
(type (;0;) (func (param i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i32)))
(type (;1;) (func (param i32)))
(type (;2;) (func))
(import "wasi_snapshot_preview1" "path_open" (func (;0;) (type 0)))
(import "wasi_snapshot_preview1" "proc_exit" (func (;1;) (type 1)))
(func $_start (type 2)
(local i32)
i32.const 3
i32.const 1
i32.const 68314
i32.const 8
i32.const 0
i64.const 264240830
i64.const 268435455
i32.const 0
i32.const 67188
call 0
local.set 0
local.get 0
call 1)
(memory (;0;) 40)
(export "memory" (memory 0))
(export "_start" (func $_start))
(data (;0;) (i32.const 68314) "test.txt"))
P.S: Arguments to the function were extracted by using node:wasi and logging calls of all import functions.
Running repro.wat works fine in both node:wasi and wasmtime.
- Dominant language
- TypeScript
- Stars
- 456
- Forks
- 42
- Avg merge
- 3d 19h
- Merged PRs (30d)
- 7
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/vscode-wasm
-
WasiProcess.run() never settles when instantiate fails or _start traps (e.g. missing fd_fdstat_set_rights import)Possibly taken @dbaeumer claimed this 19 days ago. Open
microsoft/vscode-wasm#303 · 1 assignee ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
microsoft/vscode-wasm#249 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 55/100
microsoft/vscode-wasm#244 · 2 reactions ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 35/100
microsoft/vscode-wasm#240 ·
-
feature-request
Difficulty 5/5 Over a week Newbie friendliness 28/100
microsoft/vscode-wasm#235 ·
All issues in microsoft/vscode-wasm
Similar issues
-
type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
0️⃣ phase/new
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 70/100
microsoft/playwright#43640 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100