From 76d1c41e96a2959cd65a209f28bfd2c04ca71392 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Thu, 31 Dec 2015 15:32:30 +0100 Subject: [PATCH] Use correct section flags (causes a page fault) --- src/memory/paging/entry.rs | 22 ++++++++++++++++++++++ src/memory/paging/mod.rs | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/memory/paging/entry.rs b/src/memory/paging/entry.rs index b223727a..c01c447d 100644 --- a/src/memory/paging/entry.rs +++ b/src/memory/paging/entry.rs @@ -8,6 +8,7 @@ // except according to those terms. use memory::Frame; +use multiboot2::ElfSection; pub struct Entry(u64); @@ -52,3 +53,24 @@ bitflags! { const NO_EXECUTE = 1 << 63, } } + +impl EntryFlags { + pub fn from_elf_section_flags(section: &ElfSection) -> EntryFlags { + use multiboot2::{ELF_SECTION_ALLOCATED, ELF_SECTION_WRITABLE, ELF_SECTION_EXECUTABLE}; + + let mut flags = EntryFlags::empty(); + + if section.flags().contains(ELF_SECTION_ALLOCATED) { + // section is loaded to memory + flags = flags | PRESENT; + } + if section.flags().contains(ELF_SECTION_WRITABLE) { + flags = flags | WRITABLE; + } + if !section.flags().contains(ELF_SECTION_EXECUTABLE) { + flags = flags | NO_EXECUTE; + } + + flags + } +} diff --git a/src/memory/paging/mod.rs b/src/memory/paging/mod.rs index 7746c41c..d3c906e3 100644 --- a/src/memory/paging/mod.rs +++ b/src/memory/paging/mod.rs @@ -204,7 +204,7 @@ pub fn remap_the_kernel(allocator: &mut A, boot_info: &BootInformation) section.addr, section.size); - let flags = WRITABLE; // TODO use real section flags + let flags = EntryFlags::from_elf_section_flags(section); let range = Range { start: section.addr as usize,