add box enter

This commit is contained in:
Masato Imai
2024-10-21 02:02:24 +00:00
parent 748e2a9807
commit 5086fe0ae7
2 changed files with 25 additions and 0 deletions

View File

@ -12,3 +12,4 @@ name = "izoli"
path = "src/bin/izoli.rs" path = "src/bin/izoli.rs"
[dependencies] [dependencies]
nix = { version = "0.29.0", features = ["sched"] }

View File

@ -1 +1,25 @@
use nix::{
libc::SIGCHLD,
sched::{self, CloneCb, CloneFlags},
unistd::Pid,
};
const STACK_SIZE: usize = 8192;
pub struct IzoliBox {} pub struct IzoliBox {}
impl IzoliBox {
pub fn new() -> Self {
Self {}
}
pub fn enter(&self, callback: CloneCb<'_>) -> Result<Pid, nix::errno::Errno> {
let mut stack = [0u8; STACK_SIZE];
let flags = CloneFlags::CLONE_NEWNS
| CloneFlags::CLONE_NEWUTS
| CloneFlags::CLONE_NEWIPC
| CloneFlags::CLONE_NEWPID;
unsafe { sched::clone(callback, &mut stack, flags, Some(SIGCHLD)) }
}
}