Wrap borrows of page table entries in unsafe.

This is safe because `Entry` is `#[repr(8)]` which is the minimum
alignment for qwords. Since the size of a qword is equal to that
alignment (8), they can also be borrowed from the array.
This commit is contained in:
4lDO2
2020-06-11 16:05:00 +02:00
parent 5d53c65f0b
commit 8117119d8e
2 changed files with 13 additions and 5 deletions

View File

@@ -77,3 +77,11 @@ impl Entry {
self.0 = (self.0 & !COUNTER_MASK) | (count << 52);
}
}
#[cfg(test)]
mod tests {
#[test]
fn entry_has_required_arch_alignment() {
assert_eq!(core::mem::align_of::<Entry>(), core::mem::align_of::<u64>());
}
}

View File

@@ -55,7 +55,7 @@ impl<L> Table<L> where L: TableLevel {
}
pub fn zero(&mut self) {
for entry in self.entries.iter_mut() {
for entry in unsafe { &mut self.entries }.iter_mut() {
entry.set_zero();
}
}
@@ -63,12 +63,12 @@ impl<L> Table<L> where L: TableLevel {
/// Set number of entries in first table entry
fn set_entry_count(&mut self, count: u64) {
debug_assert!(count <= ENTRY_COUNT as u64, "count can't be greater than ENTRY_COUNT");
self.entries[0].set_counter_bits(count);
unsafe { &mut self.entries[0] }.set_counter_bits(count)
}
/// Get number of entries in first table entry
fn entry_count(&self) -> u64 {
self.entries[0].counter_bits()
unsafe { &self.entries[0] }.counter_bits()
}
pub fn increment_entry_count(&mut self) {
@@ -118,12 +118,12 @@ impl<L> Index<usize> for Table<L> where L: TableLevel {
type Output = Entry;
fn index(&self, index: usize) -> &Entry {
&self.entries[index]
unsafe { &self.entries[index] }
}
}
impl<L> IndexMut<usize> for Table<L> where L: TableLevel {
fn index_mut(&mut self, index: usize) -> &mut Entry {
&mut self.entries[index]
unsafe { &mut self.entries[index] }
}
}