mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-21 08:16:32 +00:00
Page::inc_ref_count conforms to the reference counting invariant
format code Add detailed annotations Typo fixed
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
f94d2e55f7
commit
a0ec687315
@ -123,11 +123,18 @@ impl<M: PageMeta> Page<M> {
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The physical address must represent a valid page and the caller must already hold one
|
||||
/// reference count.
|
||||
/// The physical address must represent a valid page and the caller must ensure the corresponding
|
||||
/// virtual address points to an initialized metadata slot by holding a reference count priorly.
|
||||
pub(in crate::mm) unsafe fn inc_ref_count(paddr: Paddr) {
|
||||
let page = unsafe { ManuallyDrop::new(Self::from_raw(paddr)) };
|
||||
let _page = page.clone();
|
||||
debug_assert!(paddr % PAGE_SIZE == 0);
|
||||
debug_assert!(paddr < MAX_PADDR.load(Ordering::Relaxed) as Paddr);
|
||||
let vaddr: Vaddr = mapping::page_to_meta::<PagingConsts>(paddr);
|
||||
// SAFETY: The virtual address points to an initialized metadata slot. The caller can ensure
|
||||
// it is initialized by holding a reference count before calling this function, preventing
|
||||
// adding a reference count to an unused page.
|
||||
(*(vaddr as *const MetaSlot))
|
||||
.ref_count
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Get the physical address.
|
||||
@ -229,11 +236,18 @@ impl DynPage {
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The physical address must represent a valid page and the caller must already hold one
|
||||
/// reference count.
|
||||
/// The physical address must represent a valid page and the caller must ensure the corresponding
|
||||
/// virtual address points to an initialized metadata slot by holding a reference count priorly.
|
||||
pub(in crate::mm) unsafe fn inc_ref_count(paddr: Paddr) {
|
||||
let page = unsafe { ManuallyDrop::new(Self::from_raw(paddr)) };
|
||||
let _page = page.clone();
|
||||
debug_assert!(paddr % PAGE_SIZE == 0);
|
||||
debug_assert!(paddr < MAX_PADDR.load(Ordering::Relaxed) as Paddr);
|
||||
let vaddr: Vaddr = mapping::page_to_meta::<PagingConsts>(paddr);
|
||||
// SAFETY: The virtual address points to an initialized metadata slot. The caller can ensure
|
||||
// it is initialized by holding a reference count before calling this function, preventing
|
||||
// adding a reference count to an unused page.
|
||||
(*(vaddr as *const MetaSlot))
|
||||
.ref_count
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Get the physical address of the start of the page
|
||||
|
Reference in New Issue
Block a user