fn safe_lookup<T>(ptr: *const T) -> Option<usize> {

    if super::initialized() {
        unsafe {
            super::kernel_pageset().lookup(ptr as usize)
        }
    } else {
        let map_start = KERNEL_OFFSET + KERNEL_LOW_START as usize;
        let map_end   = KERNEL_OFFSET + KERNEL_LOW_END as usize;
        let vaddr     = ptr as usize;

        if vaddr >= map_start && vaddr < map_end {
            Some(vaddr - KERNEL_OFFSET)
        } else {
            None
        }
    }
}
/// This is the only safe way to get the physical address of a kernel pointer
/// during paging operations.
///
/// It's not safe outside of paging operations however, because it assumes that
/// if paging is not initialized yet then the initial identity mapping is in
/// place, and `kernel_pageset_unsafe()` is used so that we can still do lookups
/// while modifying the kernel pageset. This in itself is technically unsafe,
/// but there's really no other option within this module.
This is the only safe way to get the physical address of a kernel pointer
during paging operations.

It's not safe outside of paging operations however, because it assumes that
if paging is not initialized yet then the initial identity mapping is in
place, and `kernel_pageset_unsafe()` is used so that we can still do lookups
while modifying the kernel pageset. This in itself is technically unsafe,
but there's really no other option within this module.
This is the only safe way to get the physical address of a kernel pointer during paging operations . It ' s not safe outside of paging operations however because it assumes that if paging is not initialized yet then the initial identity mapping is in place and ` kernel_pageset_unsafe () ` is used so that we can still do lookups while modifying the kernel pageset . This in itself is technically unsafe but there ' s really no other option within this module .
fn safe_lookup<T>(ptr: *const T) -> Option<usize> {
    if super::initialized() {
        unsafe {
            super::kernel_pageset().lookup(ptr as usize)
        }
    } else {
        let map_start = KERNEL_OFFSET + KERNEL_LOW_START as usize;
        let map_end   = KERNEL_OFFSET + KERNEL_LOW_END as usize;
        let vaddr     = ptr as usize;
        if vaddr >= map_start && vaddr < map_end {
            Some(vaddr - KERNEL_OFFSET)
        } else {
            None
        }
    }
}
fn safe_lookup < T > ( ptr : * const T ) -> Option < usize > { if super :: initialized ( ) { unsafe { super :: kernel_pageset ( ) . lookup ( ptr as usize ) } } else { let map_start = KERNEL_OFFSET + KERNEL_LOW_START as usize ; let map_end = KERNEL_OFFSET + KERNEL_LOW_END as usize ; let vaddr = ptr as usize ; if vaddr >= map_start && vaddr < map_end { Some ( vaddr - KERNEL_OFFSET ) } else { None } } }
This is the only safe way to get the physical address of a kernel pointer
during paging operations.
This is the only safe way to get the physical address of a kernel pointer during paging operations .
ptr
*const T