Skip to content

Commit fbaf10e

Browse files
committed
chore: improve exception table
1 parent dfaa046 commit fbaf10e

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/loongarch64/trap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn handle_page_fault(tf: &mut TrapFrame, access_flags: PageFaultFlags) {
2222
if core::hint::likely(handle_trap!(PAGE_FAULT, vaddr, access_flags)) {
2323
return;
2424
}
25-
if !crate::trap::fixup_exception(tf) {
25+
if !tf.fixup_exception() {
2626
panic!(
2727
"Unhandled PLV0 Page Fault @ {:#x}, fault_vaddr={:#x} ({:?}):\n{:#x?}\n{}",
2828
tf.era,

src/riscv/trap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn handle_page_fault(tf: &mut TrapFrame, access_flags: PageFaultFlags) {
2323
if core::hint::likely(handle_trap!(PAGE_FAULT, vaddr, access_flags)) {
2424
return;
2525
}
26-
if !crate::trap::fixup_exception(tf) {
26+
if !tf.fixup_exception() {
2727
panic!(
2828
"Unhandled Supervisor Page Fault @ {:#x}, fault_vaddr={:#x} ({:?}):\n{:#x?}\n{}",
2929
tf.sepc,

src/trap.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,22 @@ struct ExceptionTableEntry {
5858
to: usize,
5959
}
6060

61-
pub fn fixup_exception(tf: &mut TrapFrame) -> bool {
62-
let ip = tf.ip();
63-
let entries = unsafe {
64-
core::slice::from_raw_parts(
65-
_ex_table_start as *const ExceptionTableEntry,
66-
(_ex_table_end as usize - _ex_table_start as usize)
67-
/ core::mem::size_of::<ExceptionTableEntry>(),
68-
)
69-
};
70-
match entries.binary_search_by(|e| e.from.cmp(&ip)) {
71-
Ok(entry) => {
72-
tf.set_ip(entries[entry].to);
73-
true
61+
impl TrapFrame {
62+
pub(crate) fn fixup_exception(&mut self) -> bool {
63+
let entries = unsafe {
64+
core::slice::from_raw_parts(
65+
_ex_table_start as *const ExceptionTableEntry,
66+
(_ex_table_end as usize - _ex_table_start as usize)
67+
/ core::mem::size_of::<ExceptionTableEntry>(),
68+
)
69+
};
70+
match entries.binary_search_by(|e| e.from.cmp(&self.ip())) {
71+
Ok(entry) => {
72+
self.set_ip(entries[entry].to);
73+
true
74+
}
75+
Err(_) => false,
7476
}
75-
Err(_) => false,
7677
}
7778
}
7879

@@ -84,7 +85,7 @@ pub(crate) fn init_exception_table() {
8485
(_ex_table_end as usize - _ex_table_start as usize) / size_of::<ExceptionTableEntry>(),
8586
)
8687
};
87-
ex_table.sort();
88+
ex_table.sort_unstable();
8889
}
8990

9091
unsafe extern "C" {

0 commit comments

Comments
 (0)