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

Empty args array in WASI is problematic #40196

Open
jasnell opened this issue Sep 23, 2021 · 8 comments
Open

Empty args array in WASI is problematic #40196

jasnell opened this issue Sep 23, 2021 · 8 comments
Labels
wasi Issues and PRs related to the WebAssembly System Interface.

Comments

@jasnell
Copy link
Member

jasnell commented Sep 23, 2021

/cc @cjihrig

In the new WASI(...) constructor, if the args option is not given, then there will be no args[0] available, which causes some problems with some libc-wasm compiled libraries (e.g. zstd). The question is whether we can reasonably default an args[0] when args is not provided.

@devsnek
Copy link
Member

devsnek commented Sep 23, 2021

cc @sunfishcode, is this something wasi libc should be doing instead of wasi impls? the current wasi text seems to not have any details on the expectations here.

@cjihrig
Copy link
Contributor

cjihrig commented Sep 23, 2021

@jasnell from an implementation standpoint, I think it would be fine, as long as the default args[0] is properly sandboxed, but I'm curious to see the response to @devsnek's question.

@Mesteery Mesteery added the wasi Issues and PRs related to the WebAssembly System Interface. label Sep 23, 2021
@jasnell
Copy link
Member Author

jasnell commented Sep 23, 2021

Yeah, I dunno. There's also the consideration that the args[0] convention is really only true on linux/unix systems is also worthwhile. Some libraries will expect it, others will not, and defaulting to something might actually cause problems there. One of the arguments is that we just leave this as is and document it, leaving it up to users.

@cjihrig
Copy link
Contributor

cjihrig commented Sep 23, 2021

There's also the consideration that the args[0] convention is really only true on linux/unix systems is also worthwhile.

I think in this case, it comes down to what the WASI people want to define for the virtual system, independent of the actual underlying system.

One of the arguments is that we just leave this as is and document it, leaving it up to users.

It looks like that's what our docs currently state, minus any bits about some libraries/apps expecting it to be set.

@jasnell
Copy link
Member Author

jasnell commented Sep 23, 2021

...minus any bits about some libraries/apps expecting it to be set.

Yeah, this is the additional bit I'm suggesting would be appropriate. I do like the idea that libc-wasi should be handling this part for us. Let's see where that conversation leads tho.

@sunfishcode
Copy link

sunfishcode commented Sep 23, 2021

If we're going to automatically fix up argv[0], it'd be better to do it in the spec and WASI implementations / bindings. In general, if there's something we want to always happen, it seems better to just define WASI to do what we want directly, rather than having wasi-libc take on extra code size to work around it.

Should we make this change? On one hand, POSIX and systems in practice seem ok with argc == 0. On the other, my guess is that argc == 0 isn't that important, and supporting is probably more trouble than it's worth.

What should the argv[0] string be? I expect we don't want argv[0] to default to the full path name to a wasm module file, since there won't always be a file, and the full path would expose extra host information. If programs need to locate installation files, we should provide them another way to do that. Multi-call executables have uses, so perhaps we should default to something like:

  • If there's a way for the user to provide a string for this purpose explicitly, use that.
  • If the environment has a concept of a module name, use that. These may be derived from file names or URLs, in which case the module name should exclude the ".wasm" or other extension.
  • Otherwise, use "<wasm>".

How does that sound?

@jasnell
Copy link
Member Author

jasnell commented Sep 23, 2021

That sounds like a reasonable approach for me. Let's see what others think.

@devsnek
Copy link
Member

devsnek commented Sep 23, 2021

thanks for your input dan. i think my personal preference would be to not have any default argv[0], but i can see the use in the outlined approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues and PRs related to the WebAssembly System Interface.
Projects
None yet
Development

No branches or pull requests

5 participants