Skip to content

Commit 994e9ae

Browse files
committed
Enable the functionality for the no-execute flag in page tables
1 parent c37486d commit 994e9ae

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

kernel/src/memory/vmm/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::memory::KERNEL_HEAP;
1414
use crate::{println, Locked};
1515
use fixed_size_block::FixedSizeBlockAllocator;
1616
use x86_64::registers::control::{Cr4, Cr4Flags};
17+
use x86_64::registers::model_specific::{Efer, EferFlags};
1718
use x86_64::structures::paging::mapper::{MapToError, MapperFlushAll};
1819
use x86_64::structures::paging::{
1920
FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PageTableFlags, Size4KiB,
@@ -62,6 +63,12 @@ pub fn init(
6263
flags |= Cr4Flags::PAGE_GLOBAL; // Enable the global flag in page tables.
6364
unsafe { Cr4::write(flags) };
6465

66+
// Set the EFER fields, so we can use the no-execute
67+
// page flag when we remap the kernel.
68+
let mut flags = Efer::read();
69+
flags |= EferFlags::NO_EXECUTE_ENABLE; // Enable the no-execute flag in page tables.
70+
unsafe { Efer::write(flags) };
71+
6572
// Remap the kernel, now that the heap is set up.
6673
unsafe { remap_kernel(mapper) };
6774

0 commit comments

Comments
 (0)