-
Notifications
You must be signed in to change notification settings - Fork 271
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
Dynamic detection of host functionality #12
Comments
This is precisely why we need modularity and versioning. Perhaps we could add some capability flags as a custom section? Capability flags could specify optional behavior such as |
I think this function might useful in a few corner cases, but most of the time you wouldn't want to use it. The name, module and type of the function you want to import is usually known as compile-time. What isn't known is whether the function will actually be there. So what you want is optional imports, which should have three possible outcomes:
|
This is currently possible, in a not very nice way. You can have the host provide a table of functions, and then import a global (type $t (func ...))
(import "my" "table" (table ...))
(import "my" "func" (global $g i32))
...
(call_indirect $type (global.get $g) ...) When typed function references are added, we can do a little better. Typed function references are currently spec'd to be not nullable, so you couldn't import them directly. But assuming we add a downcast from (type $t (func ...))
(import "my" "func" (global $g (optref $t)))
...
(call_ref ... (global.get $g)) |
Well that seems like a big oversight. I get that designers are wary of the "all pointers are nullable" design that was common for a while, but not having optional typed pointers at all is bad too. |
@binji, @PoignardAzur, it's currently listed as an open design question whether the function reference proposal should also include |
This would be solved by #36 right? i.e. having a weak import that is runtime testable? |
Yes, this seems addressed by #36. If people discover anything which optional imports don't cover, please file new issues! |
This is likely a pretty far-future issue, but I was curious to start a conversation around it early on to see what others think!
As wasi continues to grow syscalls (in one way or another) it's inevitable that syscalls will be implemented in some implementations of wasi but not others. Furthermore some host environments may just simply choose to not provide wasi syscall functionality while others do indeed support it. A standard library compiled to wasm, however, needs some sort of policy about what it can and can't do.
For example would a standard library have to specify a minimum set of syscalls it needs to operate? Would it need a specific threshold saying "your implementation must be as new as X with these syscalls"? I ask about this in the context of implementing the Rust standard library for wasi in contrast with how some other platforms are implemented.
Some examples that have come up elsewhere in the past are:
On Unix we've got syscalls like
accept4
which allow atomically setting CLOEXEC, but it's not available on all kernels that the Rust standard library supports. As a result we dynamically detect at runtime whetheraccept4
is available and fall back to a "guaranteed to work" accept-then-CLOEXEC if it's not found.Some platforms support the idea of the "name of thread", primarily used for debugging when you attach
gdb
for example. We dynamically detect whether linux platforms have the right symbol we can call to configure this, but if it's not present it's just an opportunistic thing that we can safely ignore.I'd be curious if we could develop something like this for wasi? For example if a syscall was added to aid in debugging (like the thread intrinsic) then the Rust standard library would want to immediately start using but wouldn't want to require all wasi implementations to provide it.
An example strawman API for this might be something like:
where the wasi runtime would effectively attempt to dynamically import
name
frommodule
(like a static wasm import). If it doens't find anything then the host would return an error, but otherwise a function would be appended to the instance's runtime table of functions and an index to that would be returned throughfunction_pointer
. It'd be up to the implementation to then ensure it has the right type signature of the syscall.I suspect this is also related to #2 in that it could affect what APIs are used, although it's less so about statically requesting different behavior but rather dynamically requesting such behavior.
The text was updated successfully, but these errors were encountered: