···236236 let mut index = 0;
237237 let mut base = self.free_list.iter();
238238 'outer: while let Some(base_frame) = base.next() {
239239- if base_frame.addr().alignment() >= layout.align() {
239239+ let address_alignment = base_frame.addr().get() & (!base_frame.addr().get() + 1);
240240+241241+ if address_alignment >= layout.align() {
240242 let mut prev_addr = base_frame.addr();
241243242244 let mut c = 0;
···116116117117 let root_pgtable = frame_alloc
118118 .allocate_one_zeroed(
119119- VirtualAddress::ZERO, // called before translation into higher half
119119+ VirtualAddress::MIN, // called before translation into higher half
120120 )
121121 .unwrap();
122122
+2-2
loader/src/mapping.rs
···9393 phys.start,
9494 phys.len(),
9595 flags,
9696- VirtualAddress::ZERO, // called before translation into higher half
9696+ VirtualAddress::MIN, // called before translation into higher half
9797 )
9898 }
9999}
···130130 phys.start,
131131 phys.len(),
132132 Flags::READ | Flags::WRITE,
133133- VirtualAddress::ZERO, // called before translation into higher half
133133+ VirtualAddress::MIN, // called before translation into higher half
134134 )?;
135135 }
136136
+9-7
loader/src/page_alloc.rs
···6060 self.page_state[idx + i] = true;
6161 }
62626363- VirtualAddress::new(idx)
6363+ let top_level_page_size = arch::page_size_for_level(arch::PAGE_TABLE_LEVELS - 1);
6464+6565+ let page = idx
6666+ .checked_mul(top_level_page_size) // convert the index into an actual address
6767+ .and_then(|idx| idx.checked_add(usize::MAX << arch::VIRT_ADDR_BITS)) // and shift it into the kernel half
6868+ .unwrap();
6969+7070+ VirtualAddress::new(page)
6471 } else {
6572 panic!("no usable top-level pages found ({num_pages} pages requested)");
6673 }
···9710498105 // how many top-level pages are needed to map `size` bytes
99106 // and attempt to allocate them
100100- let page_idx = self.allocate_pages(layout.size().div_ceil(top_level_page_size));
107107+ let base = self.allocate_pages(layout.size().div_ceil(top_level_page_size));
101108102109 // calculate the base address of the page
103110 //
···106113 //
107114 // we can then take the lowest possible address of the higher half (`usize::MAX << VA_BITS`)
108115 // and add the `idx` multiple of the size of a top-level entry to it
109109- let base = page_idx
110110- .checked_mul(top_level_page_size)
111111- .unwrap()
112112- .checked_add(usize::MAX << arch::VIRT_ADDR_BITS)
113113- .unwrap();
114116115117 let offset = if let Some(rng) = self.prng.as_mut() {
116118 // Choose a random offset.