-
Notifications
You must be signed in to change notification settings - Fork 1
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
Deduplicate set_mpp and get_raw_faulting_instr #363
Conversation
Both instructions performs exactly the same logic in userspace.rs and metal.rs and are not architecture dependent. This commit removes the smell
8c5a377
to
e5f963c
Compare
Deduplicating write_pmp is not only a best practice for software engineers but also enhances the coverage of symbolic execution.
e5f963c
to
f87dc5e
Compare
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.
Cool, thanks for the cleanup!
/// Return the faulting instruction at the provided exception PC. | ||
/// | ||
/// # Safety | ||
/// | ||
/// The trap info must correspond to a valid trap info, no further checks are performed. | ||
pub unsafe fn get_raw_faulting_instr(trap_info: &TrapInfo) -> usize { | ||
if trap_info.mcause == MCause::IllegalInstr as usize { | ||
// First, try mtval and check if it contains an instruction | ||
if trap_info.mtval != 0 { | ||
return trap_info.mtval; | ||
} | ||
} | ||
|
||
let instr_ptr = trap_info.mepc as *const u32; | ||
|
||
// With compressed instruction extention ("C") instructions can be misaligned. | ||
// TODO: add support for 16 bits instructions | ||
let instr = ptr::read_unaligned(instr_ptr); | ||
instr as usize | ||
} |
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.
This will fault when run in user-space. We probably won't run into those kinds of issues until we verify the instruction fetch, so its fine for now, but lets keep that in mind if it shows up in the future.
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.
@CharlyCst Good to know. This commit was a simple refactoring and doesn't change the userspace function. Let me check if I find a way to formally verify the decoder
Both instructions performs exactly the same logic in userspace.rs and metal.rs and are not architecture dependent. This commit removes the smell