Improve safe comment
This commit is contained in:
parent
a0ec687315
commit
92680ea25d
|
|
@ -123,15 +123,16 @@ impl<M: PageMeta> Page<M> {
|
|||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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.
|
||||
/// The physical address must represent a valid page.
|
||||
///
|
||||
/// And the caller must ensure the metadata slot pointed through the corresponding
|
||||
/// virtual address is initialized by holding a reference count of the page firstly.
|
||||
/// Otherwise the function may add a reference count to an unused page.
|
||||
pub(in crate::mm) unsafe fn inc_ref_count(paddr: Paddr) {
|
||||
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.
|
||||
// SAFETY: The virtual address points to an initialized metadata slot.
|
||||
(*(vaddr as *const MetaSlot))
|
||||
.ref_count
|
||||
.fetch_add(1, Ordering::Relaxed);
|
||||
|
|
@ -236,15 +237,11 @@ impl DynPage {
|
|||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// 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.
|
||||
/// This is the same as [`Page::inc_ref_count`].
|
||||
pub(in crate::mm) unsafe fn inc_ref_count(paddr: Paddr) {
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue