fn kernel_acquire_and_map<F>(
    vaddr: *mut u8,
    pages: PageCount,
    mut push_region: F,
) -> Result<(), PageCount>
    where F: FnMut(AcquiredMappedRegion) {

    trace!("kernel_acquire_and_map({:?}, {})", vaddr, pages);

    let mut cur_vaddr = vaddr as usize;
    let mut cur_pages = pages;

    while cur_pages > 0 {
        let (got_paddr, got_pages) =
            match acquire_region(RegionUser::Kernel, cur_pages) {
                Some(x) => x,
                None => return Err(pages - cur_pages)
            };

        unsafe {
            kernel_pageset()
                .map_pages_with_type(
                    cur_vaddr,
                    (got_paddr..).step_by(PAGE_SIZE).take(got_pages),
                    PageType::default().writable(),
                )
                .expect("unable to map acquired pages into kernel space")
        }

        push_region(AcquiredMappedRegion {
            vaddr: cur_vaddr as *mut u8,
            paddr: got_paddr,
            pages: got_pages
        });

        cur_vaddr += got_pages * PAGE_SIZE;
        cur_pages -= got_pages;
    }

    Ok(())
}
/// Returns the number of pages successfully allocated on error
Returns the number of pages successfully allocated on error
Returns the number of pages successfully allocated on error
fn kernel_acquire_and_map<F>(
    vaddr: *mut u8,
    pages: PageCount,
    mut push_region: F,
) -> Result<(), PageCount>
    where F: FnMut(AcquiredMappedRegion) {
    trace!("kernel_acquire_and_map({:?}, {})", vaddr, pages);
    let mut cur_vaddr = vaddr as usize;
    let mut cur_pages = pages;
    while cur_pages > 0 {
        let (got_paddr, got_pages) =
            match acquire_region(RegionUser::Kernel, cur_pages) {
                Some(x) => x,
                None => return Err(pages - cur_pages)
            };
        unsafe {
            kernel_pageset()
                .map_pages_with_type(
                    cur_vaddr,
                    (got_paddr..).step_by(PAGE_SIZE).take(got_pages),
                    PageType::default().writable(),
                )
                .expect("unable to map acquired pages into kernel space")
        }
        push_region(AcquiredMappedRegion {
            vaddr: cur_vaddr as *mut u8,
            paddr: got_paddr,
            pages: got_pages
        });
        cur_vaddr += got_pages * PAGE_SIZE;
        cur_pages -= got_pages;
    }
    Ok(())
}
fn kernel_acquire_and_map < F > ( vaddr : * mut u8 , pages : PageCount , mut push_region : F , ) -> Result < ( ) , PageCount > where F : FnMut ( AcquiredMappedRegion ) { trace ! ( " " vaddr pages ) ; let mut cur_vaddr = vaddr as usize ; let mut cur_pages = pages ; while cur_pages > 0 { let ( got_paddr , got_pages ) = match acquire_region ( RegionUser :: Kernel , cur_pages ) { Some ( x ) => x , None => return Err ( pages - cur_pages ) } ; unsafe { kernel_pageset ( ) . map_pages_with_type ( cur_vaddr , ( got_paddr .. ) . step_by ( PAGE_SIZE ) . take ( got_pages ) , PageType :: default ( ) . writable ( ) , ) . expect ( " " ) } push_region ( AcquiredMappedRegion { vaddr : cur_vaddr as * mut u8 , paddr : got_paddr , pages : got_pages } ) ; cur_vaddr += got_pages * PAGE_SIZE ; cur_pages -= got_pages ; } Ok ( ( ) ) }
Returns the number of pages successfully allocated on error
Returns the number of pages successfully allocated on error
vaddr
*mut u8
pages
PageCount
push_region
F