Skip to content

Commit 433f149

Browse files
zyuiopmkroening
authored andcommitted
fix(riscv64/paging): memory unmapping
1 parent 28c7089 commit 433f149

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/arch/riscv64/mm/paging.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ impl PageTableEntry {
135135
(self.physical_address_and_flags & PageTableEntryFlags::EXECUTABLE.bits()) != 0
136136
}
137137

138+
/// Mark this as an invalid (not present) entry
139+
fn unset(&mut self) {
140+
self.physical_address_and_flags = PhysAddr::zero();
141+
}
142+
138143
/// Mark this as a valid (present) entry and set address translation and flags.
139144
///
140145
/// # Arguments
@@ -377,10 +382,15 @@ impl<L: PageTableLevel> PageTableMethods for PageTable<L> {
377382
let index = page.table_index::<L>();
378383
let flush = self.entries[index].is_present();
379384

380-
self.entries[index].set(
381-
physical_address,
382-
S::MAP_EXTRA_FLAG | PageTableEntryFlags::ACCESSED | PageTableEntryFlags::DIRTY | flags,
383-
);
385+
if physical_address.is_null() && flags == PageTableEntryFlags::BLANK {
386+
// Clear PTE
387+
self.entries[index].unset();
388+
} else {
389+
self.entries[index].set(
390+
physical_address,
391+
S::MAP_EXTRA_FLAG | PageTableEntryFlags::ACCESSED | PageTableEntryFlags::DIRTY | flags,
392+
);
393+
}
384394

385395
if flush {
386396
page.flush_from_tlb();

0 commit comments

Comments
 (0)