fn load<F, M: GuestMemory>(
        guest_mem: &M,
        kernel_start: Option<GuestAddress>,
        kernel_image: &mut F,
        _highmem_start_address: Option<GuestAddress>,
    ) -> Result<KernelLoaderResult>
    where
        F: Read + Seek,
    {
        let kernel_size = kernel_image
            .seek(SeekFrom::End(0))
            .map_err(|_| Error::SeekImageEnd)? as usize;
        let mut arm64_header: arm64_image_header = Default::default();
        kernel_image
            .seek(SeekFrom::Start(0))
            .map_err(|_| Error::SeekImageHeader)?;

        arm64_header
            .as_bytes()
            .read_from(0, kernel_image, mem::size_of::<arm64_image_header>())
            .map_err(|_| Error::ReadImageHeader)?;

        if u32::from_le(arm64_header.magic) != 0x644d_5241 {
            return Err(Error::InvalidImageMagicNumber.into());
        }

        let image_size = u64::from_le(arm64_header.image_size);
        let mut text_offset = u64::from_le(arm64_header.text_offset);

        if image_size == 0 {
            text_offset = 0x80000;
        }

        let mem_offset = kernel_start
            .unwrap_or(GuestAddress(0))
            .checked_add(text_offset)
            .ok_or(Error::InvalidImage)?;

        let mut loader_result: KernelLoaderResult = Default::default();
        loader_result.kernel_load = mem_offset;

        kernel_image
            .seek(SeekFrom::Start(0))
            .map_err(|_| Error::SeekImageHeader)?;
        guest_mem
            .read_exact_from(mem_offset, kernel_image, kernel_size)
            .map_err(|_| Error::ReadKernelImage)?;

        loader_result.kernel_end = mem_offset
            .raw_value()
            .checked_add(kernel_size as GuestUsize)
            .ok_or(KernelLoaderError::MemoryOverflow)?;

        Ok(loader_result)
    }
/// Loads a PE Image into guest memory.
///
/// # Arguments
///
/// * `guest_mem` - The guest memory where the kernel image is loaded.
/// * `kernel_start` - The offset into 'guest_mem' at which to load the kernel.
/// * `kernel_image` - Input Image format kernel image.
/// * `highmem_start_address` - ignored on ARM64.
///
/// # Returns
/// * KernelLoaderResult
Loads a PE Image into guest memory.
Loads a PE Image into guest memory .
fn load<F, M: GuestMemory>(
        guest_mem: &M,
        kernel_start: Option<GuestAddress>,
        kernel_image: &mut F,
        _highmem_start_address: Option<GuestAddress>,
    ) -> Result<KernelLoaderResult>
    where
        F: Read + Seek,
    {
        let kernel_size = kernel_image
            .seek(SeekFrom::End(0))
            .map_err(|_| Error::SeekImageEnd)? as usize;
        let mut arm64_header: arm64_image_header = Default::default();
        kernel_image
            .seek(SeekFrom::Start(0))
            .map_err(|_| Error::SeekImageHeader)?;
        arm64_header
            .as_bytes()
            .read_from(0, kernel_image, mem::size_of::<arm64_image_header>())
            .map_err(|_| Error::ReadImageHeader)?;
        if u32::from_le(arm64_header.magic) != 0x644d_5241 {
            return Err(Error::InvalidImageMagicNumber.into());
        }
        let image_size = u64::from_le(arm64_header.image_size);
        let mut text_offset = u64::from_le(arm64_header.text_offset);
        if image_size == 0 {
            text_offset = 0x80000;
        }
        let mem_offset = kernel_start
            .unwrap_or(GuestAddress(0))
            .checked_add(text_offset)
            .ok_or(Error::InvalidImage)?;
        let mut loader_result: KernelLoaderResult = Default::default();
        loader_result.kernel_load = mem_offset;
        kernel_image
            .seek(SeekFrom::Start(0))
            .map_err(|_| Error::SeekImageHeader)?;
        guest_mem
            .read_exact_from(mem_offset, kernel_image, kernel_size)
            .map_err(|_| Error::ReadKernelImage)?;
        loader_result.kernel_end = mem_offset
            .raw_value()
            .checked_add(kernel_size as GuestUsize)
            .ok_or(KernelLoaderError::MemoryOverflow)?;
        Ok(loader_result)
    }
fn load < F , M : GuestMemory > ( guest_mem : & M , kernel_start : Option < GuestAddress > , kernel_image : & mut F , _highmem_start_address : Option < GuestAddress > , ) -> Result < KernelLoaderResult > where F : Read + Seek , { let kernel_size = kernel_image . seek ( SeekFrom :: End ( 0 ) ) . map_err ( | _ | Error :: SeekImageEnd ) ? as usize ; let mut arm64_header : arm64_image_header = Default :: default ( ) ; kernel_image . seek ( SeekFrom :: Start ( 0 ) ) . map_err ( | _ | Error :: SeekImageHeader ) ? ; arm64_header . as_bytes ( ) . read_from ( 0 , kernel_image , mem :: size_of :: < arm64_image_header > ( ) ) . map_err ( | _ | Error :: ReadImageHeader ) ? ; if u32 :: from_le ( arm64_header . magic ) != 0x644d_5241 { return Err ( Error :: InvalidImageMagicNumber . into ( ) ) ; } let image_size = u64 :: from_le ( arm64_header . image_size ) ; let mut text_offset = u64 :: from_le ( arm64_header . text_offset ) ; if image_size == 0 { text_offset = 0x80000 ; } let mem_offset = kernel_start . unwrap_or ( GuestAddress ( 0 ) ) . checked_add ( text_offset ) . ok_or ( Error :: InvalidImage ) ? ; let mut loader_result : KernelLoaderResult = Default :: default ( ) ; loader_result . kernel_load = mem_offset ; kernel_image . seek ( SeekFrom :: Start ( 0 ) ) . map_err ( | _ | Error :: SeekImageHeader ) ? ; guest_mem . read_exact_from ( mem_offset , kernel_image , kernel_size ) . map_err ( | _ | Error :: ReadKernelImage ) ? ; loader_result . kernel_end = mem_offset . raw_value ( ) . checked_add ( kernel_size as GuestUsize ) . ok_or ( KernelLoaderError :: MemoryOverflow ) ? ; Ok ( loader_result ) }
Loads a PE Image into guest memory.
Loads a PE Image into guest memory .
guest_mem
&M
kernel_start
Option<GuestAddress>
kernel_image
&mut F
_highmem_start_address
Option<GuestAddress>
None
guest_mem
&M
kernel_start
Option<GuestAddress>
kernel_image
&mut F
_highmem_start_address
Option<GuestAddress>