Skip to content

Commit

Permalink
[fix] check alignment in alloc_pages_at
Browse files Browse the repository at this point in the history
  • Loading branch information
hky1999 committed Dec 11, 2024
1 parent d434c9b commit adb3c90
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,17 @@ impl<const PAGE_SIZE: usize> PageAllocator for BitmapPageAllocator<PAGE_SIZE> {
if align_pow2 % PAGE_SIZE != 0 {
return Err(AllocError::InvalidParam);
}
let align_pow2 = align_pow2 / PAGE_SIZE;
if !align_pow2.is_power_of_two() {

// Check if the base address is aligned to the given alignment and the given PAGE_SIZE.
if !crate::is_aligned(base, align_pow2) || !crate::is_aligned(base, Self::PAGE_SIZE) {
return Err(AllocError::InvalidParam);
}
let align_log2 = align_pow2.trailing_zeros() as usize;

// Check if the base address is aligned to the given PAGE_SIZE.
if !crate::is_aligned(base, Self::PAGE_SIZE) {
let align_pow2 = align_pow2 / PAGE_SIZE;
if !align_pow2.is_power_of_two() {
return Err(AllocError::InvalidParam);
}
let align_log2 = align_pow2.trailing_zeros() as usize;

let idx = (base - self.base) / PAGE_SIZE;

Expand Down

0 comments on commit adb3c90

Please sign in to comment.