From 265314f5582937422e0b226dfd799fa6dafb85a6 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 16 Feb 2024 15:50:45 +0100 Subject: [PATCH] Panic again when segements overlap This seems like a good indicator for bugs in the mapping code. This reverts PR #423 and commit https://github.com/rust-osdev/bootloader/pull/422/commits/f317b0de5f8b3a5d8719e7d30433aa0b454dd4a8. --- src/page_table.rs | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/src/page_table.rs b/src/page_table.rs index 5daca1d5..35880725 100644 --- a/src/page_table.rs +++ b/src/page_table.rs @@ -97,27 +97,14 @@ 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; - match unsafe { - map_page(page, frame, page_table_flags, page_table, frame_allocator) - } { - 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), - } + unsafe { map_page(page, frame, page_table_flags, page_table, frame_allocator) } + .unwrap_or_else(|err| { + panic!( + "failed to map segment starting at {:?}: failed to map page {:?} to frame {:?}: {:?}", + start_page, page, frame, err + ) + }) + .flush(); } if mem_size > file_size {