use super::error::*;
use bitflags::bitflags;
use std::time::Duration;
#[derive(Debug)]
pub enum ImageType<'a> {
Eif(&'a [u8]),
}
#[derive(Debug)]
pub struct MemoryInfo<'a> {
pub image_type: ImageType<'a>,
pub size_mib: usize,
}
impl<'a> MemoryInfo<'a> {
pub fn new(image_type: ImageType<'a>, size_mib: usize) -> Self {
Self {
image_type,
size_mib,
}
}
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Default)]
pub struct StartFlags: u64 {
const DEBUG = 1;
}
}
pub struct PollTimeout(pub Duration);
impl TryFrom<(&[u8], usize)> for PollTimeout {
type Error = LaunchError;
fn try_from(args: (&[u8], usize)) -> Result<Self, Self::Error> {
let mul = 60 * 1000; let size = args.0.len();
let file: u64 = ((1 + (size - 1) / (6 << 30)) as u64).saturating_mul(mul);
let alloc: u64 = ((1 + (args.1 - 1) / (100 << 30)) as u64).saturating_mul(mul);
Ok(Self(Duration::from_millis(file + alloc)))
}
}
impl PollTimeout {
pub fn duration(&self) -> Duration {
self.0
}
}