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

Deduplicate set_mpp and get_raw_faulting_instr #363

Merged
merged 2 commits into from
Dec 26, 2024
Merged

Deduplicate set_mpp and get_raw_faulting_instr #363

merged 2 commits into from
Dec 26, 2024

Conversation

francois141
Copy link
Collaborator

Both instructions performs exactly the same logic in userspace.rs and metal.rs and are not architecture dependent. This commit removes the smell

Both instructions performs exactly the same logic in userspace.rs and metal.rs and are not architecture dependent. This commit removes the smell
Deduplicating write_pmp is not only a best practice for software engineers but also enhances the coverage of symbolic execution.
Copy link
Owner

@CharlyCst CharlyCst left a 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!

Comment on lines +524 to +543
/// 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
}
Copy link
Owner

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.

Copy link
Collaborator Author

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

@CharlyCst CharlyCst merged commit cebeffe into main Dec 26, 2024
1 check passed
@CharlyCst CharlyCst deleted the deduplicate branch December 26, 2024 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants