pub fn load_cmdline(
    guest_mem: &GuestMemoryMmap,
    guest_addr: GuestAddress,
    cmdline: &CString,
) -> std::result::Result<(), CmdlineError> {
    let raw_cmdline = cmdline.as_bytes_with_nul();
    if raw_cmdline.len() <= 1 {
        return Ok(());
    }

    let cmdline_last_addr = guest_addr
        .checked_add(raw_cmdline.len() as u64 - 1)
        .ok_or(CmdlineError::CommandLineOverflow)?; // Extra for null termination.

    if cmdline_last_addr > guest_mem.last_addr() {
        return Err(CmdlineError::CommandLineOverflow);
    }

    guest_mem
        .write_slice(raw_cmdline, guest_addr)
        .map_err(|_| CmdlineError::CommandLineCopy)?;

    Ok(())
}
/// Writes the command line string to the given memory slice.
///
/// # Arguments
///
/// * `guest_mem` - A u8 slice that will be partially overwritten by the command line.
/// * `guest_addr` - The address in `guest_mem` at which to load the command line.
/// * `cmdline` - The kernel command line as CString.
Writes the command line string to the given memory slice.
Writes the command line string to the given memory slice .
pub fn load_cmdline(
    guest_mem: &GuestMemoryMmap,
    guest_addr: GuestAddress,
    cmdline: &CString,
) -> std::result::Result<(), CmdlineError> {
    let raw_cmdline = cmdline.as_bytes_with_nul();
    if raw_cmdline.len() <= 1 {
        return Ok(());
    }
    let cmdline_last_addr = guest_addr
        .checked_add(raw_cmdline.len() as u64 - 1)
        .ok_or(CmdlineError::CommandLineOverflow)?; // Extra for null termination.
    if cmdline_last_addr > guest_mem.last_addr() {
        return Err(CmdlineError::CommandLineOverflow);
    }
    guest_mem
        .write_slice(raw_cmdline, guest_addr)
        .map_err(|_| CmdlineError::CommandLineCopy)?;
    Ok(())
}
pub fn load_cmdline ( guest_mem : & GuestMemoryMmap , guest_addr : GuestAddress , cmdline : & CString , ) -> std :: result :: Result < ( ) , CmdlineError > { let raw_cmdline = cmdline . as_bytes_with_nul ( ) ; if raw_cmdline . len ( ) <= 1 { return Ok ( ( ) ) ; } let cmdline_last_addr = guest_addr . checked_add ( raw_cmdline . len ( ) as u64 - 1 ) . ok_or ( CmdlineError :: CommandLineOverflow ) ? ; // Extra for null termination. if cmdline_last_addr > guest_mem . last_addr ( ) { return Err ( CmdlineError :: CommandLineOverflow ) ; } guest_mem . write_slice ( raw_cmdline , guest_addr ) . map_err ( | _ | CmdlineError :: CommandLineCopy ) ? ; Ok ( ( ) ) }
Writes the command line string to the given memory slice.
Writes the command line string to the given memory slice .
guest_mem
&GuestMemoryMmap
guest_addr
GuestAddress
cmdline
&CString