import more code from enclaveos
This commit is contained in:
parent
fa87bd8088
commit
b3fe5e23f4
|
@ -37,7 +37,7 @@ pub fn get_config() -> Result<Config> {
|
|||
|
||||
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 })
|
||||
}
|
||||
|
|
55
src/main.rs
55
src/main.rs
|
@ -3,6 +3,7 @@ mod platform;
|
|||
mod result;
|
||||
mod system;
|
||||
|
||||
use platform::Platform;
|
||||
use result::Result;
|
||||
|
||||
fn main() {
|
||||
|
@ -23,23 +24,48 @@ extern "C" fn handle_sigchld(_sig: i32) {
|
|||
}
|
||||
}
|
||||
|
||||
fn init() -> Result<()> {
|
||||
let config = config::get_config()?;
|
||||
|
||||
for (filename, mode, fd) in [
|
||||
("/dev/console", "r", 0),
|
||||
("/dev/console", "w", 1),
|
||||
("/dev/console", "w", 2),
|
||||
] {
|
||||
system::syscall::freopen(filename, mode, &fd)?;
|
||||
fn init_rootfs() {
|
||||
use libc::{MS_NOSUID, MS_NOEXEC, MS_NODEV };
|
||||
let no_dse = MS_NODEV | MS_NOSUID | MS_NOEXEC;
|
||||
let no_se = MS_NOSUID | MS_NOEXEC;
|
||||
let args = [
|
||||
("devtmpfs", "/dev", "devtmpfs", no_se, "mode=0755"),
|
||||
("devtmpfs", "/dev", "devtmpfs", no_se, "mode=0755"),
|
||||
("devpts", "/dev/pts", "devpts", no_se, ""),
|
||||
("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() {
|
||||
platform::init(platform)?;
|
||||
} else if let Some(platform) = platform::get_current_platform(None)?.as_deref() {
|
||||
platform::init(platform)?;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
let command = &config.target;
|
||||
match config.mode {
|
||||
config::Mode::Spawn => {
|
||||
|
@ -59,6 +85,17 @@ fn init() -> Result<()> {
|
|||
system::syscall::execv(command, &[])?;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
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)?;
|
||||
})
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ fn init_modules(iter: impl IntoIterator<Item = (String, String)>) -> Result<()>
|
|||
}
|
||||
|
||||
#[cfg(feature = "aws")]
|
||||
mod aws;
|
||||
pub mod aws;
|
||||
|
||||
pub fn get_current_platform(name: Option<&str>) -> Result<Option<Box<dyn Platform>>> {
|
||||
#[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.
|
||||
// We need `/dev/nsm` to exist so Aws.is() works.
|
||||
/*
|
||||
platform.get_mounts().and_then(init_filesystems)?;
|
||||
platform.get_modules().and_then(init_modules)?;
|
||||
*/
|
||||
platform.init()?;
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue