Skip to content

Commit 30f47e2

Browse files
committed
call check_may_leave before check_blocking
`check_blocking` needs access to the current task, but that's not set for post-return functions since those should not be calling _any_ imports at all, so first check for that. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent 3547452 commit 30f47e2

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

crates/wasmtime/src/runtime/component/concurrent.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,11 +2858,12 @@ impl Instance {
28582858
set: u32,
28592859
payload: u32,
28602860
) -> Result<u32> {
2861+
self.id().get(store).check_may_leave(caller)?;
2862+
28612863
if !self.options(store, options).async_ {
28622864
store.concurrent_state_mut().check_blocking()?;
28632865
}
28642866

2865-
self.id().get(store).check_may_leave(caller)?;
28662867
let &CanonicalOptions {
28672868
cancellable,
28682869
instance: caller_instance,
@@ -2891,11 +2892,12 @@ impl Instance {
28912892
set: u32,
28922893
payload: u32,
28932894
) -> Result<u32> {
2895+
self.id().get(store).check_may_leave(caller)?;
2896+
28942897
if !self.options(store, options).async_ {
28952898
store.concurrent_state_mut().check_blocking()?;
28962899
}
28972900

2898-
self.id().get(store).check_may_leave(caller)?;
28992901
let &CanonicalOptions {
29002902
cancellable,
29012903
instance: caller_instance,
@@ -3074,6 +3076,8 @@ impl Instance {
30743076
yielding: bool,
30753077
to_thread: Option<u32>,
30763078
) -> Result<WaitResult> {
3079+
self.id().get(store).check_may_leave(caller)?;
3080+
30773081
if to_thread.is_none() && !yielding {
30783082
// This is a `thread.suspend` call
30793083
store.concurrent_state_mut().check_blocking()?;
@@ -3084,8 +3088,6 @@ impl Instance {
30843088
return Ok(WaitResult::Cancelled);
30853089
}
30863090

3087-
self.id().get(store).check_may_leave(caller)?;
3088-
30893091
if let Some(thread) = to_thread {
30903092
self.resume_suspended_thread(store, caller, thread, true)?;
30913093
}
@@ -3208,11 +3210,12 @@ impl Instance {
32083210
async_: bool,
32093211
task_id: u32,
32103212
) -> Result<u32> {
3213+
self.id().get(store).check_may_leave(caller_instance)?;
3214+
32113215
if !async_ {
32123216
store.concurrent_state_mut().check_blocking()?;
32133217
}
32143218

3215-
self.id().get(store).check_may_leave(caller_instance)?;
32163219
let (rep, is_host) =
32173220
self.id().get_mut(store).guest_tables().0[caller_instance].subtask_rep(task_id)?;
32183221
let (waitable, expected_caller_instance) = if is_host {

0 commit comments

Comments
 (0)