import more code from enclaveos

This commit is contained in:
Ryan Heywood 2025-07-11 18:37:58 -04:00
parent fa87bd8088
commit b3fe5e23f4
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
3 changed files with 50 additions and 11 deletions

View File

@ -37,7 +37,7 @@ pub fn get_config() -> Result<Config> {
let platform = platform::get_current_platform(values.remove("platform").as_deref())?; let platform = platform::get_current_platform(values.remove("platform").as_deref())?;
let target = values.remove("target").unwrap(); let target = values.remove("target").unwrap_or(String::from("/bin/sh"));
Ok(Config { platform, mode, target }) Ok(Config { platform, mode, target })
} }

View File

@ -3,6 +3,7 @@ mod platform;
mod result; mod result;
mod system; mod system;
use platform::Platform;
use result::Result; use result::Result;
fn main() { fn main() {
@ -23,23 +24,48 @@ extern "C" fn handle_sigchld(_sig: i32) {
} }
} }
fn init() -> Result<()> { fn init_rootfs() {
let config = config::get_config()?; use libc::{MS_NOSUID, MS_NOEXEC, MS_NODEV };
let no_dse = MS_NODEV | MS_NOSUID | MS_NOEXEC;
for (filename, mode, fd) in [ let no_se = MS_NOSUID | MS_NOEXEC;
("/dev/console", "r", 0), let args = [
("/dev/console", "w", 1), ("devtmpfs", "/dev", "devtmpfs", no_se, "mode=0755"),
("/dev/console", "w", 2), ("devtmpfs", "/dev", "devtmpfs", no_se, "mode=0755"),
] { ("devpts", "/dev/pts", "devpts", no_se, ""),
system::syscall::freopen(filename, mode, &fd)?; ("shm", "/dev/shm", "tmpfs", no_dse, "mode=0755"),
("proc", "/proc", "proc", no_dse, "hidepid=2"),
("tmpfs", "/run", "tmpfs", no_dse, "mode=0755"),
("tmpfs", "/tmp", "tmpfs", no_dse, ""),
("sysfs", "/sys", "sysfs", no_dse, ""),
("cgroup_root", "/sys/fs/cgroup", "tmpfs", no_dse, "mode=0755"),
];
for (src, target, fstype, flags, data) in args {
match system::syscall::mount(src, target, fstype, flags, Some(data)) {
Ok(())=> eprintln!("Mounted {target}"),
Err(e)=> eprintln!("Bad mount: {e}"),
}
} }
}
fn init() -> Result<()> {
// let config = config::get_config()?;
init_rootfs();
init_console();
platform::aws::Aws.init().unwrap();
std::thread::sleep(std::time::Duration::from_secs(500));
/*
if let Some(platform) = config.platform.as_deref() { if let Some(platform) = config.platform.as_deref() {
platform::init(platform)?; platform::init(platform)?;
} else if let Some(platform) = platform::get_current_platform(None)?.as_deref() { } else if let Some(platform) = platform::get_current_platform(None)?.as_deref() {
platform::init(platform)?; platform::init(platform)?;
} }
*/
/*
let command = &config.target; let command = &config.target;
match config.mode { match config.mode {
config::Mode::Spawn => { config::Mode::Spawn => {
@ -59,6 +85,17 @@ fn init() -> Result<()> {
system::syscall::execv(command, &[])?; system::syscall::execv(command, &[])?;
} }
} }
*/
Ok(()) Ok(())
} }
fn init_console() -> Result<(), result::CtxError> {
Ok(for (filename, mode, fd) in [
("/dev/console", "r", 0),
("/dev/console", "w", 1),
("/dev/console", "w", 2),
] {
system::syscall::freopen(filename, mode, &fd)?;
})
}

View File

@ -59,7 +59,7 @@ fn init_modules(iter: impl IntoIterator<Item = (String, String)>) -> Result<()>
} }
#[cfg(feature = "aws")] #[cfg(feature = "aws")]
mod aws; pub mod aws;
pub fn get_current_platform(name: Option<&str>) -> Result<Option<Box<dyn Platform>>> { pub fn get_current_platform(name: Option<&str>) -> Result<Option<Box<dyn Platform>>> {
#[allow(clippy::collapsible_match)] #[allow(clippy::collapsible_match)]
@ -85,8 +85,10 @@ pub fn init(platform: &dyn Platform) -> Result<()> {
// NOTE: We need to make get_mounts _additional_ beyond a base set. // NOTE: We need to make get_mounts _additional_ beyond a base set.
// We need `/dev/nsm` to exist so Aws.is() works. // We need `/dev/nsm` to exist so Aws.is() works.
/*
platform.get_mounts().and_then(init_filesystems)?; platform.get_mounts().and_then(init_filesystems)?;
platform.get_modules().and_then(init_modules)?; platform.get_modules().and_then(init_modules)?;
*/
platform.init()?; platform.init()?;
Ok(()) Ok(())