add enclaveos shim to test something
This commit is contained in:
parent
861da29edf
commit
61a8ff9537
|
@ -63,7 +63,51 @@ impl super::Platform for Aws {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(&self) -> Result<()> {
|
fn init(&self) -> Result<()> {
|
||||||
Self::init_heartbeat()?;
|
// Self::init_heartbeat()?;
|
||||||
|
enclaveos_shim::nitro_heartbeat();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod enclaveos_shim {
|
||||||
|
|
||||||
|
mod system {
|
||||||
|
pub fn socket_connect(
|
||||||
|
family: libc::c_int,
|
||||||
|
port: u32,
|
||||||
|
cid: u32,
|
||||||
|
) -> libc::c_int {
|
||||||
|
use libc::{connect, socket, sockaddr, sockaddr_vm, SOCK_STREAM};
|
||||||
|
let fd = unsafe { socket(family, SOCK_STREAM, 0) };
|
||||||
|
if unsafe {
|
||||||
|
let mut sa: sockaddr_vm = std::mem::zeroed();
|
||||||
|
sa.svm_family = family as _;
|
||||||
|
sa.svm_port = port;
|
||||||
|
sa.svm_cid = cid;
|
||||||
|
connect(
|
||||||
|
fd,
|
||||||
|
&sa as *const _ as *mut sockaddr,
|
||||||
|
size_of::<sockaddr_vm>() as _,
|
||||||
|
)
|
||||||
|
} < 0 {
|
||||||
|
panic!("yikes")
|
||||||
|
} else {
|
||||||
|
fd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn nitro_heartbeat() {
|
||||||
|
use system::socket_connect;
|
||||||
|
use libc::{write, read, close, AF_VSOCK};
|
||||||
|
let mut buf: [u8; 1] = [0; 1];
|
||||||
|
buf[0] = 0xB7; // AWS Nitro heartbeat value
|
||||||
|
let fd = socket_connect(AF_VSOCK, 9000, 3);
|
||||||
|
unsafe {
|
||||||
|
write(fd, buf.as_ptr() as _, 1);
|
||||||
|
read(fd, buf.as_ptr() as _, 1);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
eprintln!("Sent NSM heartbeat");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue