1use std::fmt::Debug;
8use std::os::raw::c_void;
9
10use abi::{Attributes, Miscselect, Sigstruct};
11use sgxs::SgxsRead;
12
13pub trait Tcs: 'static + Debug + Send {
16 fn address(&self) -> *mut c_void;
18}
19
20pub trait MappingInfo: 'static + Debug {
22 fn address(&self) -> *mut c_void;
24
25 fn size(&self) -> usize;
27}
28
29pub struct Mapping<T: Load + ?Sized> {
30 pub info: T::MappingInfo,
31 pub tcss: Vec<T::Tcs>,
32}
33
34pub trait Load {
36 type MappingInfo: MappingInfo;
37 type Tcs: Tcs;
38
39 fn load<R: SgxsRead>(
43 &mut self,
44 reader: &mut R,
45 sigstruct: &Sigstruct,
46 attributes: Attributes,
47 miscselect: Miscselect,
48 ) -> Result<Mapping<Self>, anyhow::Error>;
49}
50
51impl<T: Load> Load for &mut T {
52 type MappingInfo = T::MappingInfo;
53 type Tcs = T::Tcs;
54
55 fn load<R: SgxsRead>(
59 &mut self,
60 reader: &mut R,
61 sigstruct: &Sigstruct,
62 attributes: Attributes,
63 miscselect: Miscselect,
64 ) -> Result<Mapping<Self>, anyhow::Error> {
65 T::load(self, reader, sigstruct, attributes, miscselect).map(|Mapping { info, tcss }| Mapping { info, tcss } )
66 }
67}