use std::fmt::Debug;
use std::os::raw::c_void;
use abi::{Attributes, Miscselect, Sigstruct};
use sgxs::SgxsRead;
pub trait Tcs: 'static + Debug + Send {
fn address(&self) -> *mut c_void;
}
pub trait MappingInfo: 'static + Debug {
fn address(&self) -> *mut c_void;
fn size(&self) -> usize;
}
pub struct Mapping<T: Load + ?Sized> {
pub info: T::MappingInfo,
pub tcss: Vec<T::Tcs>,
}
pub trait Load {
type MappingInfo: MappingInfo;
type Tcs: Tcs;
fn load<R: SgxsRead>(
&mut self,
reader: &mut R,
sigstruct: &Sigstruct,
attributes: Attributes,
miscselect: Miscselect,
) -> Result<Mapping<Self>, anyhow::Error>;
}
impl<T: Load> Load for &mut T {
type MappingInfo = T::MappingInfo;
type Tcs = T::Tcs;
fn load<R: SgxsRead>(
&mut self,
reader: &mut R,
sigstruct: &Sigstruct,
attributes: Attributes,
miscselect: Miscselect,
) -> Result<Mapping<Self>, anyhow::Error> {
T::load(self, reader, sigstruct, attributes, miscselect).map(|Mapping { info, tcss }| Mapping { info, tcss } )
}
}