Skip to content

Commit 9f5cd16

Browse files
committed
Only enable recursive level 4 table mapping if a cargo feature is passed
1 parent 71899f3 commit 9f5cd16

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ features = ["unicode"]
2323
[features]
2424
default = []
2525
vga_320x200 = []
26+
recursive_level_4_table = []
2627

2728
[profile.dev]
2829
panic = "abort"

src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern crate font8x8;
1818

1919
use bootloader::bootinfo::BootInfo;
2020
use core::panic::PanicInfo;
21-
use core::slice;
21+
use core::{mem, slice};
2222
use usize_conversions::usize_from;
2323
use x86_64::structures::paging::{Mapper, RecursivePageTable};
2424
use x86_64::structures::paging::{Page, PageTableFlags, PhysFrame, Size2MiB};
@@ -245,6 +245,13 @@ fn load_elf(
245245
// Make sure that the kernel respects the write-protection bits, even when in ring 0.
246246
enable_write_protect_bit();
247247

248+
if cfg!(not(feature = "recursive_level_4_table")) {
249+
// unmap recursive entry
250+
rec_page_table.unmap(recursive_page_table_addr)
251+
.expect("error deallocating recursive entry").1.flush();
252+
mem::drop(rec_page_table);
253+
}
254+
248255
let entry_point = VirtAddr::new(entry_point);
249256

250257
unsafe { context_switch(boot_info_addr, entry_point, stack_end) };

0 commit comments

Comments
 (0)