pub fn read_into_slice(self, out: &mut [MaybeUninit<T>])
        -> Result<&mut [T], Error> {

        // Easy out if slice is empty.
        if out.is_empty() {
            // SAFETY: slice is empty
            unsafe {
                return Ok(MaybeUninit::slice_assume_init_mut(out));
            }
        }

        // Ensure pages can be accessed.
        let min_vaddr = self.0 as usize;
        let max_vaddr = self.0.wrapping_offset(out.len() as isize) as usize;

        assert!(max_vaddr >= min_vaddr);

        let min_vaddr_page = min_vaddr & !(PAGE_SIZE - 1);
        let max_vaddr_page = max_vaddr & !(PAGE_SIZE - 1);
        let expected_pages = (max_vaddr_page - min_vaddr_page) / PAGE_SIZE;

        let mut found_pages = 0;

        // SAFETY: we are only reading the pageset, this is always ok
        let pageset_ref = unsafe {
            current_pageset().expect("paging not initialized")
        };
        let pageset = pageset_ref.lock();

        // Walk pageset, ensure all mapped and accessible by user
        for page in pageset.from(min_vaddr_page).take(expected_pages) {
            if let Some((_, page_type)) = page {
                if page_type.is_user() {
                    found_pages += 1;
                } else {
                    return Err(Error::InaccessiblePage);
                }
            } else {
                return Err(Error::InaccessiblePage);
            }
        }

        if found_pages != expected_pages {
            return Err(Error::InaccessiblePage);
        }

        // Copy is safe now.
        unsafe {
            out.as_mut_ptr().cast::<T>().copy_from(self.0, out.len());
        }

        // Check each element
        for element in out.iter() {
            // SAFETY: bounds checked by iterator
            if !unsafe { UserSafe::is_user_safe(element.as_ptr()) } {
                return Err(Error::UnsafeData);
            }
        }

        // We had to hold the pageset lock until now to make sure it doesn't get
        // modified.
        drop(pageset);

        // All ok. Return the reference
        //
        // SAFETY: we initialized all of the elements and they're safe
        unsafe {
            Ok(MaybeUninit::slice_assume_init_mut(out))
        }
    }
/// Read a slice of user data safely.
///
/// Each page will be checked for user accessibility before reading from it.
///
/// Each object will be checked for validity (according to
/// [UserSafe::is_user_safe]) during the read operation.
///
/// The reference returned in the `Ok` case is guaranteed to have been
/// initialized, and is the same as the slice passed in `out`, just
/// appropriately assumed initialized. It is also safe to assume that the
/// `out` slice itself has been initialized if this function returns `Ok`.
///
/// If the function returns `Err`, the contents of the slice must be assumed
/// uninitialized.
Read a slice of user data safely.
Each page will be checked for user accessibility before reading from it.

Each object will be checked for validity (according to
[UserSafe::is_user_safe]) during the read operation.

The reference returned in the `Ok` case is guaranteed to have been
initialized, and is the same as the slice passed in `out`, just
appropriately assumed initialized. It is also safe to assume that the
`out` slice itself has been initialized if this function returns `Ok`.

