-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve traps #2305
Improve traps #2305
Conversation
bors try |
tryBuild failed: |
bors try |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
pub struct CallThreadState { | ||
unwind: Cell<UnwindReason>, | ||
pub struct CallThreadState<'a> { | ||
unwind: UnsafeCell<MaybeUninit<UnwindReason>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we replace MaybeUninit with something safer, like Option? That way we can detect an unwind that happened without an unwnd_with, instead of just executing undefined behaviour in unsafe Rust?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I actually tried with Option
but it turned to be not trivial (and I couldn't solve it in a few hours, so I went with this).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add an explicit "Poison" state to the UnwindReason and then initialize to that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a pidgin copy of the problem in the rust playground, this code works:
use std::cell::UnsafeCell;
pub struct Foo {
unwind: UnsafeCell<Option<UnwindReason>>,
}
enum UnwindReason {
Foo(u8),
Bar
}
impl Foo {
fn a(mut self) {
match unsafe { &*self.unwind.get() } {
Some(UnwindReason::Foo(_unwind)) => {},
Some(UnwindReason::Bar) => {},
None => {}
}
}
fn b(&self, reason: UnwindReason) {
*(unsafe { &mut *self.unwind.get() }) = Some(reason);
}
}
pub struct CallThreadState { | ||
unwind: Cell<UnwindReason>, | ||
pub struct CallThreadState<'a> { | ||
unwind: UnsafeCell<MaybeUninit<UnwindReason>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add an explicit "Poison" state to the UnwindReason and then initialize to that?
pub struct CallThreadState { | ||
unwind: Cell<UnwindReason>, | ||
pub struct CallThreadState<'a> { | ||
unwind: UnsafeCell<MaybeUninit<UnwindReason>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a pidgin copy of the problem in the rust playground, this code works:
use std::cell::UnsafeCell;
pub struct Foo {
unwind: UnsafeCell<Option<UnwindReason>>,
}
enum UnwindReason {
Foo(u8),
Bar
}
impl Foo {
fn a(mut self) {
match unsafe { &*self.unwind.get() } {
Some(UnwindReason::Foo(_unwind)) => {},
Some(UnwindReason::Bar) => {},
None => {}
}
}
fn b(&self, reason: UnwindReason) {
*(unsafe { &mut *self.unwind.get() }) = Some(reason);
}
}
bors try |
Merging manually to avoid CI since tests have already passed and there are no new changes since last tests |
Description
This PR moves the trap code forward so we can start refactoring easily in subsequent PRs:
is_wasm_pc
method to the traps/engine (so we only trap Wasm-related signals/...)Store
generic overTrapInfo
(so users can implement their custom trap handlers)Interrupt
(non-used) andVMOutOfMemory
(moved intoRuntimeError
) cases inTrapCode
, so it's deterministicReview