Skip to content

Commit

Permalink
[Fix] dont jump out from JMP_BUF
Browse files Browse the repository at this point in the history
Signed-off-by: csh <[email protected]>
  • Loading branch information
L-jasmine committed Sep 7, 2023
1 parent 8ee72d3 commit 5c6ef2c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
13 changes: 7 additions & 6 deletions crates/wasmedge-sys/src/async/fiber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,17 @@ impl<'a> Future for TimeoutFiberFuture<'a> {
in_host: &mut in_host,
is_timeout: &mut is_timeout,
};
let r = if setjmp::sigsetjmp(&mut env, 1) == 0 {
crate::executor::JMP_BUF.set(&jmp_state, || {

let r = crate::executor::JMP_BUF.set(&jmp_state, || {
if setjmp::sigsetjmp(&mut env, 1) == 0 {
match self.as_ref().fiber.resume(Ok(())) {
Ok(ret) => Poll::Ready(ret),
Err(_) => Poll::Pending,
}
})
} else {
Poll::Ready(Err(()))
};
} else {
Poll::Ready(Err(()))
}
});
libc::timer_delete(timerid);
r
})
Expand Down
24 changes: 12 additions & 12 deletions crates/wasmedge-sys/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,9 @@ impl Executor {
in_host: &mut in_host,
is_timeout: &mut is_timeout,
};
if setjmp::sigsetjmp(env, 1) == 0 {
let r = JMP_BUF.set(&jmp_state, || {

let r = JMP_BUF.set(&jmp_state, || {
if setjmp::sigsetjmp(env, 1) == 0 {
check(ffi::WasmEdge_ExecutorInvoke(
self.inner.0,
func.inner.lock().0 as *const _,
Expand All @@ -428,17 +429,16 @@ impl Executor {
returns.as_mut_ptr(),
returns_len,
))
});
libc::timer_delete(timerid);
r?;
returns.set_len(returns_len as usize);
} else {
libc::timer_delete(timerid);
return Err(Box::new(error::WasmEdgeError::Operation("timeout".into())));
}
}
} else {
Err(Box::new(error::WasmEdgeError::Operation("timeout".into())))
}
});
libc::timer_delete(timerid);
r?;

Ok(returns.into_iter().map(Into::into).collect::<Vec<_>>())
returns.set_len(returns_len as usize);
Ok(returns.into_iter().map(Into::into).collect::<Vec<_>>())
}
}

/// Asynchronously runs a host function instance and returns the results.
Expand Down

0 comments on commit 5c6ef2c

Please sign in to comment.