mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Use the correct entry flags for kernel sections
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
use memory::Frame;
|
use memory::Frame;
|
||||||
|
use multiboot2::ElfSection;
|
||||||
|
|
||||||
pub struct Entry(u64);
|
pub struct Entry(u64);
|
||||||
|
|
||||||
@@ -45,3 +46,26 @@ bitflags! {
|
|||||||
const NO_EXECUTE = 1 << 63,
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ pub fn remap_the_kernel<A>(allocator: &mut A, boot_info: &BootInformation)
|
|||||||
println!("mapping section at addr: {:#x}, size: {:#x}",
|
println!("mapping section at addr: {:#x}, size: {:#x}",
|
||||||
section.addr, section.size);
|
section.addr, section.size);
|
||||||
|
|
||||||
let flags = WRITABLE; // TODO use real section flags
|
let flags = EntryFlags::from_elf_section_flags(section);
|
||||||
|
|
||||||
let start_frame = Frame::containing_address(section.start_address());
|
let start_frame = Frame::containing_address(section.start_address());
|
||||||
let end_frame = Frame::containing_address(section.end_address() - 1);
|
let end_frame = Frame::containing_address(section.end_address() - 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user