mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Fix sign extension bug in next_table_address (#372)
Fixes #362 Fix an issue where the left shift of the old table address would overwrite the sign extension, making the address non-canonical and leading to #GPs. This calculates the correct sign extension for the new table address.
This commit is contained in:
committed by
Philipp Oppermann
parent
0a583ca73b
commit
cf2c5550aa
@@ -31,6 +31,15 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Addresses are expected to be canonical (bits 48-63 must be the same as bit 47), otherwise the
|
||||||
|
* CPU will #GP when we ask it to translate it.
|
||||||
|
*/
|
||||||
|
fn make_address_canonical(address : usize) -> usize {
|
||||||
|
let sign_extension = 0o177777_000_000_000_000_0000 * ((address >> 47) & 0b1);
|
||||||
|
(address & ((1 << 48) - 1)) | sign_extension
|
||||||
|
}
|
||||||
|
|
||||||
impl<L> Table<L>
|
impl<L> Table<L>
|
||||||
where
|
where
|
||||||
L: HierarchicalLevel,
|
L: HierarchicalLevel,
|
||||||
@@ -39,7 +48,7 @@ where
|
|||||||
let entry_flags = self[index].flags();
|
let entry_flags = self[index].flags();
|
||||||
if entry_flags.contains(PRESENT) && !entry_flags.contains(HUGE_PAGE) {
|
if entry_flags.contains(PRESENT) && !entry_flags.contains(HUGE_PAGE) {
|
||||||
let table_address = self as *const _ as usize;
|
let table_address = self as *const _ as usize;
|
||||||
Some((table_address << 9) | (index << 12))
|
Some(make_address_canonical((table_address << 9) | (index << 12)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user