-
Notifications
You must be signed in to change notification settings - Fork 206
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
Rough sketch for a syscall API for argv/argc and exit status #179
Comments
|
That's a good point. I've tweaked the wording a little, but let me also explain here: Calling main from the wasm start function isn't the only way to do it, but for purely command-line-oriented programs, I think it is a natural way to do it. The important aspect here is that we don't want to rely on the entrypoint (whatever it is) having arguents or return values.
The argv data comes from whatever entity satisfies these imports. In a command-line-oriented wasm runner, these might be provided by the runner itself. In a browser, there might be a polyfill module providing a command-line-environment to run in. Other environments could decide how to resolve these symbols in whatever way makes sense in their contexts. As for pointing the module to where the argv data is rather than copying it in, the difficulty is that Wasm programs by design can't refer to data they haven't been explicitly given access to. |
I see, so the module runner is responsible for filling the argv data when the module calls |
It would be nice if there was some convention regarding calling a |
@bjfish the function being named "main" is the convention, isn't it? whatever is running the wasm can just assume that is the main entry point by convention. |
@rianhunter Yes, I think a "main" function being the entry point would be a good convention for a wasm runtime. It'd be nice to have an option to override this via configuration as well. |
Would that pass in cli arguments as parameters like emscripten does? Or would imported functions be used to get the cli arguments? |
@lachlansneff I think the way emscripten does this is by generating glue code (shims) which call it’s own wasm syscall/runtime API. In the short term, I think imported functions could be used directly but hopefully future glue code would adopt the new reference syscall API. |
This design for command-line arguments is now subsumed by the WASI proposal; see the |
The following is a rough sketch for a syscall API. The idea is to support a traditional C-style "main" function which in some environments is called from the wasm start function. The wasm start function has no arguments or return values, so we instead use imported functions to communicate this information.
I'm hoping this proposal will eventually help lead to something useful on its own (a standard way to invoke command-line-style wasm programs), but I'm also hoping it encourages meta-level conversations about how to design and document proposals. "main" is just the beginning ;-).
argv and argc
Argv strings are NUL-terminated C-style strings and are concatenated into a single buffer, the argv data.
argv_data_len
returns the unsigned length of the argv data, including the NULs.store_argv_data
stores the argv data into the default linear memory at $ptr.argc
returns the unsigned number of NUL-terminated strings are encoded in the argv data.store_argv_pointers
populates an argv-style array (with length argc) of 32-bit indices at $pointers in the default linear memory, giving the starts of the NUL-terminated strings in the argv data.store_argv_data
andstore_argv_offsets
trap if any byte to be written would be out of bounds.Exit Status
Each wasm instance has an associated exit status variable, which is either an integer or one of a predefined set of exit messages. The value is returned to the host when the start function exits. The initial value when the start function is called is the message “success”.
set_exit_status_i32
sets the exit status variable to an integer value.set_exit_status_message
sets the exit status variable to one of a set of predefined exit messages:Integer values and exit messages are both mapped to the host environment in host-specific and potentially lossy ways, with the following constraints:
The text was updated successfully, but these errors were encountered: