(
store: &mut dyn crate::vm::VMStore,
instance: crate::store::InstanceId,
func: *mut u8,
param_count: u32,
result_count: u32,
)
| 297 | #[cfg(feature = "stack-switching")] |
| 298 | #[inline(always)] |
| 299 | pub fn cont_new( |
| 300 | store: &mut dyn crate::vm::VMStore, |
| 301 | instance: crate::store::InstanceId, |
| 302 | func: *mut u8, |
| 303 | param_count: u32, |
| 304 | result_count: u32, |
| 305 | ) -> crate::Result<*mut VMContRef> { |
| 306 | let instance = store.instance_mut(instance); |
| 307 | let caller_vmctx = instance.vmctx(); |
| 308 | |
| 309 | let stack_size = store.engine().config().async_stack_size; |
| 310 | |
| 311 | let contref = store.allocate_continuation()?; |
| 312 | let contref = unsafe { contref.as_mut().unwrap() }; |
| 313 | |
| 314 | let tsp = contref.stack.top().unwrap(); |
| 315 | contref.parent_chain = VMStackChain::Absent; |
| 316 | // The continuation is fresh, which is a special case of being suspended. |
| 317 | // Thus we need to set the correct end of the continuation chain: itself. |
| 318 | contref.last_ancestor = contref; |
| 319 | |
| 320 | // The initialization function will allocate the actual args/return value buffer and |
| 321 | // update this object (if needed). |
| 322 | let contref_args_ptr = &mut contref.args as *mut _ as *mut VMHostArray<crate::ValRaw>; |
| 323 | |
| 324 | contref.stack.initialize( |
| 325 | func.cast::<crate::vm::VMFuncRef>(), |
| 326 | caller_vmctx.as_ptr(), |
| 327 | contref_args_ptr, |
| 328 | param_count, |
| 329 | result_count, |
| 330 | ); |
| 331 | |
| 332 | // Now that the initial stack pointer was set by the initialization |
| 333 | // function, use it to determine stack limit. |
| 334 | let stack_pointer = contref.stack.control_context_stack_pointer(); |
| 335 | // Same caveat regarding stack_limit here as described in |
| 336 | // `wasmtime::runtime::func::EntryStoreContext::enter_wasm`. |
| 337 | let wasm_stack_limit = core::cmp::max( |
| 338 | stack_pointer - store.engine().config().max_wasm_stack, |
| 339 | tsp as usize - stack_size, |
| 340 | ); |
| 341 | let limits = VMStackLimits::with_stack_limit(wasm_stack_limit); |
| 342 | let csi = &mut contref.common_stack_information; |
| 343 | csi.state = VMStackState::Fresh; |
| 344 | csi.limits = limits; |
| 345 | |
| 346 | log::trace!("Created contref @ {contref:p}"); |
| 347 | Ok(contref) |
| 348 | } |
| 349 | |
| 350 | /// This type represents a linked lists ("chain") of stacks, where the a |
| 351 | /// node's successor denotes its parent. |
nothing calls this directly
no test coverage detected