use std::marker::PhantomData;
use iocuddle::*;
use sgx::page::{SecInfo, Secs};
use sgx::signature::Signature;
const SGX: Group = Group::new(0xA4);
pub const ENCLAVE_CREATE: Ioctl<Write, &Create> = unsafe { SGX.write(0x00) };
pub const ENCLAVE_ADD_PAGES: Ioctl<WriteRead, &AddPages> = unsafe { SGX.write_read(0x01) };
pub const ENCLAVE_INIT: Ioctl<Write, &Init> = unsafe { SGX.write(0x02) };
#[repr(C)]
#[derive(Debug)]
pub struct Create<'a>(u64, PhantomData<&'a ()>);
impl<'a> Create<'a> {
pub fn new(secs: &'a Secs) -> Self {
Create(secs as *const _ as _, PhantomData)
}
}
#[repr(C)]
#[derive(Debug)]
pub struct AddPages<'a> {
src: u64,
offset: u64,
length: u64,
secinfo: u64,
flags: u64,
count: u64,
phantom: PhantomData<&'a ()>,
}
impl<'a> AddPages<'a> {
pub fn new(bytes: &'a [u8], offset: usize, secinfo: &'a SecInfo, measure: bool) -> Self {
const MEASURE: u64 = 1 << 0;
let flags = match measure {
true => MEASURE,
false => 0,
};
Self {
src: bytes.as_ptr() as _,
offset: offset as _,
length: bytes.len() as _,
secinfo: secinfo as *const _ as _,
flags,
count: 0,
phantom: PhantomData,
}
}
#[allow(dead_code)]
pub fn count(&self) -> u64 {
self.count
}
}
#[repr(C)]
#[derive(Debug)]
pub struct Init<'a>(u64, PhantomData<&'a ()>);
impl<'a> Init<'a> {
pub fn new(sig: &'a Signature) -> Self {
Init(sig as *const _ as _, PhantomData)
}
}
#[repr(C)]
#[derive(Debug)]
#[allow(dead_code)]
pub struct SetAttribute<'a>(u64, PhantomData<&'a ()>);
impl<'a> SetAttribute<'a> {
#[allow(dead_code)]
pub fn new(fd: &'a impl std::os::unix::io::AsRawFd) -> Self {
SetAttribute(fd.as_raw_fd() as _, PhantomData)
}
}