Skip to content

Commit 6b49d24

Browse files
committed
Fix: unify flags if multiple segments are mapped to same frame with different flags
1 parent 5186c62 commit 6b49d24

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/page_table.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use crate::frame_allocator::FrameAllocator;
22
use bootloader::bootinfo::MemoryRegionType;
33
use bootloader::bootinfo::TlsTemplate;
44
use fixedvec::FixedVec;
5-
use x86_64::structures::paging::mapper::{MapToError, MapperFlush, UnmapError};
5+
use x86_64::structures::paging::mapper::{MapToError, MapperFlush, TranslateResult, UnmapError};
66
use x86_64::structures::paging::{
77
self, Mapper, Page, PageSize, PageTableFlags, PhysFrame, RecursivePageTable, Size4KiB,
8+
Translate,
89
};
910
use x86_64::{align_up, PhysAddr, VirtAddr};
1011
use xmas_elf::program::{self, ProgramHeader64};
@@ -101,6 +102,18 @@ pub(crate) fn map_segment(
101102
} {
102103
Ok(flusher) => flusher.flush(),
103104
Err(MapToError::PageAlreadyMapped(to)) if to == frame => {
105+
let flags = match page_table.translate(page.start_address()) {
106+
TranslateResult::Mapped { flags, .. } => flags,
107+
_ => unreachable!(),
108+
};
109+
if flags != page_table_flags {
110+
unsafe {
111+
page_table
112+
.update_flags(page, flags | page_table_flags)
113+
.unwrap()
114+
.flush()
115+
};
116+
}
104117
// nothing to do, page is already mapped to the correct frame
105118
}
106119
Err(err) => return Err(err),

0 commit comments

Comments
 (0)