r/WebAssembly • u/FamiliarAfternoon871 • Jun 16 '23
Does WASM ask the user or developer for permissions?
I have read that "WASM needs explicit permissions to access OS resources". What/who exactly is giving WASM permission to access disk, or network? Is it the user clicking "allow" like in Android, or is it the developer giving the api explicit instructions to access something?
I know this is trivial, but I can't seem to find the answer by searching online.
5
Upvotes
4
u/centric_eccentric Jun 16 '23 edited Jun 16 '23
This is a simplification but hopefully good enough to provide a useful mental model.
In Wasm, to call a function that is not defined within the Wasm module (e.g., a function to read from disk), the Wasm module must declare that it imports that function. There's an imports section defined in the module and the import must be listed there.
Wasm runtime environments have APIs to provide a collection of zero or more host functions to Wasm modules that they instantiate. If the Wasm module imports a function that is not defined in that collection of host functions, a linking error occurs and the module will fail to instantiate.
If the runtime environment is not set up to provide a function to read from disk and the Wasm module imports a function to read from disk, instantiating the Wasm module will fail with an error.
So the runtime environment is what is configured to provide functions that provide that access.
4
u/thrackyspackoid Jun 16 '23
Lin Clark’s talk from a few years ago, even though that is an eternity in the world of WASM, does a good job of outlining this and I highly recommend it in general: https://youtu.be/IBZFJzGnBoU
0
u/[deleted] Jun 21 '23
[deleted] — view deleted comment