//! Static native executable admission before acquiring any image resources. use super::{elf_loader::{Headers,Error as HeaderError},elf_segments::{Plan,Error as SegmentError}}; #[derive(Clone,Copy,Debug,PartialEq,Eq)]pub enum Error{Header(HeaderError),UnsupportedInterpreter,UnsupportedDynamicLink,Segments(SegmentError)} #[derive(Clone,Copy,Debug,PartialEq,Eq)]pub struct Static<'a>{plan:Plan<'a>} impl<'a>Static<'a>{ pub fn parse(file:&'a[u8])->Result{ let headers=Headers::parse(file).map_err(Error::Header)?; for i in 0..headers.count(){let program=headers.program(i).expect("bounded program header"); if program.kind==3{return Err(Error::UnsupportedInterpreter);} if program.kind==2{return Err(Error::UnsupportedDynamicLink);} } Ok(Self{plan:Plan::parse(file).map_err(Error::Segments)?}) } pub fn plan(&self)->Plan<'a>{self.plan} } #[derive(Debug,PartialEq,Eq)]pub enum PrepareError{Image(Error),Resource(E)} pub fn prepare<'a,T,E>(file:&'a[u8],acquire:impl FnOnce(Plan<'a>)->Result)->Result>{ let image=Static::parse(file).map_err(PrepareError::Image)?;acquire(image.plan).map_err(PrepareError::Resource) }