Skip to content

Commit

Permalink
Fix: unify flags if multiple segments are mapped to same frame with d…
Browse files Browse the repository at this point in the history
…ifferent flags
  • Loading branch information
phil-opp committed Feb 16, 2024
1 parent 5186c62 commit 6b49d24
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use crate::frame_allocator::FrameAllocator;
use bootloader::bootinfo::MemoryRegionType;
use bootloader::bootinfo::TlsTemplate;
use fixedvec::FixedVec;
use x86_64::structures::paging::mapper::{MapToError, MapperFlush, UnmapError};
use x86_64::structures::paging::mapper::{MapToError, MapperFlush, TranslateResult, UnmapError};
use x86_64::structures::paging::{
self, Mapper, Page, PageSize, PageTableFlags, PhysFrame, RecursivePageTable, Size4KiB,
Translate,
};
use x86_64::{align_up, PhysAddr, VirtAddr};
use xmas_elf::program::{self, ProgramHeader64};
Expand Down Expand Up @@ -101,6 +102,18 @@ pub(crate) fn map_segment(
} {
Ok(flusher) => flusher.flush(),
Err(MapToError::PageAlreadyMapped(to)) if to == frame => {
let flags = match page_table.translate(page.start_address()) {
TranslateResult::Mapped { flags, .. } => flags,
_ => unreachable!(),
};
if flags != page_table_flags {
unsafe {
page_table
.update_flags(page, flags | page_table_flags)
.unwrap()
.flush()
};
}
// nothing to do, page is already mapped to the correct frame
}
Err(err) => return Err(err),
Expand Down

0 comments on commit 6b49d24

Please sign in to comment.