Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v0.9] Fix: unify flags if multiple segments are mapped to same frame with different flags #423

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading