Skip to content
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

Use Undefined instruction with payload to carry over TrapInformation on Singlepass #2836

Merged
merged 15 commits into from
May 11, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Made a static out of the 0xc0 constant used for ud payload
  • Loading branch information
ptitSeb committed Apr 5, 2022
commit 92820575457921e1bf63bec9a7651b564be59037
7 changes: 6 additions & 1 deletion lib/vm/src/trap/traphandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ use std::ptr::{self, NonNull};
use std::sync::atomic::{compiler_fence, AtomicPtr, Ordering};
use std::sync::{Mutex, Once};

// TrapInformation can be stored in the "Undefined Instruction" itself.
// On x86_64, 0xC? select a "Register" for the Mod R/M part of "ud1" (so with no other bytes after)
// On Arm64, the udf alows for a 16bits values, so we'll use the same 0xC? to store the trapinfo
static MAGIC: u8 = 0xc0;

cfg_if::cfg_if! {
if #[cfg(unix)] {
/// Function which may handle custom signals while processing traps.
Expand Down Expand Up @@ -179,7 +184,7 @@ cfg_if::cfg_if! {
0
}
}
if val&0xc0 == 0xc0 {
if val&MAGIC == MAGIC {
ptitSeb marked this conversation as resolved.
Show resolved Hide resolved
match val&0x0f {
0 => Some(TrapCode::StackOverflow),
1 => Some(TrapCode::HeapAccessOutOfBounds),
Expand Down