Skip to content

Commit

Permalink
Fix align up bug in crates/percpu
Browse files Browse the repository at this point in the history
  • Loading branch information
hky1999 committed Apr 12, 2024
1 parent 92609cc commit b27f88d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/percpu/src/imp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fn align_up(val: usize) -> usize {
const PAGE_SIZE: usize = 0x1000;
(val + PAGE_SIZE - 1) & !(PAGE_SIZE - 1)
const fn align_up_64(val: usize) -> usize {
const SIZE_64BYTE: usize = 0x40;
(val + SIZE_64BYTE - 1) & !(SIZE_64BYTE - 1)
}

#[cfg(not(target_os = "none"))]
Expand Down Expand Up @@ -32,7 +32,7 @@ pub fn percpu_area_base(cpu_id: usize) -> usize {
let base = *PERCPU_AREA_BASE.get().unwrap();
}
}
base + cpu_id * align_up(percpu_area_size())
base + cpu_id * align_up_64(percpu_area_size())
}

/// Initialize the per-CPU data area for `max_cpu_num` CPUs.
Expand All @@ -42,7 +42,7 @@ pub fn init(max_cpu_num: usize) {
#[cfg(target_os = "linux")]
{
// we not load the percpu section in ELF, allocate them here.
let total_size = align_up(size) * max_cpu_num;
let total_size = align_up_64(size) * max_cpu_num;
let layout = std::alloc::Layout::from_size_align(total_size, 0x1000).unwrap();
PERCPU_AREA_BASE.call_once(|| unsafe { std::alloc::alloc(layout) as usize });
}
Expand Down

0 comments on commit b27f88d

Please sign in to comment.