-
Notifications
You must be signed in to change notification settings - Fork 20
Cannot leave component instance issue #97
Comments
I don't know how this hasn't cropped up sooner, and unfortunately I'm not sure how best to solve this. The error here is coming from Wasmtime itself and is reflective of the reentrance rules of the component model. The |
@alexcrichton We could generalize the logic I added in #83 and bytecodealliance/wasm-tools#919 such that wit-component wraps the main module's cabi_realloc function in some code that sets the Does that sound reasonable? If so, I'll be happy to implement it. |
BTW, will this be an issue for post-return functions also? |
This will be an issue with post-return, yeah, but #83 and related support was about updates to the adapter module but this is a case where This may be a deeper issue worth talking about with @sunfishcode and @lukewagner though to see if there's a better solution here. I'm not sure how flexible this reentrancy constraint is or how flexible the env var/ctor code can be made. |
I discussed this with @sunfishcode and @lukewagner today, and I think the plan going forward is to move away from wrapping each export in ctor/dtor calls and instead rely on initialization happening in an So I think we can handle the ctor/dtor wrappers with the preview2 adapter and then assume there will be no such wrappers by the time wasi-libc uses preview2 directly. Does that sound reasonable? |
Re relying on initialization happening in an Can you describe more what "handle the ctor/dtor wrappers with the preview2 adapter" means? From my view (and I apologize that I came to this separately and didnt join the discussion you just had) this difficulty is driven by the adapter needing to rely on wasi-libc in order to allocate memory. This requirement is driven by needing to use "legacy" wasi-libcs that have the allocator behavior from before components or adapters were created. If we can throw away that requirement, and require preview 1 apps be linked against a wasi-libc which won't stomp on the adapter's allocation, we can resolve this problem in a way that eliminates a lot of the complexity in the adapter. (The fixed wasi-libc allocator is available in rustc nightly, right @sunfishcode?) By "moving away from wrapping each export in ctor/dtor wrappers" we mean that some change to lld is required in order to produce modules that work with the adapter, then have we already made that leap? |
Alex corrected my understanding of this issue - even if we can separate allocation from the adapter and libc, we would still run into this issue because libc is calling import functions during the call to cabi_realloc (which is being called from outside the component in preparation for passing in some lists to an export function) |
How plausible is it to change wasi-libc just not call any import functions in its constructors? (Edit: I read all of Dan's comments throughout wasi-libc on environment initialization and read |
(I'll let Luke or Dan answer your first question, since they floated a few ideas, and I'm not totally sure where they landed).
I outlined it in my earlier comment: #97 (comment)
At Fermyon, we would prefer to have a way to convert customers' existing modules to components without rebuilding from source. If that is prohibitively difficult then we can explore other options, but I don't think that's a given at this point. Also, some toolchains, such as TeaVM, don't use wasi-libc at all, and will require modifications to accommodate a "reserved" portion of linear memory for the adapter. That could get awkward as more non-wasi-libc tools come on the scene. And as Alex pointed out, requiring the latest wasi-libc wouldn't help with this particular issue anyway. |
Probably doable for environment variables, but not sure about preopens. |
I don't understand how this approach is viable, because short-circuiting the response to wasi-libc gives it incorrect values. How do those values later get corrected when calling imports is allowed? |
The incorrect values will only live persist as long as the |
That sounds reasonable to me as a stopgap, yeah. (albeit this continues to pile quite a few hacks in the adapter construction but our hand is sort of forced) Longer-term I still feel like the picture is a bit unclear, however:
I know there's been a lot of historical discussion about command/reactor patterns in WASI but very little of that I feel has ended up getting surfaced into the component model itself. In that sense I find it difficult to think about commands/reactors since that's in theory a higher-level abstraction than the component model itself and the problem here in this issue is the component model's semantics. So "well it should be a reactor" or "let's fix commands" I find unclear since that's dealing with higher level semantics than the issue being run into here. |
Hey, not sure if this is the right place to ask but the issue was caused when
wasm32-wasi
target is used in my case.I tried to execute a wasi component using the host crate from this repo and I got a message showed below
The setup
I am using the 'release-6.0.0' branch of wasmtime and the latest commits of this repo and wit-bindgen, wasm-tools for creating a component out of my Rust application.
This is the output of
wasm-tools component wit
My host is building a Wasi Context using
wasi_cap_std_sync
crate from this repo as well.Getting Around
I was able to get around this error by compiling the application to
wasm32-unknown-unknown
target and remove--adapt
flag fromwasm-tools component
command. This indicates that there might be something going on in wasi and thus I want to raise this issue here.The text was updated successfully, but these errors were encountered: