Skip to content

Commit

Permalink
Ensure all page table frames are mapped as writable
Browse files Browse the repository at this point in the history
  • Loading branch information
Wasabi375 committed May 24, 2024
1 parent 972aaa7 commit 350adcd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

* Fix bug leading to page table frames that are not mapped as writable

# 0.11.7 – 2024-02-16

* Set `NO_EXECUTE` flag for all writable memory regions by @phil-opp in https://github.com/rust-osdev/bootloader/pull/409
Expand Down
18 changes: 16 additions & 2 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,15 @@ where
context_switch_function_start_frame,
context_switch_function_start_frame + 1,
) {
let page = Page::containing_address(VirtAddr::new(frame.start_address().as_u64()));
match unsafe {
kernel_page_table.identity_map(frame, PageTableFlags::PRESENT, frame_allocator)
kernel_page_table.map_to_with_table_flags(
page,
frame,
PageTableFlags::PRESENT,
PageTableFlags::PRESENT | PageTableFlags::WRITABLE,
frame_allocator,
)
} {
Ok(tlb) => tlb.flush(),
Err(err) => panic!("failed to identity map frame {:?}: {:?}", frame, err),
Expand All @@ -254,8 +261,15 @@ where
.allocate_frame()
.expect("failed to allocate GDT frame");
gdt::create_and_load(gdt_frame);
let gdt_page = Page::containing_address(VirtAddr::new(gdt_frame.start_address().as_u64()));
match unsafe {
kernel_page_table.identity_map(gdt_frame, PageTableFlags::PRESENT, frame_allocator)
kernel_page_table.map_to_with_table_flags(
gdt_page,
gdt_frame,
PageTableFlags::PRESENT,
PageTableFlags::PRESENT | PageTableFlags::WRITABLE,
frame_allocator,
)
} {
Ok(tlb) => tlb.flush(),
Err(err) => panic!("failed to identity map frame {:?}: {:?}", gdt_frame, err),
Expand Down

0 comments on commit 350adcd

Please sign in to comment.