Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

add missing may-block checks for sync-to-sync guest-to-guest calls (#12282)

Joel Dicefae9e6af8780
diff --git a/crates/cranelift/src/compiler/component.rs b/crates/cranelift/src/compiler/component.rs
index 4aaae9cbc4..2d7578c5af 100644
--- a/crates/cranelift/src/compiler/component.rs
+++ b/crates/cranelift/src/compiler/component.rs
@@ -732,14 +732,6 @@ impl<'a> TrampolineCompiler<'a> {
|_, _| {},
);
}
- Trampoline::CheckBlocking => {
- self.translate_libcall(
- host::check_blocking,
- TrapSentinel::Falsy,
- WasmArgs::InRegisters,
- |_, _| {},
- );
- }
Trampoline::Trap => {
self.translate_libcall(
host::trap,
@@ -1140,10 +1132,14 @@ impl<'a> TrampolineCompiler<'a> {
// run_destructor_block:
// ;; test may_enter, but only if the component instances
// ;; differ
- // flags = load.i32 vmctx+$offset
+ // flags = load.i32 vmctx+$instance_flags_offset
// masked = band flags, $FLAG_MAY_ENTER
// trapz masked, CANNOT_ENTER_CODE
//
+ // ;; set may_block to false, saving the old value to restore later
+ // old_may_block = load.i32 vmctx+$may_block_offset
+ // store 0, vmctx+$may_block_offset
+ //
// ;; ============================================================
// ;; this is conditionally emitted based on whether the resource
// ;; has a destructor or not, and can be statically omitted
@@ -1156,6 +1152,9 @@ impl<'a> TrampolineCompiler<'a> {
// call_indirect func_addr, callee_vmctx, vmctx, rep
// ;; ============================================================
//
+ // ;; restore old value of may_block
+ // store old_may_block, vmctx+$may_block_offset
+ //
// jump return_block
//
// return_block:
@@ -1190,7 +1189,7 @@ impl<'a> TrampolineCompiler<'a> {
// that this check can be elided if the resource table resides in
// the same component instance that defined the resource as the
// component is calling itself.
- if let Some(def) = resource_def {
+ let old_may_block = if let Some(def) = resource_def {
if self.types[resource].unwrap_concrete_instance() != def.instance {
let flags = self.builder.ins().load(
ir::types::I32,
@@ -1203,8 +1202,29 @@ impl<'a> TrampolineCompiler<'a> {
.ins()
.band_imm(flags, i64::from(FLAG_MAY_ENTER));
self.builder.ins().trapz(masked, TRAP_CANNOT_ENTER);
+
+ // Stash the old value of `may_block` and then set it to false.
+ let old_may_block = self.builder.ins().load(
+ ir::types::I32,
+ trusted,
+ vmctx,
+ i32::try_from(self.offsets.task_may_block()).unwrap(),
+ );
+ let zero = self.builder.ins().iconst(ir::types::I32, i64::from(0));
+ self.builder.ins().store(
+ ir::MemFlags::trusted(),
+ zero,
+ vmctx,
+ i32::try_from(self.offsets.task_may_block()).unwrap(),
+ );
+
+ Some(old_may_block)
+ } else {
+ None
}
- }
+ } else {
+ None
+ };
// Conditionally emit destructor-execution code based on whether we
// statically know that a destructor exists or not.
@@ -1253,6 +1273,16 @@ impl<'a> TrampolineCompiler<'a> {
&[callee_vmctx, caller_vmctx, rep],
);
}
+
+ if let Some(old_may_block) = old_may_block {
+ self.builder.ins().store(
+ ir::MemFlags::trusted(),
+ old_may_block,
+ vmctx,
+ i32::try_from(self.offsets.task_may_block()).unwrap(),
+ );
+ }
+
self.builder.ins().jump(return_block, &[]);
self.builder.seal_block(run_destructor_block);
diff --git a/crates/environ/src/component.rs b/crates/environ/src/component.rs
index e68c357b11..377a98fe95 100644
--- a/crates/environ/src/component.rs
+++ b/crates/environ/src/component.rs
@@ -185,8 +185,6 @@ macro_rules! foreach_builtin_component_function {
#[cfg(feature = "component-model-async")]
error_context_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
#[cfg(feature = "component-model-async")]
- check_blocking(vmctx: vmctx) -> bool;
- #[cfg(feature = "component-model-async")]
context_get(vmctx: vmctx, caller_instance: u32, slot: u32) -> u64;
#[cfg(feature = "component-model-async")]
context_set(vmctx: vmctx, caller_instance: u32, slot: u32, val: u32) -> bool;
diff --git a/crates/environ/src/component/dfg.rs b/crates/environ/src/component/dfg.rs
index 9bf35ec7e9..5f5a3b84fa 100644
--- a/crates/environ/src/component/dfg.rs
+++ b/crates/environ/src/component/dfg.rs
@@ -267,6 +267,7 @@ pub enum CoreDef {
InstanceFlags(RuntimeComponentInstanceIndex),
Trampoline(TrampolineIndex),
UnsafeIntrinsic(ModuleInternedTypeIndex, UnsafeIntrinsic),
+ TaskMayBlock,
/// This is a special variant not present in `info::CoreDef` which
/// represents that this definition refers to a fused adapter function. This
@@ -475,7 +476,6 @@ pub enum Trampoline {
FutureTransfer,
StreamTransfer,
ErrorContextTransfer,
- CheckBlocking,
Trap,
ContextGet {
instance: RuntimeComponentInstanceIndex,
@@ -905,6 +905,7 @@ impl LinearizeDfg<'_> {
}
info::CoreDef::UnsafeIntrinsic(*i)
}
+ CoreDef::TaskMayBlock => info::CoreDef::TaskMayBlock,
}
}
@@ -1156,7 +1157,6 @@ impl LinearizeDfg<'_> {
Trampoline::FutureTransfer => info::Trampoline::FutureTransfer,
Trampoline::StreamTransfer => info::Trampoline::StreamTransfer,
Trampoline::ErrorContextTransfer => info::Trampoline::ErrorContextTransfer,
- Trampoline::CheckBlocking => info::Trampoline::CheckBlocking,
Trampoline::Trap => info::Trampoline::Trap,
Trampoline::ContextGet { instance, slot } => info::Trampoline::ContextGet {
instance: *instance,
diff --git a/crates/environ/src/component/info.rs b/crates/environ/src/component/info.rs
index 6be69584fc..65a12aebdb 100644
--- a/crates/environ/src/component/info.rs
+++ b/crates/environ/src/component/info.rs
@@ -389,6 +389,10 @@ pub enum CoreDef {
Trampoline(TrampolineIndex),
/// An intrinsic for compile-time builtins.
UnsafeIntrinsic(UnsafeIntrinsic),
+ /// Reference to a wasm global which represents a runtime-managed boolean
+ /// indicating whether the currently-running task may perform a blocking
+ /// operation.
+ TaskMayBlock,
}
impl<T> From<CoreExport<T>> for CoreDef
@@ -1105,10 +1109,6 @@ pub enum Trampoline {
/// component does not invalidate the handle in the original component.
ErrorContextTransfer,
- /// An intrinsic used by FACT-generated modules to check whether an
- /// async-typed function may be called via a sync lower.
- CheckBlocking,
-
/// An intrinsic used by FACT-generated modules to trap with a specified
/// code.
Trap,
@@ -1242,7 +1242,6 @@ impl Trampoline {
FutureTransfer => format!("future-transfer"),
StreamTransfer => format!("stream-transfer"),
ErrorContextTransfer => format!("error-context-transfer"),
- CheckBlocking => format!("check-blocking"),
Trap => format!("trap"),
ContextGet { .. } => format!("context-get"),
ContextSet { .. } => format!("context-set"),
diff --git a/crates/environ/src/component/translate.rs b/crates/environ/src/component/translate.rs
index b1c09ad454..06cd7a3079 100644
--- a/crates/environ/src/component/translate.rs
+++ b/crates/environ/src/component/translate.rs
@@ -606,6 +606,7 @@ impl<'a, 'data> Translator<'a, 'data> {
let known_func = match arg {
CoreDef::InstanceFlags(_) => unreachable!("instance flags are not a function"),
+ CoreDef::TaskMayBlock => unreachable!("task_may_block is not a function"),
// We could in theory inline these trampolines, so it could
// potentially make sense to record that we know this
diff --git a/crates/environ/src/component/translate/adapt.rs b/crates/environ/src/component/translate/adapt.rs
index 75758d2558..2f66974a7a 100644
--- a/crates/environ/src/component/translate/adapt.rs
+++ b/crates/environ/src/component/translate/adapt.rs
@@ -345,7 +345,6 @@ fn fact_import_to_core_def(
fact::Import::ErrorContextTransfer => {
simple_intrinsic(dfg::Trampoline::ErrorContextTransfer)
}
- fact::Import::CheckBlocking => simple_intrinsic(dfg::Trampoline::CheckBlocking),
fact::Import::Trap => simple_intrinsic(dfg::Trampoline::Trap),
}
}
@@ -452,7 +451,8 @@ impl PartitionAdapterModules {
// These items can't transitively depend on an adapter
dfg::CoreDef::Trampoline(_)
| dfg::CoreDef::InstanceFlags(_)
- | dfg::CoreDef::UnsafeIntrinsic(..) => {}
+ | dfg::CoreDef::UnsafeIntrinsic(..)
+ | dfg::CoreDef::TaskMayBlock => {}
}
}
diff --git a/crates/environ/src/component/translate/inline.rs b/crates/environ/src/component/translate/inline.rs
index badbfd8e8d..afff24fc41 100644
--- a/crates/environ/src/component/translate/inline.rs
+++ b/crates/environ/src/component/translate/inline.rs
@@ -1594,7 +1594,7 @@ impl<'a> Inliner<'a> {
}
}
- /// Translatees an `AdapterOptions` into a `CanonicalOptions` where
+ /// Translates an `AdapterOptions` into a `CanonicalOptions` where
/// memories/functions are inserted into the global initializer list for
/// use at runtime. This is only used for lowered host functions and lifted
/// functions exported to the host.
diff --git a/crates/environ/src/component/vmcomponent_offsets.rs b/crates/environ/src/component/vmcomponent_offsets.rs
index bbbb0e79a1..6743dbba2f 100644
--- a/crates/environ/src/component/vmcomponent_offsets.rs
+++ b/crates/environ/src/component/vmcomponent_offsets.rs
@@ -5,6 +5,7 @@
// builtins: &'static VMComponentBuiltins,
// limits: *const VMStoreContext,
// flags: [VMGlobalDefinition; component.num_runtime_component_instances],
+// task_may_block: u32,
// trampoline_func_refs: [VMFuncRef; component.num_trampolines],
// unsafe_intrinsics: [VMFuncRef; component.num_unsafe_intrinsics],
// lowerings: [VMLowering; component.num_lowerings],
@@ -70,6 +71,7 @@ pub struct VMComponentOffsets<P> {
builtins: u32,
vm_store_context: u32,
flags: u32,
+ task_may_block: u32,
trampoline_func_refs: u32,
intrinsic_func_refs: u32,
lowerings: u32,
@@ -129,6 +131,7 @@ impl<P: PtrSize> VMComponentOffsets<P> {
builtins: 0,
vm_store_context: 0,
flags: 0,
+ task_may_block: 0,
trampoline_func_refs: 0,
intrinsic_func_refs: 0,
lowerings: 0,
@@ -172,6 +175,7 @@ impl<P: PtrSize> VMComponentOffsets<P> {
size(vm_store_context) = ret.ptr.size(),
align(16),
size(flags) = cmul(ret.num_runtime_component_instances, ret.ptr.size_of_vmglobal_definition()),
+ size(task_may_block) = ret.ptr.size_of_vmglobal_definition(),
align(u32::from(ret.ptr.size())),
size(trampoline_func_refs) = cmul(ret.num_trampolines, ret.ptr.size_of_vm_func_ref()),
size(intrinsic_func_refs) = cmul(ret.num_unsafe_intrinsics, ret.ptr.size_of_vm_func_ref()),
@@ -219,6 +223,11 @@ impl<P: PtrSize> VMComponentOffsets<P> {
self.flags + index.as_u32() * u32::from(self.ptr.size_of_vmglobal_definition())
}
+ /// The offset of the `task_may_block` field.
+ pub fn task_may_block(&self) -> u32 {
+ self.task_may_block
+ }
+
/// The offset of the `vm_store_context` field.
#[inline]
pub fn vm_store_context(&self) -> u32 {
diff --git a/crates/environ/src/fact.rs b/crates/environ/src/fact.rs
index 74da3aba4a..686c0ba96b 100644
--- a/crates/environ/src/fact.rs
+++ b/crates/environ/src/fact.rs
@@ -88,8 +88,6 @@ pub struct Module<'a> {
imported_stream_transfer: Option<FuncIndex>,
imported_error_context_transfer: Option<FuncIndex>,
- imported_check_blocking: Option<FuncIndex>,
-
imported_trap: Option<FuncIndex>,
// Current status of index spaces from the imports generated so far.
@@ -102,6 +100,8 @@ pub struct Module<'a> {
helper_worklist: Vec<(FunctionId, Helper)>,
exports: Vec<(u32, String)>,
+
+ task_may_block: Option<GlobalIndex>,
}
struct AdapterData {
@@ -262,9 +262,9 @@ impl<'a> Module<'a> {
imported_future_transfer: None,
imported_stream_transfer: None,
imported_error_context_transfer: None,
- imported_check_blocking: None,
imported_trap: None,
exports: Vec::new(),
+ task_may_block: None,
}
}
@@ -460,6 +460,25 @@ impl<'a> Module<'a> {
idx
}
+ fn import_task_may_block(&mut self) -> GlobalIndex {
+ if let Some(task_may_block) = self.task_may_block {
+ task_may_block
+ } else {
+ let task_may_block = self.import_global(
+ "instance",
+ "task_may_block",
+ GlobalType {
+ val_type: ValType::I32,
+ mutable: true,
+ shared: false,
+ },
+ CoreDef::TaskMayBlock,
+ );
+ self.task_may_block = Some(task_may_block);
+ task_may_block
+ }
+ }
+
fn import_transcoder(&mut self, transcoder: transcode::Transcoder) -> FuncIndex {
*self
.imported_transcoders
@@ -717,17 +736,6 @@ impl<'a> Module<'a> {
)
}
- fn import_check_blocking(&mut self) -> FuncIndex {
- self.import_simple(
- "async",
- "check-blocking",
- &[],
- &[],
- Import::CheckBlocking,
- |me| &mut me.imported_check_blocking,
- )
- }
-
fn import_trap(&mut self) -> FuncIndex {
self.import_simple(
"runtime",
@@ -882,9 +890,6 @@ pub enum Import {
/// An intrinisic used by FACT-generated modules to (partially or entirely) transfer
/// ownership of an `error-context`.
ErrorContextTransfer,
- /// An intrinsic used by FACT-generated modules to check whether an
- /// async-typed function may be called via a sync lower.
- CheckBlocking,
/// An intrinsic for trapping the instance with a specific trap code.
Trap,
}
diff --git a/crates/environ/src/fact/trampoline.rs b/crates/environ/src/fact/trampoline.rs
index 0411e67f78..f75c30ccf3 100644
--- a/crates/environ/src/fact/trampoline.rs
+++ b/crates/environ/src/fact/trampoline.rs
@@ -753,10 +753,22 @@ impl<'a, 'b> Compiler<'a, 'b> {
);
}
- if self.types[adapter.lift.ty].async_ {
- let check_blocking = self.module.import_check_blocking();
- self.instruction(Call(check_blocking.as_u32()));
- }
+ let task_may_block = self.module.import_task_may_block();
+ let old_task_may_block = if self.types[adapter.lift.ty].async_ {
+ self.instruction(GlobalGet(task_may_block.as_u32()));
+ self.instruction(I32Eqz);
+ self.instruction(If(BlockType::Empty));
+ self.trap(Trap::CannotBlockSyncTask);
+ self.instruction(End);
+ None
+ } else {
+ let task_may_block = self.module.import_task_may_block();
+ self.instruction(GlobalGet(task_may_block.as_u32()));
+ let old_task_may_block = self.local_set_new_tmp(ValType::I32);
+ self.instruction(I32Const(0));
+ self.instruction(GlobalSet(task_may_block.as_u32()));
+ Some(old_task_may_block)
+ };
if self.emit_resource_call {
let enter = self.module.import_resource_enter_call();
@@ -831,6 +843,13 @@ impl<'a, 'b> Compiler<'a, 'b> {
self.instruction(Call(exit.as_u32()));
}
+ if let Some(old_task_may_block) = old_task_may_block {
+ let task_may_block = self.module.import_task_may_block();
+ self.instruction(LocalGet(old_task_may_block.idx));
+ self.instruction(GlobalSet(task_may_block.as_u32()));
+ self.free_temp_local(old_task_may_block);
+ }
+
self.finish()
}
diff --git a/crates/test-util/src/wast.rs b/crates/test-util/src/wast.rs
index f02c8bba58..c07dda1f8b 100644
--- a/crates/test-util/src/wast.rs
+++ b/crates/test-util/src/wast.rs
@@ -700,19 +700,6 @@ impl WastTest {
}
}
- let failing_component_model_tests = [
- // TODO: Remove this once
- // https://github.com/WebAssembly/component-model/issues/345 has
- // been addressed and the test updated accordingly:
- "component-model/test/wasm-tools/naming.wast",
- ];
- if failing_component_model_tests
- .iter()
- .any(|part| self.path.ends_with(part))
- {
- return true;
- }
-
// Not implemented in Wasmtime anywhere yet.
if self.config.custom_descriptors() {
let happens_to_work =
diff --git a/crates/wasmtime/src/runtime/component/concurrent.rs b/crates/wasmtime/src/runtime/component/concurrent.rs
index f4e084c69f..7df5c07dd8 100644
--- a/crates/wasmtime/src/runtime/component/concurrent.rs
+++ b/crates/wasmtime/src/runtime/component/concurrent.rs
@@ -710,12 +710,6 @@ pub(crate) enum WaitResult {
Completed,
}
-/// Raise a trap if the calling task is synchronous and trying to block prior to
-/// returning a value.
-pub(crate) fn check_blocking(store: &mut dyn VMStore) -> Result<()> {
- store.concurrent_state_mut().check_blocking()
-}
-
/// Poll the specified future until it completes on behalf of a guest->host call
/// using a sync-lowered import.
///
@@ -841,7 +835,7 @@ fn handle_guest_call(store: &mut dyn VMStore, call: GuestCall) -> Result<()> {
call.thread,
);
- let old_thread = state.guest_thread.replace(call.thread);
+ let old_thread = store.set_thread(Some(call.thread));
log::trace!(
"GuestCallKind::DeliverEvent: replaced {old_thread:?} with {:?} as current thread",
call.thread
@@ -869,6 +863,8 @@ fn handle_guest_call(store: &mut dyn VMStore, call: GuestCall) -> Result<()> {
store.maybe_pop_call_context(call.thread.task)?;
+ store.set_thread(old_thread);
+
next = instance.handle_callback_code(
store,
call.thread,
@@ -876,7 +872,6 @@ fn handle_guest_call(store: &mut dyn VMStore, call: GuestCall) -> Result<()> {
code,
)?;
- store.concurrent_state_mut().guest_thread = old_thread;
log::trace!(
"GuestCallKind::DeliverEvent: restored {old_thread:?} as current thread"
);
@@ -1404,7 +1399,6 @@ impl StoreOpaque {
StoreComponentInstanceId::new(self.id(), instance.instance)
.get_mut(self)
.instance_state(instance.index)
- .unwrap()
.concurrent_state()
}
@@ -1414,10 +1408,61 @@ impl StoreOpaque {
StoreComponentInstanceId::new(self.id(), instance.instance)
.get_mut(self)
.instance_state(instance.index)
- .unwrap()
.handle_table()
}
+ fn set_thread(&mut self, thread: Option<QualifiedThreadId>) -> Option<QualifiedThreadId> {
+ // Each time we switch threads, we conservatively set `task_may_block`
+ // to `false` for the component instance we're switching away from (if
+ // any), meaning it will be `false` for any new thread created for that
+ // instance unless explicitly set otherwise.
+ let state = self.concurrent_state_mut();
+ let old_thread = state.guest_thread.take();
+ if let Some(old_thread) = old_thread {
+ let instance = state.get_mut(old_thread.task).unwrap().instance.instance;
+ StoreComponentInstanceId::new(self.id(), instance)
+ .get_mut(self)
+ .set_task_may_block(false)
+ }
+
+ self.concurrent_state_mut().guest_thread = thread;
+
+ // If we're switching to a new thread, set its component instance's
+ // `task_may_block` according to where it left off.
+ if thread.is_some() {
+ self.set_task_may_block();
+ }
+
+ old_thread
+ }
+
+ /// Set the global variable representing whether the current task may block
+ /// prior to entering Wasm code.
+ fn set_task_may_block(&mut self) {
+ let state = self.concurrent_state_mut();
+ let guest_thread = state.guest_thread.unwrap();
+ let instance = state.get_mut(guest_thread.task).unwrap().instance.instance;
+ let may_block = self.concurrent_state_mut().may_block(guest_thread.task);
+ StoreComponentInstanceId::new(self.id(), instance)
+ .get_mut(self)
+ .set_task_may_block(may_block)
+ }
+
+ pub(crate) fn check_blocking(&mut self) -> Result<()> {
+ let state = self.concurrent_state_mut();
+ let task = state.guest_thread.unwrap().task;
+ let instance = state.get_mut(task).unwrap().instance.instance;
+ let task_may_block = StoreComponentInstanceId::new(self.id(), instance)
+ .get_mut(self)
+ .get_task_may_block();
+
+ if task_may_block {
+ Ok(())
+ } else {
+ Err(Trap::CannotBlockSyncTask.into())
+ }
+ }
+
/// Record that we're about to enter a (sub-)component instance which does
/// not support more than one concurrent, stackful activation, meaning it
/// cannot be entered again until the next call returns.
@@ -1483,9 +1528,10 @@ impl StoreOpaque {
let fiber = fiber::resolve_or_release(self, fiber).await?;
+ self.set_thread(old_thread);
+
let state = self.concurrent_state_mut();
- state.guest_thread = old_thread;
if let Some(ref ot) = old_thread {
state.get_mut(ot.thread)?.state = GuestThreadState::Running;
}
@@ -1579,7 +1625,7 @@ impl StoreOpaque {
self.with_blocking(|_, cx| cx.suspend(StoreFiberYield::ReleaseStore))?;
if let Some(task) = task {
- self.concurrent_state_mut().guest_thread = old_guest_thread;
+ self.set_thread(old_guest_thread);
self.maybe_push_call_context(task)?;
}
@@ -1948,10 +1994,7 @@ impl Instance {
store,
callee_instance.index,
)?;
- let old_thread = store
- .concurrent_state_mut()
- .guest_thread
- .replace(guest_thread);
+ let old_thread = store.set_thread(Some(guest_thread));
log::trace!(
"stackless call: replaced {old_thread:?} with {guest_thread:?} as current thread"
);
@@ -1972,8 +2015,8 @@ impl Instance {
store.maybe_pop_call_context(guest_thread.task)?;
+ store.set_thread(old_thread);
let state = store.concurrent_state_mut();
- state.guest_thread = old_thread;
old_thread
.map(|t| state.get_mut(t.thread).unwrap().state = GuestThreadState::Running);
log::trace!("stackless call: restored {old_thread:?} as current thread");
@@ -1993,10 +2036,7 @@ impl Instance {
store,
callee_instance.index,
)?;
- let old_thread = store
- .concurrent_state_mut()
- .guest_thread
- .replace(guest_thread);
+ let old_thread = store.set_thread(Some(guest_thread));
log::trace!(
"sync/async-stackful call: replaced {old_thread:?} with {guest_thread:?} as current thread",
);
@@ -2104,6 +2144,8 @@ impl Instance {
)?;
}
+ store.set_thread(old_thread);
+
store.maybe_pop_call_context(guest_thread.task)?;
let state = store.concurrent_state_mut();
@@ -2166,7 +2208,7 @@ impl Instance {
// A task may only call an async-typed function via a sync lower if
// it was created by a call to an async export. Otherwise, we'll
// trap.
- store.0.concurrent_state_mut().check_blocking()?;
+ store.0.check_blocking()?;
}
enum ResultInfo {
@@ -2327,10 +2369,10 @@ impl Instance {
// Make the new thread the current one so that `Self::start_call` knows
// which one to start.
- state.guest_thread = Some(QualifiedThreadId {
+ store.0.set_thread(Some(QualifiedThreadId {
task: guest_task,
thread: guest_thread,
- });
+ }));
log::trace!(
"pushed {guest_task:?}:{guest_thread:?} as current thread; old thread was {old_thread:?}"
);
@@ -2544,33 +2586,30 @@ impl Instance {
}
};
- let state = store.0.concurrent_state_mut();
+ guest_waitable.join(store.0.concurrent_state_mut(), old_set)?;
- guest_waitable.join(state, old_set)?;
+ // Reset the current thread to point to the caller as it resumes control.
+ store.0.set_thread(Some(caller));
+ store.0.concurrent_state_mut().get_mut(caller.thread)?.state = GuestThreadState::Running;
+ log::trace!("popped current thread {guest_thread:?}; new thread is {caller:?}");
if let Some(storage) = storage {
// The caller used a sync-lowered import to call an async-lifted
// export, in which case the result, if any, has been stashed in
// `GuestTask::sync_result`.
+ let state = store.0.concurrent_state_mut();
let task = state.get_mut(guest_thread.task)?;
if let Some(result) = task.sync_result.take() {
if let Some(result) = result {
storage[0] = MaybeUninit::new(result);
}
- if task.exited {
- if task.ready_to_delete() {
- Waitable::Guest(guest_thread.task).delete_from(state)?;
- }
+ if task.exited && task.ready_to_delete() {
+ Waitable::Guest(guest_thread.task).delete_from(state)?;
}
}
}
- // Reset the current thread to point to the caller as it resumes control.
- state.guest_thread = Some(caller);
- state.get_mut(caller.thread)?.state = GuestThreadState::Running;
- log::trace!("popped current thread {guest_thread:?}; new thread is {caller:?}");
-
Ok(status.pack(waitable))
}
@@ -3015,7 +3054,7 @@ impl Instance {
// The caller may only call `waitable-set.wait` from an async task
// (i.e. a task created via a call to an async export).
// Otherwise, we'll trap.
- store.concurrent_state_mut().check_blocking()?;
+ store.check_blocking()?;
}
let &CanonicalOptions {
@@ -3122,10 +3161,7 @@ impl Instance {
let token = StoreToken::new(store.as_context_mut());
let start_func = Box::new(
move |store: &mut dyn VMStore, guest_thread: QualifiedThreadId| -> Result<()> {
- let old_thread = store
- .concurrent_state_mut()
- .guest_thread
- .replace(guest_thread);
+ let old_thread = store.set_thread(Some(guest_thread));
log::trace!(
"thread start: replaced {old_thread:?} with {guest_thread:?} as current thread"
);
@@ -3147,7 +3183,8 @@ impl Instance {
if task.threads.is_empty() && !task.returned_or_cancelled() {
bail!(Trap::NoAsyncResult);
}
- state.guest_thread = old_thread;
+ store.0.set_thread(old_thread);
+ let state = store.0.concurrent_state_mut();
old_thread
.map(|t| state.get_mut(t.thread).unwrap().state = GuestThreadState::Running);
if state.get_mut(guest_thread.task)?.ready_to_delete() {
@@ -3256,7 +3293,7 @@ impl Instance {
// The caller may only call `thread.suspend` from an async task
// (i.e. a task created via a call to an async export).
// Otherwise, we'll trap.
- state.check_blocking()?;
+ store.check_blocking()?;
}
}
@@ -3397,7 +3434,7 @@ impl Instance {
// The caller may only sync call `subtask.cancel` from an async task
// (i.e. a task created via a call to an async export). Otherwise,
// we'll trap.
- store.concurrent_state_mut().check_blocking()?;
+ store.check_blocking()?;
}
let (rep, is_host) = store
@@ -4939,11 +4976,6 @@ impl ConcurrentState {
}
}
- fn check_blocking(&mut self) -> Result<()> {
- let task = self.guest_thread.unwrap().task;
- self.check_blocking_for(task)
- }
-
fn check_blocking_for(&mut self, task: TableId<GuestTask>) -> Result<()> {
if self.may_block(task) {
Ok(())
diff --git a/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs b/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs
index 913e43d393..f1fa44d110 100644
--- a/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs
+++ b/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs
@@ -3243,7 +3243,7 @@ impl Instance {
// The caller may only sync call `{stream,future}.write` from an
// async task (i.e. a task created via a call to an async export).
// Otherwise, we'll trap.
- store.0.concurrent_state_mut().check_blocking()?;
+ store.0.check_blocking()?;
}
let address = usize::try_from(address).unwrap();
@@ -3478,7 +3478,7 @@ impl Instance {
// The caller may only sync call `{stream,future}.read` from an
// async task (i.e. a task created via a call to an async export).
// Otherwise, we'll trap.
- store.0.concurrent_state_mut().check_blocking()?;
+ store.0.check_blocking()?;
}
let address = usize::try_from(address).unwrap();
@@ -3864,7 +3864,7 @@ impl Instance {
// The caller may only sync call `{stream,future}.cancel-write` from
// an async task (i.e. a task created via a call to an async
// export). Otherwise, we'll trap.
- store.concurrent_state_mut().check_blocking()?;
+ store.check_blocking()?;
}
let (rep, state) =
@@ -3905,7 +3905,7 @@ impl Instance {
// The caller may only sync call `{stream,future}.cancel-read` from
// an async task (i.e. a task created via a call to an async
// export). Otherwise, we'll trap.
- store.concurrent_state_mut().check_blocking()?;
+ store.check_blocking()?;
}
let (rep, state) =
diff --git a/crates/wasmtime/src/runtime/component/concurrent_disabled.rs b/crates/wasmtime/src/runtime/component/concurrent_disabled.rs
index 68f58ec5f9..2843cd5b2f 100644
--- a/crates/wasmtime/src/runtime/component/concurrent_disabled.rs
+++ b/crates/wasmtime/src/runtime/component/concurrent_disabled.rs
@@ -1,7 +1,7 @@
use crate::component::func::{LiftContext, LowerContext};
use crate::component::matching::InstanceType;
use crate::component::{ComponentType, Lift, Lower, Val};
-use crate::runtime::vm::VMStore;
+use crate::store::StoreOpaque;
use crate::{Result, bail, error::format_err};
use core::convert::Infallible;
use core::mem::MaybeUninit;
@@ -19,10 +19,6 @@ fn should_have_failed_validation<T>(what: &str) -> Result<T> {
))
}
-pub(crate) fn check_blocking(_: &mut dyn VMStore) -> Result<()> {
- Ok(())
-}
-
pub(crate) fn lower_error_context_to_index<U>(
_rep: u32,
_cx: &mut LowerContext<'_, U>,
@@ -154,3 +150,9 @@ unsafe impl Lower for StreamAny {
match self.0 {}
}
}
+
+impl StoreOpaque {
+ pub(crate) fn check_blocking(&mut self) -> Result<()> {
+ Ok(())
+ }
+}
diff --git a/crates/wasmtime/src/runtime/component/func/host.rs b/crates/wasmtime/src/runtime/component/func/host.rs
index 24aca7e0d9..a20a80d23e 100644
--- a/crates/wasmtime/src/runtime/component/func/host.rs
+++ b/crates/wasmtime/src/runtime/component/func/host.rs
@@ -1,5 +1,6 @@
//! Implementation of calling Rust-defined functions from components.
+#[cfg(feature = "component-model-async")]
use crate::component::concurrent;
#[cfg(feature = "component-model-async")]
use crate::component::concurrent::{Accessor, Status};
@@ -327,7 +328,7 @@ where
// The caller has synchronously lowered an async function, meaning
// the caller can only call it from an async task (i.e. a task
// created via a call to an async export). Otherwise, we'll trap.
- concurrent::check_blocking(store.0)?;
+ store.0.check_blocking()?;
}
let mut lift = LiftContext::new(store.0.store_opaque_mut(), options, instance);
diff --git a/crates/wasmtime/src/runtime/component/instance.rs b/crates/wasmtime/src/runtime/component/instance.rs
index caa75ae503..41c7f6cd8d 100644
--- a/crates/wasmtime/src/runtime/component/instance.rs
+++ b/crates/wasmtime/src/runtime/component/instance.rs
@@ -614,6 +614,9 @@ pub(crate) fn lookup_vmdef(
// within that store, so it's safe to create a `Func`.
vm::Export::Function(unsafe { crate::Func::from_vm_func_ref(store.id(), funcref) })
}
+ CoreDef::TaskMayBlock => vm::Export::Global(crate::Global::from_task_may_block(
+ StoreComponentInstanceId::new(store.id(), id),
+ )),
}
}
diff --git a/crates/wasmtime/src/runtime/externals/global.rs b/crates/wasmtime/src/runtime/externals/global.rs
index d10c0cbecb..8927793fca 100644
--- a/crates/wasmtime/src/runtime/externals/global.rs
+++ b/crates/wasmtime/src/runtime/externals/global.rs
@@ -338,6 +338,17 @@ impl Global {
}
}
+ #[cfg(feature = "component-model")]
+ pub(crate) fn from_task_may_block(
+ instance: crate::component::store::StoreComponentInstanceId,
+ ) -> Global {
+ Global {
+ store: instance.store_id(),
+ instance: instance.instance().as_u32(),
+ kind: VMGlobalKind::TaskMayBlock,
+ }
+ }
+
pub(crate) fn wasmtime_ty<'a>(&self, store: &'a StoreOpaque) -> &'a wasmtime_environ::Global {
self.store.assert_belongs_to(store.id());
match self.kind {
@@ -349,7 +360,7 @@ impl Global {
}
VMGlobalKind::Host(index) => unsafe { &store.host_globals()[index].get().as_ref().ty },
#[cfg(feature = "component-model")]
- VMGlobalKind::ComponentFlags(_) => {
+ VMGlobalKind::ComponentFlags(_) | VMGlobalKind::TaskMayBlock => {
const TY: wasmtime_environ::Global = wasmtime_environ::Global {
mutability: true,
wasm_ty: wasmtime_environ::WasmValType::I32,
@@ -367,7 +378,7 @@ impl Global {
}
VMGlobalKind::Host(_) => None,
#[cfg(feature = "component-model")]
- VMGlobalKind::ComponentFlags(_) => {
+ VMGlobalKind::ComponentFlags(_) | VMGlobalKind::TaskMayBlock => {
let instance = crate::component::ComponentInstanceId::from_u32(self.instance);
Some(
VMOpaqueContext::from_vmcomponent(store.component_instance(instance).vmctx())
@@ -414,6 +425,12 @@ impl Global {
.instance_flags(index)
.as_raw()
}
+ #[cfg(feature = "component-model")]
+ VMGlobalKind::TaskMayBlock => store
+ .component_instance(crate::component::ComponentInstanceId::from_u32(
+ self.instance,
+ ))
+ .task_may_block(),
}
}
}
diff --git a/crates/wasmtime/src/runtime/vm/component.rs b/crates/wasmtime/src/runtime/vm/component.rs
index a10db5053a..35feb448d6 100644
--- a/crates/wasmtime/src/runtime/vm/component.rs
+++ b/crates/wasmtime/src/runtime/vm/component.rs
@@ -871,8 +871,8 @@ impl ComponentInstance {
pub fn instance_state(
self: Pin<&mut Self>,
instance: RuntimeComponentInstanceIndex,
- ) -> Option<&mut InstanceState> {
- self.instance_states().0.get_mut(instance)
+ ) -> &mut InstanceState {
+ &mut self.instance_states().0[instance]
}
/// Returns the destructor and instance flags for the specified resource
@@ -1006,6 +1006,20 @@ impl ComponentInstance {
Err(crate::format_err!(crate::Trap::CannotLeaveComponent))
}
}
+
+ pub(crate) fn task_may_block(&self) -> NonNull<VMGlobalDefinition> {
+ unsafe { self.vmctx_plus_offset_raw::<VMGlobalDefinition>(self.offsets.task_may_block()) }
+ }
+
+ #[cfg(feature = "component-model-async")]
+ pub(crate) fn get_task_may_block(&self) -> bool {
+ unsafe { *self.task_may_block().as_ref().as_i32() != 0 }
+ }
+
+ #[cfg(feature = "component-model-async")]
+ pub(crate) fn set_task_may_block(self: Pin<&mut Self>, val: bool) {
+ unsafe { *self.task_may_block().as_mut().as_i32_mut() = if val { 1 } else { 0 } }
+ }
}
// SAFETY: `layout` should describe this accurately and `OwnedVMContext` is the
diff --git a/crates/wasmtime/src/runtime/vm/component/libcalls.rs b/crates/wasmtime/src/runtime/vm/component/libcalls.rs
index d7f8527c3e..01c6f45897 100644
--- a/crates/wasmtime/src/runtime/vm/component/libcalls.rs
+++ b/crates/wasmtime/src/runtime/vm/component/libcalls.rs
@@ -971,11 +971,6 @@ fn error_context_transfer(
instance.error_context_transfer(store, src_idx, src_table, dst_table)
}
-#[cfg(feature = "component-model-async")]
-fn check_blocking(store: &mut dyn VMStore, _instance: Instance) -> Result<()> {
- crate::component::concurrent::check_blocking(store)
-}
-
#[cfg(feature = "component-model-async")]
unsafe impl HostResultHasUnwindSentinel for ResourcePair {
type Abi = u64;
diff --git a/crates/wasmtime/src/runtime/vm/instance.rs b/crates/wasmtime/src/runtime/vm/instance.rs
index 38b9df44bb..a574e38033 100644
--- a/crates/wasmtime/src/runtime/vm/instance.rs
+++ b/crates/wasmtime/src/runtime/vm/instance.rs
@@ -675,6 +675,20 @@ impl Instance {
index,
)
}
+ #[cfg(feature = "component-model")]
+ VMGlobalKind::TaskMayBlock => {
+ // SAFETY: validity of this `&Instance` means validity of its
+ // imports meaning we can read the id of the vmctx within.
+ let id = unsafe {
+ let vmctx = super::component::VMComponentContext::from_opaque(
+ import.vmctx.unwrap().as_non_null(),
+ );
+ super::component::ComponentInstance::vmctx_instance_id(vmctx)
+ };
+ crate::Global::from_task_may_block(
+ crate::component::store::StoreComponentInstanceId::new(store, id),
+ )
+ }
}
}
diff --git a/crates/wasmtime/src/runtime/vm/vmcontext.rs b/crates/wasmtime/src/runtime/vm/vmcontext.rs
index 61cbba81c7..c3287979a1 100644
--- a/crates/wasmtime/src/runtime/vm/vmcontext.rs
+++ b/crates/wasmtime/src/runtime/vm/vmcontext.rs
@@ -292,6 +292,8 @@ pub enum VMGlobalKind {
/// Flags for a component instance, stored in `VMComponentContext`.
#[cfg(feature = "component-model")]
ComponentFlags(wasmtime_environ::component::RuntimeComponentInstanceIndex),
+ #[cfg(feature = "component-model")]
+ TaskMayBlock,
}
// SAFETY: the above enum is repr(C) and stores nothing else
diff --git a/tests/all/pooling_allocator.rs b/tests/all/pooling_allocator.rs
index fddd26bf64..1ba7fc805e 100644
--- a/tests/all/pooling_allocator.rs
+++ b/tests/all/pooling_allocator.rs
@@ -859,7 +859,7 @@ fn component_instance_size_limit() -> Result<()> {
match wasmtime::component::Component::new(&engine, "(component)") {
Ok(_) => panic!("should have hit limit"),
Err(e) => e.assert_contains(
- "instance allocation for this component requires 48 bytes of \
+ "instance allocation for this component requires 64 bytes of \
`VMComponentContext` space which exceeds the configured maximum of 1 bytes",
),
}
diff --git a/tests/component-model b/tests/component-model
index 09d7c76615..48603cbc04 160000
--- a/tests/component-model
+++ b/tests/component-model
@@ -1 +1 @@
-Subproject commit 09d7c7661513e9b6bad926594d1e2605c791d7da
+Subproject commit 48603cbc04dbb3e69cefba5b259941876459fb8d
diff --git a/tests/disas/component-model/direct-adapter-calls-inlining.wat b/tests/disas/component-model/direct-adapter-calls-inlining.wat
index 01717f76ae..6c8f4fb6d8 100644
--- a/tests/disas/component-model/direct-adapter-calls-inlining.wat
+++ b/tests/disas/component-model/direct-adapter-calls-inlining.wat
@@ -65,9 +65,10 @@
;; gv7 = vmctx
;; gv8 = load.i64 notrap aligned readonly can_move gv7+120
;; gv9 = load.i64 notrap aligned readonly can_move gv7+96
-;; gv10 = vmctx
-;; gv11 = load.i64 notrap aligned readonly gv10+8
-;; gv12 = load.i64 notrap aligned gv11+16
+;; gv10 = load.i64 notrap aligned readonly can_move gv7+144
+;; gv11 = vmctx
+;; gv12 = load.i64 notrap aligned readonly gv11+8
+;; gv13 = load.i64 notrap aligned gv12+16
;; sig0 = (i64 vmctx, i64, i32) -> i32 tail
;; sig1 = (i64 vmctx, i64, i32) tail
;; sig2 = (i64 vmctx, i64, i32) -> i32 tail
@@ -90,10 +91,10 @@
;; brif v18, block4, block5
;;
;; block4:
-;; v93 = load.i64 notrap aligned readonly can_move v5+72
-;; v94 = load.i64 notrap aligned readonly can_move v5+88
+;; v92 = load.i64 notrap aligned readonly can_move v5+72
+;; v93 = load.i64 notrap aligned readonly can_move v5+88
;; v19 = iconst.i32 24
-;; call_indirect sig1, v93(v94, v5, v19) ; v19 = 24
+;; call_indirect sig1, v92(v93, v5, v19) ; v19 = 24
;; trap user11
;;
;; block5:
@@ -101,9 +102,9 @@
;; v23 = load.i32 notrap aligned table v22
;; v24 = iconst.i32 2
;; v25 = band v23, v24 ; v24 = 2
-;; v85 = iconst.i32 0
-;; v86 = icmp eq v25, v85 ; v85 = 0
-;; v28 = uextend.i32 v86
+;; v81 = iconst.i32 0
+;; v82 = icmp eq v25, v81 ; v81 = 0
+;; v28 = uextend.i32 v82
;; brif v28, block6, block7
;;
;; block6:
@@ -117,12 +118,17 @@
;; v34 = iconst.i32 -3
;; v35 = band.i32 v23, v34 ; v34 = -3
;; store notrap aligned table v35, v22
-;; v66 = iconst.i32 -4
-;; v72 = band.i32 v23, v66 ; v66 = -4
-;; store notrap aligned table v72, v22
-;; v87 = iconst.i32 1
-;; v88 = bor v35, v87 ; v87 = 1
-;; store notrap aligned table v88, v22
+;; v37 = load.i64 notrap aligned readonly can_move v5+144
+;; v38 = load.i32 notrap aligned table v37
+;; v83 = iconst.i32 0
+;; store notrap aligned table v83, v37 ; v83 = 0
+;; v42 = load.i32 notrap aligned table v22
+;; v43 = iconst.i32 -2
+;; v44 = band v42, v43 ; v43 = -2
+;; store notrap aligned table v44, v22
+;; v84 = iconst.i32 1
+;; v85 = bor v42, v84 ; v84 = 1
+;; store notrap aligned table v85, v22
;; jump block8
;;
;; block8:
@@ -132,17 +138,18 @@
;; jump block10
;;
;; block10:
-;; v51 = load.i32 notrap aligned table v12
-;; v39 = iconst.i32 -2
-;; v53 = band v51, v39 ; v39 = -2
-;; store notrap aligned table v53, v12
-;; v89 = iconst.i32 1
-;; v90 = bor v51, v89 ; v89 = 1
-;; store notrap aligned table v90, v12
-;; v61 = load.i32 notrap aligned table v22
-;; v91 = iconst.i32 2
-;; v92 = bor v61, v91 ; v91 = 2
-;; store notrap aligned table v92, v22
+;; v55 = load.i32 notrap aligned table v12
+;; v86 = iconst.i32 -2
+;; v87 = band v55, v86 ; v86 = -2
+;; store notrap aligned table v87, v12
+;; v88 = iconst.i32 1
+;; v89 = bor v55, v88 ; v88 = 1
+;; store notrap aligned table v89, v12
+;; v65 = load.i32 notrap aligned table v22
+;; v90 = iconst.i32 2
+;; v91 = bor v65, v90 ; v90 = 2
+;; store notrap aligned table v91, v22
+;; store.i32 notrap aligned table v38, v37
;; jump block3
;;
;; block3:
@@ -152,6 +159,6 @@
;; @00f0 jump block1
;;
;; block1:
-;; v76 = iconst.i32 1276
-;; @00f0 return v76 ; v76 = 1276
+;; v72 = iconst.i32 1276
+;; @00f0 return v72 ; v72 = 1276
;; }
diff --git a/tests/disas/component-model/direct-adapter-calls-x64.wat b/tests/disas/component-model/direct-adapter-calls-x64.wat
index 36096bbf26..e1ef652561 100644
--- a/tests/disas/component-model/direct-adapter-calls-x64.wat
+++ b/tests/disas/component-model/direct-adapter-calls-x64.wat
@@ -85,52 +85,63 @@
;; movq %rsp, %rbp
;; movq 8(%rdi), %r10
;; movq 0x10(%r10), %r10
-;; addq $0x20, %r10
+;; addq $0x30, %r10
;; cmpq %rsp, %r10
-;; ja 0x120
-;; 79: subq $0x10, %rsp
+;; ja 0x14e
+;; 79: subq $0x20, %rsp
;; movq %rbx, (%rsp)
-;; movq %r13, 8(%rsp)
-;; movq 0x78(%rdi), %rbx
-;; movl (%rbx), %eax
-;; testl $1, %eax
-;; je 0x10b
-;; 97: movq 0x60(%rdi), %r13
-;; movq %rdi, %rsi
-;; movl (%r13), %eax
-;; testl $2, %eax
-;; je 0xf9
-;; ad: movq %rax, %r8
-;; andl $0xfffffffd, %r8d
-;; movl %r8d, (%r13)
-;; andl $0xfffffffc, %eax
-;; movl %eax, (%r13)
-;; orl $1, %r8d
-;; movl %r8d, (%r13)
-;; movq 0x40(%rsi), %rdi
-;; callq 0
-;; movl (%rbx), %r10d
-;; movq %r10, %rsi
-;; andl $0xfffffffe, %esi
+;; movq %r12, 8(%rsp)
+;; movq %r14, 0x10(%rsp)
+;; movq %r15, 0x18(%rsp)
+;; movq 0x78(%rdi), %r12
+;; movl (%r12), %r8d
+;; testl $1, %r8d
+;; je 0x13a
+;; a5: movq 0x60(%rdi), %rbx
+;; movl (%rbx), %r9d
+;; testl $2, %r9d
+;; je 0x126
+;; b9: andl $0xfffffffd, %r9d
+;; movl %r9d, (%rbx)
+;; movq 0x90(%rdi), %r14
+;; movq %rdi, %r10
+;; movl (%r14), %r15d
+;; movl $0, (%r14)
+;; movl (%rbx), %esi
+;; movq %rsi, %rax
+;; andl $0xfffffffe, %eax
+;; movl %eax, (%rbx)
+;; orl $1, %esi
;; movl %esi, (%rbx)
-;; orl $1, %r10d
-;; movl %r10d, (%rbx)
-;; orl $2, (%r13)
+;; movq 0x40(%r10), %rdi
+;; movq %r10, %rsi
+;; callq 0
+;; movl (%r12), %ecx
+;; movq %rcx, %rdx
+;; andl $0xfffffffe, %edx
+;; movl %edx, (%r12)
+;; orl $1, %ecx
+;; movl %ecx, (%r12)
+;; orl $2, (%rbx)
+;; movl %r15d, (%r14)
;; movq (%rsp), %rbx
-;; movq 8(%rsp), %r13
-;; addq $0x10, %rsp
+;; movq 8(%rsp), %r12
+;; movq 0x10(%rsp), %r14
+;; movq 0x18(%rsp), %r15
+;; addq $0x20, %rsp
;; movq %rbp, %rsp
;; popq %rbp
;; retq
-;; f9: movq 0x48(%rsi), %r8
-;; fd: movq 0x58(%rsi), %rdi
-;; 101: movl $0x12, %edx
-;; 106: callq *%r8
-;; 109: ud2
-;; 10b: movq %rdi, %rsi
-;; 10e: movq 0x48(%rsi), %r10
-;; 112: movq 0x58(%rsi), %rdi
-;; 116: movl $0x18, %edx
-;; 11b: callq *%r10
-;; 11e: ud2
-;; 120: ud2
+;; 126: movq %rdi, %rsi
+;; 129: movq 0x48(%rsi), %rax
+;; 12d: movq 0x58(%rsi), %rdi
+;; 131: movl $0x12, %edx
+;; 136: callq *%rax
+;; 138: ud2
+;; 13a: movq %rdi, %rsi
+;; 13d: movq 0x48(%rsi), %rcx
+;; 141: movq 0x58(%rsi), %rdi
+;; 145: movl $0x18, %edx
+;; 14a: callq *%rcx
+;; 14c: ud2
+;; 14e: ud2
diff --git a/tests/disas/component-model/direct-adapter-calls.wat b/tests/disas/component-model/direct-adapter-calls.wat
index 2d95304311..ef9478ab57 100644
--- a/tests/disas/component-model/direct-adapter-calls.wat
+++ b/tests/disas/component-model/direct-adapter-calls.wat
@@ -98,69 +98,75 @@
;; gv3 = vmctx
;; gv4 = load.i64 notrap aligned readonly can_move gv3+120
;; gv5 = load.i64 notrap aligned readonly can_move gv3+96
+;; gv6 = load.i64 notrap aligned readonly can_move gv3+144
;; sig0 = (i64 vmctx, i64, i32) tail
;; sig1 = (i64 vmctx, i64, i32) -> i32 tail
;; fn0 = colocated u0:0 sig1
;; stack_limit = gv2
;;
;; block0(v0: i64, v1: i64, v2: i32):
-;; @0077 v5 = load.i64 notrap aligned readonly can_move v0+120
-;; @0077 v6 = load.i32 notrap aligned table v5
-;; @0079 v7 = iconst.i32 1
-;; @007b v8 = band v6, v7 ; v7 = 1
-;; @0075 v4 = iconst.i32 0
-;; @007c v9 = icmp eq v8, v4 ; v4 = 0
-;; @007c v10 = uextend.i32 v9
-;; @007d brif v10, block2, block3
+;; @0092 v5 = load.i64 notrap aligned readonly can_move v0+120
+;; @0092 v6 = load.i32 notrap aligned table v5
+;; @0094 v7 = iconst.i32 1
+;; @0096 v8 = band v6, v7 ; v7 = 1
+;; @0090 v4 = iconst.i32 0
+;; @0097 v9 = icmp eq v8, v4 ; v4 = 0
+;; @0097 v10 = uextend.i32 v9
+;; @0098 brif v10, block2, block3
;;
;; block2:
;; v94 = load.i64 notrap aligned readonly can_move v0+72
;; v95 = load.i64 notrap aligned readonly can_move v0+88
-;; @007f v11 = iconst.i32 24
-;; @0081 call_indirect sig0, v94(v95, v0, v11) ; v11 = 24
-;; @0083 trap user11
+;; @009a v11 = iconst.i32 24
+;; @009c call_indirect sig0, v94(v95, v0, v11) ; v11 = 24
+;; @009e trap user11
;;
;; block3:
-;; @0085 v15 = load.i64 notrap aligned readonly can_move v0+96
-;; @0085 v16 = load.i32 notrap aligned table v15
-;; @0087 v17 = iconst.i32 2
-;; @0089 v18 = band v16, v17 ; v17 = 2
-;; v87 = iconst.i32 0
-;; v88 = icmp eq v18, v87 ; v87 = 0
-;; @008a v20 = uextend.i32 v88
-;; @008b brif v20, block4, block5
+;; @00a0 v15 = load.i64 notrap aligned readonly can_move v0+96
+;; @00a0 v16 = load.i32 notrap aligned table v15
+;; @00a2 v17 = iconst.i32 2
+;; @00a4 v18 = band v16, v17 ; v17 = 2
+;; v86 = iconst.i32 0
+;; v87 = icmp eq v18, v86 ; v86 = 0
+;; @00a5 v20 = uextend.i32 v87
+;; @00a6 brif v20, block4, block5
;;
;; block4:
-;; @0081 v14 = load.i64 notrap aligned readonly can_move v0+72
-;; @0081 v13 = load.i64 notrap aligned readonly can_move v0+88
-;; @008d v21 = iconst.i32 18
-;; @008f call_indirect sig0, v14(v13, v0, v21) ; v21 = 18
-;; @0091 trap user11
+;; @009c v14 = load.i64 notrap aligned readonly can_move v0+72
+;; @009c v13 = load.i64 notrap aligned readonly can_move v0+88
+;; @00a8 v21 = iconst.i32 18
+;; @00aa call_indirect sig0, v14(v13, v0, v21) ; v21 = 18
+;; @00ac trap user11
;;
;; block5:
-;; @0095 v27 = iconst.i32 -3
-;; @0097 v28 = band.i32 v16, v27 ; v27 = -3
-;; @0098 store notrap aligned table v28, v15
-;; v75 = iconst.i32 -4
-;; v81 = band.i32 v16, v75 ; v75 = -4
-;; @009f store notrap aligned table v81, v15
+;; @00b0 v27 = iconst.i32 -3
+;; @00b2 v28 = band.i32 v16, v27 ; v27 = -3
+;; @00b3 store notrap aligned table v28, v15
+;; @00b5 v30 = load.i64 notrap aligned readonly can_move v0+144
+;; @00b5 v31 = load.i32 notrap aligned table v30
+;; v88 = iconst.i32 0
+;; @00bb store notrap aligned table v88, v30 ; v88 = 0
+;; @00bd v35 = load.i32 notrap aligned table v15
+;; @00bf v36 = iconst.i32 -2
+;; @00c1 v37 = band v35, v36 ; v36 = -2
+;; @00c2 store notrap aligned table v37, v15
;; v89 = iconst.i32 1
-;; v90 = bor v28, v89 ; v89 = 1
-;; @00a8 store notrap aligned table v90, v15
-;; @00aa v41 = load.i64 notrap aligned readonly can_move v0+64
-;; @00aa v42 = call fn0(v41, v0, v2)
-;; @00ae v44 = load.i32 notrap aligned table v5
-;; @009c v32 = iconst.i32 -2
-;; @00b2 v46 = band v44, v32 ; v32 = -2
-;; @00b3 store notrap aligned table v46, v5
-;; v91 = bor v44, v89 ; v89 = 1
-;; @00bc store notrap aligned table v91, v5
-;; @00be v54 = load.i32 notrap aligned table v15
+;; v90 = bor v35, v89 ; v89 = 1
+;; @00cb store notrap aligned table v90, v15
+;; @00cd v45 = load.i64 notrap aligned readonly can_move v0+64
+;; @00cd v46 = call fn0(v45, v0, v2)
+;; @00d1 v48 = load.i32 notrap aligned table v5
+;; @00d5 v50 = band v48, v36 ; v36 = -2
+;; @00d6 store notrap aligned table v50, v5
+;; v91 = bor v48, v89 ; v89 = 1
+;; @00df store notrap aligned table v91, v5
+;; @00e1 v58 = load.i32 notrap aligned table v15
;; v92 = iconst.i32 2
-;; v93 = bor v54, v92 ; v92 = 2
-;; @00c3 store notrap aligned table v93, v15
-;; @00c5 jump block1
+;; v93 = bor v58, v92 ; v92 = 2
+;; @00e6 store notrap aligned table v93, v15
+;; @00ea store notrap aligned table v31, v30
+;; @00ec jump block1
;;
;; block1:
-;; @00c5 return v42
+;; @00ec return v46
;; }
diff --git a/tests/misc_testsuite/component-model/async/future-read.wast b/tests/misc_testsuite/component-model/async/future-read.wast
index 934f909590..ec80f85796 100644
--- a/tests/misc_testsuite/component-model/async/future-read.wast
+++ b/tests/misc_testsuite/component-model/async/future-read.wast
@@ -25,7 +25,7 @@
(export "read" (func $read))
))
))
- (func (export "run") (param "x" $future)
+ (func (export "run") async (param "x" $future)
(canon lift (core func $i "run")))
)
(instance $child (instantiate $child))
diff --git a/tests/misc_testsuite/component-model/async/sync-streams.wast b/tests/misc_testsuite/component-model/async/sync-streams.wast
index 4d0b450ba2..205dc196c4 100644
--- a/tests/misc_testsuite/component-model/async/sync-streams.wast
+++ b/tests/misc_testsuite/component-model/async/sync-streams.wast
@@ -63,6 +63,7 @@
;; (stream.read $tx $bufp 4) will block and, because called
;; synchronously, switch to the caller who will write and rendezvous
(local.set $bufp (i32.const 16))
+
(local.set $ret (call $stream.read (local.get $rx) (local.get $bufp) (i32.const 4)))
(if (i32.ne (i32.const 0x41 (; COMPLETED=0 | (4<<4) ;)) (local.get $ret))
(then unreachable))
@@ -94,18 +95,18 @@
(export "stream.drop-readable" (func $stream.drop-readable))
(export "stream.drop-writable" (func $stream.drop-writable))
))))
- (func (export "get") (result (stream u8)) (canon lift
+ (func (export "get") async (result (stream u8)) (canon lift
(core func $cm "get")
async (memory $memory "mem") (callback (func $cm "get_cb"))
))
- (func (export "set") (param "in" (stream u8)) (canon lift
+ (func (export "set") async (param "in" (stream u8)) (canon lift
(core func $cm "set")
async (memory $memory "mem") (callback (func $cm "set_cb"))
))
)
(component $D
- (import "get" (func $get (result (stream u8))))
- (import "set" (func $set (param "in" (stream u8))))
+ (import "get" (func $get async (result (stream u8))))
+ (import "set" (func $set async (param "in" (stream u8))))
(core module $Memory (memory (export "mem") 1))
(core instance $memory (instantiate $Memory))
@@ -172,7 +173,7 @@
(export "get" (func $get'))
(export "set" (func $set'))
))))
- (func (export "run") (result u32) (canon lift (core func $dm "run")))
+ (func (export "run") async (result u32) (canon lift (core func $dm "run")))
)
(instance $c (instantiate $C))
diff --git a/tests/misc_testsuite/component-model/async/trap-if-done.wast b/tests/misc_testsuite/component-model/async/trap-if-done.wast
index d4220cbc63..742edac1fe 100644
--- a/tests/misc_testsuite/component-model/async/trap-if-done.wast
+++ b/tests/misc_testsuite/component-model/async/trap-if-done.wast
@@ -122,22 +122,22 @@
))))
(func (export "start-future") (result (future u8)) (canon lift (core func $cm "start-future")))
(func (export "future-write") (result u32) (canon lift (core func $cm "future-write")))
- (func (export "acknowledge-future-write") (canon lift (core func $cm "acknowledge-future-write")))
+ (func (export "acknowledge-future-write") async (canon lift (core func $cm "acknowledge-future-write")))
(func (export "future-drop-writable") (canon lift (core func $cm "future-drop-writable")))
(func (export "start-stream") (result (stream u8)) (canon lift (core func $cm "start-stream")))
(func (export "stream-write") (result u32) (canon lift (core func $cm "stream-write")))
- (func (export "acknowledge-stream-write") (canon lift (core func $cm "acknowledge-stream-write")))
+ (func (export "acknowledge-stream-write") async (canon lift (core func $cm "acknowledge-stream-write")))
(func (export "stream-drop-writable") (canon lift (core func $cm "stream-drop-writable")))
)
(component $D
(import "c" (instance $c
(export "start-future" (func (result (future u8))))
(export "future-write" (func (result u32)))
- (export "acknowledge-future-write" (func))
+ (export "acknowledge-future-write" (func async))
(export "future-drop-writable" (func))
(export "start-stream" (func (result (stream u8))))
(export "stream-write" (func (result u32)))
- (export "acknowledge-stream-write" (func))
+ (export "acknowledge-stream-write" (func async))
(export "stream-drop-writable" (func))
))