// Frees the memory used by the given pages.
// Precondition:
// - each page is mapped as shared and writable.
Frees the memory used by the given pages.
Precondition:
each page is mapped as shared and writable.
Frees the memory used by the given pages . Precondition : each page is mapped as shared and writable .
fn free_pages(mut pages: Vec<PagePtr>) {
    if pages.is_empty() {
        return;
    }
    // Sort the pages to find contiguous page ranges.
    pages.sort_unstable();
    // The start and end of the current contiguous page range.
    let mut start_ptr = pages[0].0;
    // SAFETY: the page is valid.
    let mut end_ptr = unsafe { start_ptr.add(PAGE_SIZE) };
    for page_ptr in pages.into_iter() {
        if page_ptr.0 == end_ptr {
            // Extend the current page range.
            // SAFETY: the page is valid.
            end_ptr = unsafe { end_ptr.add(PAGE_SIZE) };
        } else {
            // Free the current page range and a start a new one.
            // SAFETY: the range consists of pages that mapped as shared and writable.
            unsafe { madvise_remove(start_ptr, end_ptr) }
            start_ptr = page_ptr.0;
            // SAFETY: the page is valid.
            end_ptr = unsafe { start_ptr.add(PAGE_SIZE) };
        }
    }
    // Free the last page range.
    // SAFETY: the range consists of pages that mapped as shared and writable.
    unsafe { madvise_remove(start_ptr, end_ptr) }
}
fn free_pages ( mut pages : Vec < PagePtr > ) { if pages . is_empty ( ) { return ; } // Sort the pages to find contiguous page ranges. pages . sort_unstable ( ) ; // The start and end of the current contiguous page range. let mut start_ptr = pages [ 0 ] . 0 ; // SAFETY: the page is valid. let mut end_ptr = unsafe { start_ptr . add ( PAGE_SIZE ) } ; for page_ptr in pages . into_iter ( ) { if page_ptr . 0 == end_ptr { // Extend the current page range. // SAFETY: the page is valid. end_ptr = unsafe { end_ptr . add ( PAGE_SIZE ) } ; } else { // Free the current page range and a start a new one. // SAFETY: the range consists of pages that mapped as shared and writable. unsafe { madvise_remove ( start_ptr , end_ptr ) } start_ptr = page_ptr . 0 ; // SAFETY: the page is valid. end_ptr = unsafe { start_ptr . add ( PAGE_SIZE ) } ; } } // Free the last page range. // SAFETY: the range consists of pages that mapped as shared and writable. unsafe { madvise_remove ( start_ptr , end_ptr ) } }
Frees the memory used by the given pages.
Frees the memory used by the given pages .
pages
Vec<PagePtr>