Skip to content

Commit

Permalink
Panic again when segements overlap
Browse files Browse the repository at this point in the history
This seems like a good indicator for bugs in the mapping code.

This reverts PR #423 and commit f317b0d.
  • Loading branch information
phil-opp committed Feb 16, 2024
1 parent 4b80d28 commit 265314f
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions src/page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 265314f

Please sign in to comment.