Skip to content

Commit 9b34294

Browse files
committed
Use inclusive range and 512 page stack
1 parent 5578fea commit 9b34294

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

Diff for: src/level4_entries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl UsedLevel4Entries {
2121
let end_page: Page =
2222
Page::containing_address(VirtAddr::new(segment.virtual_addr + segment.mem_size));
2323

24-
for p4_index in u64::from(start_page.p4_index())..u64::from(end_page.p4_index()) {
24+
for p4_index in u64::from(start_page.p4_index())..=u64::from(end_page.p4_index()) {
2525
used.entry_state[p4_index as usize] = true;
2626
}
2727
}

Diff for: src/page_table.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::frame_allocator::FrameAllocator;
2-
use crate::level4_entries::UsedLevel4Entries;
32
use bootloader::bootinfo::MemoryRegionType;
43
use fixedvec::FixedVec;
54
use x86_64::structures::paging::mapper::{MapToError, MapperFlush, UnmapError};
@@ -22,13 +21,13 @@ pub(crate) fn map_kernel(
2221

2322
// Create a stack
2423
let stack_size: u64 = 512; // in pages
24+
let stack_start = stack_start + 1; // Leave the first page unmapped as a 'guard page'
2525
let stack_end = stack_start + stack_size;
2626

2727
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
2828
let region_type = MemoryRegionType::KernelStack;
2929

30-
// Leave the first page unmapped as a 'guard page'
31-
for page in Page::range(stack_start + 1, stack_end) {
30+
for page in Page::range(stack_start, stack_end) {
3231
let frame = frame_allocator
3332
.allocate_frame(region_type)
3433
.ok_or(MapToError::FrameAllocationFailed)?;

0 commit comments

Comments
 (0)