Skip to content

Commit

Permalink
remove everything else from resume libcall
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-emrich committed Nov 13, 2023
1 parent 1f32e58 commit 1d4bb5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
16 changes: 13 additions & 3 deletions crates/cranelift/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3509,12 +3509,22 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
// The continuation object to actually call resume on.
let resume_contobj = builder.block_params(resume_block)[0];

let (vmctx, result) =
let vmctx = self.vmctx(builder.func);
let vmctx = builder.ins().global_value(self.pointer_type(), vmctx);

// We mark `resume_contobj` as the currently running one
let vmctx = tc::Vmctx::new(vmctx, self.pointer_type());
vmctx.set_active_continuation(self, builder, resume_contobj);

// We mark `resume_contobj` to be invoked
let co = tc::ContinuationObject::new(resume_contobj, self.pointer_type());
co.set_state(builder, wasmtime_continuations::State::Invoked);

let (_vmctx, result) =
generate_builtin_call!(self, builder, tc_resume, [resume_contobj]);

// Update the currently running continuation stored in the vmctx
// Now the parent contobj is active
let parent_contobj = self.typed_continuations_load_parent(builder, resume_contobj);
let vmctx = tc::Vmctx::new(vmctx, self.pointer_type());
vmctx.set_active_continuation(self, builder, parent_contobj);

// The result encodes whether the return happens via ordinary
Expand Down
23 changes: 4 additions & 19 deletions crates/runtime/src/continuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,37 +153,26 @@ pub fn resume(
);
}

// Note that this function updates the typed continuation store field in the
// VMContext (i.e., the currently running continuation), but does not update
// any parent pointers. The latter has to happen elsewhere.

// We mark `contobj` as the currently running one
instance.set_typed_continuations_store(contobj);

unsafe {
(*(*(*instance.store()).vmruntime_limits())
.stack_limit
.get_mut()) = 0
};
unsafe { (*contobj).state = State::Invoked };

match unsafe { fiber.as_mut().unwrap().resume(()) } {
Ok(()) => {
// The result of the continuation was written to the first
// entry of the payload store by virtue of using the array
// calling trampoline to execute it.

// Restore the currently running contobj entry in the VMContext
let parent = unsafe { (*contobj).parent };
instance.set_typed_continuations_store(parent);

debug_println!(
if cfg!(debug_assertions) {
let parent = unsafe { (*contobj).parent };
debug_println!(
"Continuation @ {:p} returned normally, setting running continuation in VMContext to {:p}",
contobj,
parent
);

unsafe { (*contobj).state = State::Returned };
}
Ok(0) // zero value = return normally.
}
Err(tag) => {
Expand All @@ -194,10 +183,6 @@ pub fn resume(
let signal_mask = 0xf000_0000;
debug_assert_eq!(tag & signal_mask, 0);

// Restore the currently running contobj entry in the VMContext
let parent = unsafe { (*contobj).parent };
instance.set_typed_continuations_store(parent);

Ok(tag | signal_mask)
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/runtime/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,7 @@ impl Instance {
unsafe { *self.vmctx_plus_offset_mut(self.offsets().vmctx_typed_continuations_store()) }
}

#[allow(dead_code)]
pub(crate) fn set_typed_continuations_store(
&mut self,
contobj: *mut crate::continuation::ContinuationObject,
Expand Down

0 comments on commit 1d4bb5a

Please sign in to comment.