If the function returns `Err`, the contents of the slice must be assumed
uninitialized.
Read a slice of user data safely . Each page will be checked for user accessibility before reading from it . Each object will be checked for validity ( according to [ UserSafe :: is_user_safe ] ) during the read operation . The reference returned in the ` Ok ` case is guaranteed to have been initialized and is the same as the slice passed in ` out ` just appropriately assumed initialized . It is also safe to assume that the ` out ` slice itself has been initialized if this function returns ` Ok ` . If the function returns ` Err ` the contents of the slice must be assumed uninitialized .
pub fn read_into_slice(self, out: &mut [MaybeUninit<T>])
        -> Result<&mut [T], Error> {
        // Easy out if slice is empty.
        if out.is_empty() {
            // SAFETY: slice is empty
            unsafe {
                return Ok(MaybeUninit::slice_assume_init_mut(out));
            }
        }
        // Ensure pages can be accessed.
        let min_vaddr = self.0 as usize;
        let max_vaddr = self.0.wrapping_offset(out.len() as isize) as usize;
        assert!(max_vaddr >= min_vaddr);
        let min_vaddr_page = min_vaddr & !(PAGE_SIZE - 1);
        let max_vaddr_page = max_vaddr & !(PAGE_SIZE - 1);
        let expected_pages = (max_vaddr_page - min_vaddr_page) / PAGE_SIZE;
        let mut found_pages = 0;
        // SAFETY: we are only reading the pageset, this is always ok
        let pageset_ref = unsafe {
            current_pageset().expect("paging not initialized")
        };
        let pageset = pageset_ref.lock();
        // Walk pageset, ensure all mapped and accessible by user
        for page in pageset.from(min_vaddr_page).take(expected_pages) {
            if let Some((_, page_type)) = page {
                if page_type.is_user() {
                    found_pages += 1;
                } else {
                    return Err(Error::InaccessiblePage);
                }
            } else {
                return Err(Error::InaccessiblePage);
            }
        }
        if found_pages != expected_pages {
            return Err(Error::InaccessiblePage);
        }
        // Copy is safe now.
        unsafe {
            out.as_mut_ptr().cast::<T>().copy_from(self.0, out.len());
        }
        // Check each element
        for element in out.iter() {
            // SAFETY: bounds checked by iterator
            if !unsafe { UserSafe::is_user_safe(element.as_ptr()) } {
                return Err(Error::UnsafeData);
            }
        }
        // We had to hold the pageset lock until now to make sure it doesn't get
        // modified.
        drop(pageset);
        // All ok. Return the reference
        //
        // SAFETY: we initialized all of the elements and they're safe
        unsafe {
            Ok(MaybeUninit::slice_assume_init_mut(out))
        }
    }
pub fn read_into_slice ( self , out : & mut [ MaybeUninit < T > ] ) -> Result < & mut [ T ] , Error > { // Easy out if slice is empty. if out . is_empty ( ) { // SAFETY: slice is empty unsafe { return Ok ( MaybeUninit :: slice_assume_init_mut ( out ) ) ; } } // Ensure pages can be accessed. let min_vaddr = self . 0 as usize ; let max_vaddr = self . 0 . wrapping_offset ( out . len ( ) as isize ) as usize ; assert ! ( max_vaddr min_vaddr ) ; let min_vaddr_page = min_vaddr & ! ( PAGE_SIZE - 1 ) ; let max_vaddr_page = max_vaddr & ! ( PAGE_SIZE - 1 ) ; let expected_pages = ( max_vaddr_page - min_vaddr_page ) / PAGE_SIZE ; let mut found_pages = 0 ; // SAFETY: we are only reading the pageset, this is always ok let pageset_ref = unsafe { current_pageset ( ) . expect ( " " ) } ; let pageset = pageset_ref . lock ( ) ; // Walk pageset, ensure all mapped and accessible by user for page in pageset . from ( min_vaddr_page ) . take ( expected_pages ) { if let Some ( ( _ , page_type ) ) = page { if page_type . is_user ( ) { found_pages += 1 ; } else { return Err ( Error :: InaccessiblePage ) ; } } else { return Err ( Error :: InaccessiblePage ) ; } } if found_pages != expected_pages { return Err ( Error :: InaccessiblePage ) ; } // Copy is safe now. unsafe { out . as_mut_ptr ( ) . cast :: < T > ( ) . copy_from ( self . 0 , out . len ( ) ) ; } // Check each element for element in out . iter ( ) { // SAFETY: bounds checked by iterator if ! unsafe { UserSafe :: is_user_safe ( element . as_ptr ( ) ) } { return Err ( Error :: UnsafeData ) ; } } // We had to hold the pageset lock until now to make sure it doesn't get // modified. drop ( pageset ) ; // All ok. Return the reference // // SAFETY: we initialized all of the elements and they're safe unsafe { Ok ( MaybeUninit :: slice_assume_init_mut ( out ) ) } }
Read a slice of user data safely.
Read a slice of user data safely .
self
out
&mut [MaybeUninit<T>]