Skip to content

Commit

Permalink
Merge pull request #423 from rust-osdev/update-flags
Browse files Browse the repository at this point in the history
[v0.9] Fix: unify flags if multiple segments are mapped to same frame with different flags
  • Loading branch information
phil-opp authored Feb 16, 2024
2 parents 5186c62 + a9a4787 commit 3531dfb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Unreleased

# 0.9.26 – 2024-02-16
- [Fix: unify flags if multiple segments are mapped to same frame with different flags](https://github.com/rust-osdev/bootloader/pull/423)

# 0.9.26 – 2024-02-16

- [Fix map errors during kernel loading](https://github.com/rust-osdev/bootloader/pull/422)
- Don't error if a kernel page is already mapped to the correct frame
Expand Down
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 3531dfb

Please sign in to comment.