diff --git a/ostd/src/mm/frame/segment.rs b/ostd/src/mm/frame/segment.rs index d718f184..915c0e62 100644 --- a/ostd/src/mm/frame/segment.rs +++ b/ostd/src/mm/frame/segment.rs @@ -116,6 +116,8 @@ impl Segment { /// It could be manually forgotten by [`core::mem::forget`], /// [`ManuallyDrop`], or [`Self::into_raw`]. pub(crate) unsafe fn from_raw(range: Range) -> Self { + debug_assert_eq!(range.start % PAGE_SIZE, 0); + debug_assert_eq!(range.end % PAGE_SIZE, 0); Self { range, _marker: core::marker::PhantomData, diff --git a/ostd/src/mm/heap/slot.rs b/ostd/src/mm/heap/slot.rs index 1893ee9c..fee85412 100644 --- a/ostd/src/mm/heap/slot.rs +++ b/ostd/src/mm/heap/slot.rs @@ -116,8 +116,7 @@ impl HeapSlot { debug_assert_eq!(size % PAGE_SIZE, 0); debug_assert_eq!(self.paddr() % PAGE_SIZE, 0); - let nframes = size / PAGE_SIZE; - let range = self.paddr()..self.paddr() + nframes; + let range = self.paddr()..self.paddr() + size; // SAFETY: The segment was once forgotten when allocated. drop(unsafe { Segment::::from_raw(range) });