fix page tracking bug on physical swap addresses

This commit is contained in:
bunnie 2024-05-05 21:51:17 +08:00
parent fe0db3e29a
commit 8ceaa1afe4
2 changed files with 9 additions and 5 deletions

View file

@ -70,10 +70,14 @@ pub struct BootConfig {
#[cfg(feature = "swap")]
pub swap: Option<&'static SwapDescriptor>,
/// Offset of the current free page in swap
/// Offset of the current free page in swap, used in phase 1
#[cfg(feature = "swap")]
pub swap_free_page: usize,
#[cfg(feature = "swap")]
/// Offset of the current page in swap, used in phase 2
pub last_swap_page: usize,
/// root swap page table of the process
#[cfg(feature = "swap")]
pub swap_root: &'static mut [usize],
@ -102,6 +106,8 @@ impl Default for BootConfig {
#[cfg(feature = "swap")]
swap_free_page: 0,
#[cfg(feature = "swap")]
last_swap_page: 0,
#[cfg(feature = "swap")]
swap_root: Default::default(),
}
}

View file

@ -102,8 +102,6 @@ impl MiniElf {
let mut current_page_addr: usize = 0;
let mut previous_addr: usize = 0;
let mut last_mapped_xip = 0;
#[cfg(feature = "swap")]
let mut last_swap_page = 0;
let image_phys_base = allocator.base_addr as usize + self.load_offset as usize;
// It is a requirement that the image generator lay out the artifacts on disk such that
// the page offsets line up for XIP sections. This assert confirms this necessary pre-condition.
@ -371,8 +369,8 @@ impl MiniElf {
allocator.map_page(tt, map_phys_addr, virt_page, flags, pid as XousPid);
#[cfg(feature = "swap")]
if ini_type == IniType::IniS {
allocator.map_swap(last_swap_page * 0x1000, virt_page, pid);
last_swap_page += 1;
allocator.map_swap(allocator.last_swap_page * 0x1000, virt_page, pid);
allocator.last_swap_page += 1;
}
last_mapped_xip = virt_page;