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 map errors during kernel loading #422

Merged
merged 3 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
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Unreleased


- [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
- Fix: unmap temp page again to enable multiple bss-like sections

# 0.9.25 – 2024-02-16

- [Fix data layout for custom targets for LLVM 18](https://github.com/rust-osdev/bootloader/pull/421)
Expand Down
18 changes: 15 additions & 3 deletions src/page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,15 @@ pub(crate) fn map_segment(
for frame in PhysFrame::range_inclusive(start_frame, end_frame) {
let offset = frame - start_frame;
let page = start_page + offset;
unsafe { map_page(page, frame, page_table_flags, page_table, frame_allocator)? }
.flush();
match unsafe {
map_page(page, frame, page_table_flags, page_table, frame_allocator)
} {
Ok(flusher) => flusher.flush(),
Err(MapToError::PageAlreadyMapped(to)) if to == frame => {
// nothing to do, page is already mapped to the correct frame
}
Err(err) => return Err(err),
}
}

if mem_size > file_size {
Expand All @@ -117,7 +124,7 @@ pub(crate) fn map_segment(
unsafe {
map_page(
temp_page.clone(),
new_frame.clone(),
new_frame,
page_table_flags,
page_table,
frame_allocator,
Expand Down Expand Up @@ -145,6 +152,11 @@ pub(crate) fn map_segment(
});
}

// unmap temp page again
let (new_frame, flusher) = page_table.unmap(temp_page).unwrap();
flusher.flush();

// map last page to new frame
unsafe {
map_page(
last_page,
Expand Down
Loading