more dmesg lines
This commit is contained in:
parent
f35a923dee
commit
1641e7b793
15
src/main.rs
15
src/main.rs
|
@ -5,13 +5,14 @@ mod system;
|
||||||
|
|
||||||
use platform::Platform;
|
use platform::Platform;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
use system::dmesg;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if let Err(e) = init() {
|
if let Err(e) = init() {
|
||||||
eprintln!("Error: {e}");
|
dmesg(format!("Error: {e}"));
|
||||||
let mut opt = Some(&e as &dyn std::error::Error);
|
let mut opt = Some(&e as &dyn std::error::Error);
|
||||||
while let Some(current_source) = opt {
|
while let Some(current_source) = opt {
|
||||||
eprintln!("Caused by: {current_source}");
|
dmesg(format!("Caused by: {current_source}"));
|
||||||
opt = current_source.source();
|
opt = current_source.source();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,12 +43,12 @@ fn init_rootfs() {
|
||||||
];
|
];
|
||||||
for (src, target, fstype, flags, data) in args {
|
for (src, target, fstype, flags, data) in args {
|
||||||
match system::syscall::mount(src, target, fstype, flags, Some(data)) {
|
match system::syscall::mount(src, target, fstype, flags, Some(data)) {
|
||||||
Ok(())=> eprintln!("Mounted {target}"),
|
Ok(())=> dmesg(format!("Mounted {target}")),
|
||||||
Err(e)=> {
|
Err(e)=> {
|
||||||
eprintln!("Error: {e}");
|
dmesg(format!("Error: {e}"));
|
||||||
let mut opt = Some(&e as &dyn std::error::Error);
|
let mut opt = Some(&e as &dyn std::error::Error);
|
||||||
while let Some(current_source) = opt {
|
while let Some(current_source) = opt {
|
||||||
eprintln!("Caused by: {current_source}");
|
dmesg(format!("Caused by: {current_source}"));
|
||||||
opt = current_source.source();
|
opt = current_source.source();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -61,10 +62,10 @@ fn init() -> Result<()> {
|
||||||
// init_rootfs();
|
// init_rootfs();
|
||||||
if let Err(errors) = system::mount_default_targets() {
|
if let Err(errors) = system::mount_default_targets() {
|
||||||
for error in errors {
|
for error in errors {
|
||||||
eprintln!("Error while mounting: {error}");
|
dmesg(format!("Error while mounting: {error}"));
|
||||||
let mut opt = Some(&error as &dyn std::error::Error);
|
let mut opt = Some(&error as &dyn std::error::Error);
|
||||||
while let Some(current_source) = opt {
|
while let Some(current_source) = opt {
|
||||||
eprintln!("Caused by: {current_source}");
|
dmesg(format!("Caused by: {current_source}"));
|
||||||
opt = current_source.source();
|
opt = current_source.source();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use crate::result::{Context, Result};
|
use crate::{
|
||||||
|
result::{Context, Result},
|
||||||
|
system::dmesg,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct Aws;
|
pub struct Aws;
|
||||||
|
|
||||||
|
@ -70,8 +73,10 @@ impl super::Platform for Aws {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod enclaveos_shim {
|
mod enclaveos_shim {
|
||||||
|
use super::dmesg;
|
||||||
|
|
||||||
mod system {
|
mod system {
|
||||||
|
use super::dmesg;
|
||||||
use std::os::fd::AsRawFd;
|
use std::os::fd::AsRawFd;
|
||||||
|
|
||||||
pub fn insmod(path: &str) {
|
pub fn insmod(path: &str) {
|
||||||
|
@ -79,15 +84,11 @@ mod enclaveos_shim {
|
||||||
let file = std::fs::File::open(path).unwrap();
|
let file = std::fs::File::open(path).unwrap();
|
||||||
let fd = file.as_raw_fd();
|
let fd = file.as_raw_fd();
|
||||||
if unsafe { syscall(SYS_finit_module, fd, &[0u8; 1], 0) } < 0 {
|
if unsafe { syscall(SYS_finit_module, fd, &[0u8; 1], 0) } < 0 {
|
||||||
eprintln!("bad insert kernel module: {path}");
|
dmesg(format!("bad insert kernel module: {path}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn socket_connect(
|
pub fn socket_connect(family: libc::c_int, port: u32, cid: u32) -> libc::c_int {
|
||||||
family: libc::c_int,
|
use libc::{connect, sockaddr, sockaddr_vm, socket, SOCK_STREAM};
|
||||||
port: u32,
|
|
||||||
cid: u32,
|
|
||||||
) -> libc::c_int {
|
|
||||||
use libc::{connect, socket, sockaddr, sockaddr_vm, SOCK_STREAM};
|
|
||||||
let fd = unsafe { socket(family, SOCK_STREAM, 0) };
|
let fd = unsafe { socket(family, SOCK_STREAM, 0) };
|
||||||
if unsafe {
|
if unsafe {
|
||||||
let mut sa: sockaddr_vm = std::mem::zeroed();
|
let mut sa: sockaddr_vm = std::mem::zeroed();
|
||||||
|
@ -99,7 +100,8 @@ mod enclaveos_shim {
|
||||||
&sa as *const _ as *mut sockaddr,
|
&sa as *const _ as *mut sockaddr,
|
||||||
size_of::<sockaddr_vm>() as _,
|
size_of::<sockaddr_vm>() as _,
|
||||||
)
|
)
|
||||||
} < 0 {
|
} < 0
|
||||||
|
{
|
||||||
panic!("yikes")
|
panic!("yikes")
|
||||||
} else {
|
} else {
|
||||||
fd
|
fd
|
||||||
|
@ -117,8 +119,8 @@ mod enclaveos_shim {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nitro_heartbeat() {
|
fn nitro_heartbeat() {
|
||||||
|
use libc::{close, read, write, AF_VSOCK};
|
||||||
use system::socket_connect;
|
use system::socket_connect;
|
||||||
use libc::{write, read, close, AF_VSOCK};
|
|
||||||
let mut buf: [u8; 1] = [0; 1];
|
let mut buf: [u8; 1] = [0; 1];
|
||||||
buf[0] = 0xB7; // AWS Nitro heartbeat value
|
buf[0] = 0xB7; // AWS Nitro heartbeat value
|
||||||
let fd = socket_connect(AF_VSOCK, 9000, 3);
|
let fd = socket_connect(AF_VSOCK, 9000, 3);
|
||||||
|
@ -127,6 +129,6 @@ mod enclaveos_shim {
|
||||||
read(fd, buf.as_ptr() as _, 1);
|
read(fd, buf.as_ptr() as _, 1);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
eprintln!("Sent NSM heartbeat");
|
dmesg("Sent NSM heartbeat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue