diff --git a/src/interface/errnos.rs b/src/interface/errnos.rs index 067f5f0..0385a77 100644 --- a/src/interface/errnos.rs +++ b/src/interface/errnos.rs @@ -1,5 +1,4 @@ #![allow(dead_code)] -// Error handling for SafePOSIX use crate::interface; use std::sync::OnceLock; diff --git a/src/interface/file.rs b/src/interface/file.rs index bebe6b8..1a3b8b3 100644 --- a/src/interface/file.rs +++ b/src/interface/file.rs @@ -1,6 +1,3 @@ -// // Author: Nicholas Renner -// // - use parking_lot::Mutex; use std::fs::{self, canonicalize, File, OpenOptions}; use std::sync::Arc; diff --git a/src/interface/misc.rs b/src/interface/misc.rs index 88bef74..2476b23 100644 --- a/src/interface/misc.rs +++ b/src/interface/misc.rs @@ -1,5 +1,3 @@ -// Author: Nicholas Renner -// // Misc functions for interface // Random, locks, etc. #![allow(dead_code)] diff --git a/src/interface/mod.rs b/src/interface/mod.rs index 7bf2ff1..e8c7353 100644 --- a/src/interface/mod.rs +++ b/src/interface/mod.rs @@ -1,8 +1,3 @@ -// Author: Nicholas Renner -// -// Module definitions for the SafePOSIX Rust interface -// this interface limits kernel access from Rust to the popular paths as defined in Lock-in-Pop - mod comm; pub mod errnos; mod file; diff --git a/src/interface/timer.rs b/src/interface/timer.rs index 28e94fe..397dda6 100644 --- a/src/interface/timer.rs +++ b/src/interface/timer.rs @@ -1,5 +1,3 @@ -// Author: Nicholas Renner -// // Timer functions for Rust interface. #![allow(dead_code)] diff --git a/src/safeposix/cage.rs b/src/safeposix/cage.rs index 946b8e3..2243a6a 100644 --- a/src/safeposix/cage.rs +++ b/src/safeposix/cage.rs @@ -2,80 +2,23 @@ use crate::interface; //going to get the datatypes and errnos from the cage file from now on pub use crate::interface::errnos::{syscall_error, Errno}; -// pub use crate::interface::types::{ -// Arg, EpollEvent, FSData, IoctlPtrUnion, PipeArray, PollStruct, Rlimit, ShmidsStruct, StatData, -// }; pub use crate::interface::types::{ EpollEvent, IoctlPtrUnion, PipeArray, PollStruct, }; use super::filesystem::normpath; -// use super::net::SocketHandle; pub use super::syscalls::fs_constants::*; pub use super::syscalls::net_constants::*; pub use super::syscalls::sys_constants::*; pub use crate::interface::CAGE_TABLE; -// #[derive(Debug, Clone)] -// pub enum FileDescriptor { -// File(FileDesc), -// Stream(StreamDesc), -// Socket(SocketDesc), -// Pipe(PipeDesc), -// Epoll(EpollDesc), -// } - -// #[derive(Debug, Clone)] -// pub struct FileDesc { -// pub position: usize, -// pub inode: usize, -// pub flags: i32, -// pub advlock: interface::RustRfc, -// } - -// #[derive(Debug, Clone)] -// pub struct StreamDesc { -// pub position: usize, -// pub stream: i32, //0 for stdin, 1 for stdout, 2 for stderr -// pub flags: i32, -// pub advlock: interface::RustRfc, -// } - -// #[derive(Debug, Clone)] -// pub struct SocketDesc { -// pub flags: i32, -// pub domain: i32, -// pub rawfd: i32, -// pub handle: interface::RustRfc>, -// pub advlock: interface::RustRfc, -// } - -// #[derive(Debug, Clone)] -// pub struct PipeDesc { -// pub pipe: interface::RustRfc, -// pub flags: i32, -// pub advlock: interface::RustRfc, -// } - -// #[derive(Debug, Clone)] -// pub struct EpollDesc { -// pub mode: i32, -// pub registered_fds: interface::RustHashMap, -// pub advlock: interface::RustRfc, -// pub errno: i32, -// pub flags: i32, -// } - -// pub type FdTable = Vec>>>; - #[derive(Debug)] pub struct Cage { pub cageid: u64, pub cwd: interface::RustLock>, pub parent: u64, - // pub filedescriptortable: FdTable, pub cancelstatus: interface::RustAtomicBool, pub getgid: interface::RustAtomicI32, pub getuid: interface::RustAtomicI32, @@ -94,38 +37,6 @@ pub struct Cage { } impl Cage { - // pub fn get_next_fd( - // &self, - // startfd: Option, - // ) -> ( - // i32, - // Option>>, - // ) { - // let start = match startfd { - // Some(startfd) => startfd, - // None => STARTINGFD, - // }; - - // // let's get the next available fd number. The standard says we need to return the lowest open fd number. - // for fd in start..MAXFD { - // let fdguard = self.filedescriptortable[fd as usize].try_write(); - // if let Some(ref fdopt) = fdguard { - // // we grab the lock here and if there is no occupied cage, we return the fdno and guard while keeping the fd slot locked - // if fdopt.is_none() { - // return (fd, fdguard); - // } - // } - // } - // return ( - // syscall_error( - // Errno::ENFILE, - // "get_next_fd", - // "no available file descriptor number could be found", - // ), - // None, - // ); - // } - pub fn changedir(&self, newdir: interface::RustPathBuf) { let newwd = interface::RustRfc::new(normpath(newdir, self)); let mut cwdbox = self.cwd.write(); @@ -151,62 +62,4 @@ impl Cage { } } } - - // pub fn get_filedescriptor( - // &self, - // fd: i32, - // ) -> Result>>, ()> { - // if (fd < 0) || (fd >= MAXFD) { - // Err(()) - // } else { - // Ok(self.filedescriptortable[fd as usize].clone()) - // } - // } } - -// pub fn init_fdtable() -> FdTable { -// let mut fdtable = Vec::new(); -// // load lower handle stubs -// let stdin = interface::RustRfc::new(interface::RustLock::new(Some(FileDescriptor::Stream( -// StreamDesc { -// position: 0, -// stream: 0, -// flags: O_RDONLY, -// advlock: interface::RustRfc::new(interface::AdvisoryLock::new()), -// }, -// )))); -// let stdout = interface::RustRfc::new(interface::RustLock::new(Some(FileDescriptor::Stream( -// StreamDesc { -// position: 0, -// stream: 1, -// flags: O_WRONLY, -// advlock: interface::RustRfc::new(interface::AdvisoryLock::new()), -// }, -// )))); -// let stderr = interface::RustRfc::new(interface::RustLock::new(Some(FileDescriptor::Stream( -// StreamDesc { -// position: 0, -// stream: 2, -// flags: O_WRONLY, -// advlock: interface::RustRfc::new(interface::AdvisoryLock::new()), -// }, -// )))); -// fdtable.push(stdin); -// fdtable.push(stdout); -// fdtable.push(stderr); - -// for _fd in 3..MAXFD as usize { -// fdtable.push(interface::RustRfc::new(interface::RustLock::new(None))); -// } -// fdtable -// } - -// pub fn create_unix_sockpipes() -> ( -// interface::RustRfc, -// interface::RustRfc, -// ) { -// let pipe1 = interface::RustRfc::new(interface::new_pipe(UDSOCK_CAPACITY)); -// let pipe2 = interface::RustRfc::new(interface::new_pipe(UDSOCK_CAPACITY)); - -// (pipe1, pipe2) -// } diff --git a/src/safeposix/dispatcher.rs b/src/safeposix/dispatcher.rs index e581e03..814a240 100644 --- a/src/safeposix/dispatcher.rs +++ b/src/safeposix/dispatcher.rs @@ -143,9 +143,6 @@ macro_rules! get_onearg { }; } -// the following "quick" functions are implemented for research purposes -// to increase I/O performance by bypassing the dispatcher and type checker - #[no_mangle] pub extern "C" fn rustposix_thread_init(cageid: u64, signalflag: u64) { let cage = interface::cagetable_getref(cageid); @@ -925,9 +922,6 @@ pub fn lind_syscall_api( GETSOCKNAME_SYSCALL => { let fd = arg1 as i32; - // let addrlen = arg3 as u32; - // let mut addr = interface::get_sockaddr(start_address + arg2), addrlen).unwrap(); - let mut addr = interface::GenSockaddr::V4(interface::SockaddrV4::default()); //value doesn't matter if interface::arg_nullity(arg2) || interface::arg_nullity(arg3) { @@ -1127,7 +1121,6 @@ pub fn lindrustinit(verbosity: isize) { cageid: 1, cwd: interface::RustLock::new(interface::RustRfc::new(interface::RustPathBuf::from("/"))), parent: 1, - // filedescriptortable: init_fdtable(), cancelstatus: interface::RustAtomicBool::new(false), getgid: interface::RustAtomicI32::new(-1), getuid: interface::RustAtomicI32::new(-1), diff --git a/src/safeposix/filesystem.rs b/src/safeposix/filesystem.rs index 67d1e04..1356ddf 100644 --- a/src/safeposix/filesystem.rs +++ b/src/safeposix/filesystem.rs @@ -1,547 +1,12 @@ // Filesystem metadata struct #![allow(dead_code)] -// use super::net::NET_METADATA; // use super::syscalls::fs_constants::*; // use super::syscalls::sys_constants::*; use crate::interface; use super::cage::Cage; -// pub const METADATAFILENAME: &str = "lind.metadata"; - -// pub const LOGFILENAME: &str = "lind.md.log"; - -// pub static LOGMAP: interface::RustLazyGlobal< -// interface::RustRfc>>, -// > = interface::RustLazyGlobal::new(|| interface::RustRfc::new(interface::RustLock::new(None))); - -// pub static FS_METADATA: interface::RustLazyGlobal> = -// interface::RustLazyGlobal::new(|| { -// interface::RustRfc::new(FilesystemMetadata::init_fs_metadata()) -// }); //we want to check if fs exists before doing a blank init, but not for now - -// type FileObjectTable = interface::RustHashMap; -// pub static FILEOBJECTTABLE: interface::RustLazyGlobal = -// interface::RustLazyGlobal::new(|| interface::RustHashMap::new()); - -// #[derive(interface::SerdeSerialize, interface::SerdeDeserialize, Debug)] -// pub enum Inode { -// File(GenericInode), -// CharDev(DeviceInode), -// Socket(SocketInode), -// Dir(DirectoryInode), -// } - -// #[derive(interface::SerdeSerialize, interface::SerdeDeserialize, Debug)] -// pub struct GenericInode { -// pub size: usize, -// pub uid: u32, -// pub gid: u32, -// pub mode: u32, -// pub linkcount: u32, -// #[serde(skip)] -// //skips serializing and deserializing field, will populate with u32 default of 0 (refcount should not be persisted) -// pub refcount: u32, -// pub atime: u64, -// pub ctime: u64, -// pub mtime: u64, -// } - -// #[derive(interface::SerdeSerialize, interface::SerdeDeserialize, Debug)] -// pub struct DeviceInode { -// pub size: usize, -// pub uid: u32, -// pub gid: u32, -// pub mode: u32, -// pub linkcount: u32, -// #[serde(skip)] -// //skips serializing and deserializing field, will populate with u32 default of 0 (refcount should not be persisted) -// pub refcount: u32, -// pub atime: u64, -// pub ctime: u64, -// pub mtime: u64, -// pub dev: DevNo, -// } - -// #[derive(interface::SerdeSerialize, interface::SerdeDeserialize, Debug)] -// pub struct SocketInode { -// pub size: usize, -// pub uid: u32, -// pub gid: u32, -// pub mode: u32, -// pub linkcount: u32, -// #[serde(skip)] -// pub refcount: u32, -// pub atime: u64, -// pub ctime: u64, -// pub mtime: u64, -// } - -// #[derive(interface::SerdeSerialize, interface::SerdeDeserialize, Debug)] -// pub struct DirectoryInode { -// pub size: usize, -// pub uid: u32, -// pub gid: u32, -// pub mode: u32, -// pub linkcount: u32, -// #[serde(skip)] -// //skips serializing and deserializing field, will populate with u32 default of 0 (refcount should not be persisted) -// pub refcount: u32, -// pub atime: u64, -// pub ctime: u64, -// pub mtime: u64, -// pub filename_to_inode_dict: interface::RustHashMap, -// } - -// #[derive(interface::SerdeSerialize, interface::SerdeDeserialize, Debug)] -// pub struct FilesystemMetadata { -// pub nextinode: interface::RustAtomicUsize, -// pub dev_id: u64, -// pub inodetable: interface::RustHashMap, -// } - -// pub fn init_filename_to_inode_dict( -// curinode: usize, -// parentinode: usize, -// ) -> interface::RustHashMap { -// let retval = interface::RustHashMap::new(); -// retval.insert(".".to_string(), curinode); -// retval.insert("..".to_string(), parentinode); -// retval -// } - -// impl FilesystemMetadata { -// pub fn blank_fs_init() -> FilesystemMetadata { -// //remove open files? -// let retval = FilesystemMetadata { -// nextinode: interface::RustAtomicUsize::new(STREAMINODE + 1), -// dev_id: 20, -// inodetable: interface::RustHashMap::new(), -// }; -// let time = interface::timestamp(); //We do a real timestamp now -// let dirinode = DirectoryInode { -// size: 0, -// uid: DEFAULT_UID, -// gid: DEFAULT_GID, -// //linkcount is how many entries the directory has (as per linux kernel), . and .. making 2 for the root directory initially, -// //plus one to make sure it can never be removed (can be thought of as mount point link) -// //refcount is how many open file descriptors pointing to the directory exist, 0 as no cages exist yet -// mode: S_IFDIR as u32 | S_IRWXA, -// linkcount: 3, -// refcount: 0, -// atime: time, -// ctime: time, -// mtime: time, -// filename_to_inode_dict: init_filename_to_inode_dict( -// ROOTDIRECTORYINODE, -// ROOTDIRECTORYINODE, -// ), -// }; -// retval -// .inodetable -// .insert(ROOTDIRECTORYINODE, Inode::Dir(dirinode)); - -// retval -// } - -// // Read file, and deserialize CBOR to FS METADATA -// pub fn init_fs_metadata() -> FilesystemMetadata { -// // Read CBOR from file -// if interface::pathexists(METADATAFILENAME.to_string()) { -// let metadata_fileobj = interface::openmetadata(METADATAFILENAME.to_string()).unwrap(); -// let metadatabytes = metadata_fileobj.readfile_to_new_bytes().unwrap(); -// metadata_fileobj.close().unwrap(); - -// // Restore metadata -// interface::serde_deserialize_from_bytes(&metadatabytes).unwrap() -// } else { -// FilesystemMetadata::blank_fs_init() -// } -// } -// } - -// pub fn format_fs() { -// let newmetadata = FilesystemMetadata::blank_fs_init(); -// //Because we keep the metadata as a synclazy, it is not possible to completely wipe it and -// //reinstate something over it in-place. Thus we create a new file system, wipe the old one, and -// //then persist our new one. In order to create the new one, because the FS_METADATA does not -// //point to the same metadata that we are trying to create, we need to manually insert these -// //rather than using system calls. - -// let mut rootinode = newmetadata.inodetable.get_mut(&1).unwrap(); //get root to populate its dict -// if let Inode::Dir(ref mut rootdir) = *rootinode { -// rootdir.filename_to_inode_dict.insert("dev".to_string(), 2); -// rootdir.linkcount += 1; -// } else { -// unreachable!(); -// } -// drop(rootinode); - -// let devchildren = interface::RustHashMap::new(); -// devchildren.insert("..".to_string(), 1); -// devchildren.insert(".".to_string(), 2); -// devchildren.insert("null".to_string(), 3); -// devchildren.insert("zero".to_string(), 4); -// devchildren.insert("urandom".to_string(), 5); -// devchildren.insert("random".to_string(), 6); - -// let tmpchildren = interface::RustHashMap::new(); -// tmpchildren.insert("..".to_string(), 1); -// tmpchildren.insert(".".to_string(), 2); - -// let time = interface::timestamp(); //We do a real timestamp now -// let devdirinode = Inode::Dir(DirectoryInode { -// size: 0, -// uid: DEFAULT_UID, -// gid: DEFAULT_GID, -// mode: (S_IFDIR | 0o755) as u32, -// linkcount: 3 + 4, //3 for ., .., and the parent dir, 4 is one for each child we will create -// refcount: 0, -// atime: time, -// ctime: time, -// mtime: time, -// filename_to_inode_dict: devchildren, -// }); //inode 2 -// let nullinode = Inode::CharDev(DeviceInode { -// size: 0, -// uid: DEFAULT_UID, -// gid: DEFAULT_UID, -// mode: (S_IFCHR | 0o666) as u32, -// linkcount: 1, -// refcount: 0, -// atime: time, -// ctime: time, -// mtime: time, -// dev: DevNo { major: 1, minor: 3 }, -// }); //inode 3 -// let zeroinode = Inode::CharDev(DeviceInode { -// size: 0, -// uid: DEFAULT_UID, -// gid: DEFAULT_UID, -// mode: (S_IFCHR | 0o666) as u32, -// linkcount: 1, -// refcount: 0, -// atime: time, -// ctime: time, -// mtime: time, -// dev: DevNo { major: 1, minor: 5 }, -// }); //inode 4 -// let urandominode = Inode::CharDev(DeviceInode { -// size: 0, -// uid: DEFAULT_UID, -// gid: DEFAULT_UID, -// mode: (S_IFCHR | 0o666) as u32, -// linkcount: 1, -// refcount: 0, -// atime: time, -// ctime: time, -// mtime: time, -// dev: DevNo { major: 1, minor: 9 }, -// }); //inode 5 -// let randominode = Inode::CharDev(DeviceInode { -// size: 0, -// uid: DEFAULT_UID, -// gid: DEFAULT_UID, -// mode: (S_IFCHR | 0o666) as u32, -// linkcount: 1, -// refcount: 0, -// atime: time, -// ctime: time, -// mtime: time, -// dev: DevNo { major: 1, minor: 8 }, -// }); //inode 6 -// let tmpdirinode = Inode::Dir(DirectoryInode { -// size: 0, -// uid: DEFAULT_UID, -// gid: DEFAULT_GID, -// mode: (S_IFDIR | 0o755) as u32, -// linkcount: 3 + 4, -// refcount: 0, -// atime: time, -// ctime: time, -// mtime: time, -// filename_to_inode_dict: tmpchildren, -// }); //inode 7 -// newmetadata -// .nextinode -// .store(8, interface::RustAtomicOrdering::Relaxed); -// newmetadata.inodetable.insert(2, devdirinode); -// newmetadata.inodetable.insert(3, nullinode); -// newmetadata.inodetable.insert(4, zeroinode); -// newmetadata.inodetable.insert(5, urandominode); -// newmetadata.inodetable.insert(6, randominode); -// newmetadata.inodetable.insert(7, tmpdirinode); - -// let _logremove = interface::removefile(LOGFILENAME.to_string()); - -// persist_metadata(&newmetadata); -// } - -// pub fn load_fs() { -// // If the metadata file exists, just close the file for later restore -// // If it doesn't, lets create a new one, load special files, and persist it. -// if interface::pathexists(METADATAFILENAME.to_string()) { -// let metadata_fileobj = interface::openmetadata(METADATAFILENAME.to_string()).unwrap(); -// metadata_fileobj.close().unwrap(); - -// // if we have a log file at this point, we need to sync it with the existing metadata -// if interface::pathexists(LOGFILENAME.to_string()) { -// let log_fileobj = interface::openmetadata(LOGFILENAME.to_string()).unwrap(); -// // read log file and parse count -// let mut logread = log_fileobj.readfile_to_new_bytes().unwrap(); -// let logsize = interface::convert_bytes_to_size(&logread[0..interface::COUNTMAPSIZE]); - -// // create vec of log file bounded by indefinite encoding bytes (0x9F, 0xFF) -// let mut logbytes: Vec = Vec::new(); -// logbytes.push(0x9F); -// logbytes.extend_from_slice( -// &mut logread[interface::COUNTMAPSIZE..(interface::COUNTMAPSIZE + logsize)], -// ); -// logbytes.push(0xFF); -// let mut logvec: Vec<(usize, Option)> = -// interface::serde_deserialize_from_bytes(&logbytes).unwrap(); - -// // drain the vector and deserialize into pairs of inodenum + inodes, -// // if the inode exists, add it, if not, remove it -// // keep track of the largest inodenum we see so we can update the nextinode counter -// let mut max_inodenum = FS_METADATA -// .nextinode -// .load(interface::RustAtomicOrdering::Relaxed); -// for serialpair in logvec.drain(..) { -// let (inodenum, inode) = serialpair; -// match inode { -// Some(inode) => { -// max_inodenum = interface::rust_max(max_inodenum, inodenum); -// FS_METADATA.inodetable.insert(inodenum, inode); -// } -// None => { -// FS_METADATA.inodetable.remove(&inodenum); -// } -// } -// } - -// // update the nextinode counter to avoid collisions -// FS_METADATA -// .nextinode -// .store(max_inodenum + 1, interface::RustAtomicOrdering::Relaxed); - -// let _logclose = log_fileobj.close(); -// let _logremove = interface::removefile(LOGFILENAME.to_string()); - -// // clean up broken links -// fsck(); -// } -// } else { -// if interface::pathexists(LOGFILENAME.to_string()) { -// println!("Filesystem in very corrupted state: log existed but metadata did not!"); -// } -// format_fs(); -// } - -// // then recreate the log -// create_log(); -// } - -// pub fn fsck() { -// FS_METADATA.inodetable.retain(|_inodenum, inode_obj| { -// match inode_obj { -// Inode::File(ref mut normalfile_inode) => normalfile_inode.linkcount != 0, -// Inode::Dir(ref mut dir_inode) => { -// //2 because . and .. always contribute to the linkcount of a directory -// dir_inode.linkcount > 2 -// } -// Inode::CharDev(ref mut char_inodej) => char_inodej.linkcount != 0, -// Inode::Socket(_) => false, -// } -// }); -// } - -// pub fn create_log() { -// // reinstantiate the log file and assign it to the metadata struct -// let log_mapobj = interface::mapfilenew(LOGFILENAME.to_string()).unwrap(); -// let mut logobj = LOGMAP.write(); -// logobj.replace(log_mapobj); -// } - -// // Serialize New Metadata to CBOR, write to logfile -// pub fn log_metadata(metadata: &FilesystemMetadata, inodenum: usize) { -// let serialpair: (usize, Option<&Inode>); -// let entrybytes; - -// // pack and serialize log entry -// if let Some(inode) = metadata.inodetable.get(&inodenum) { -// serialpair = (inodenum, Some(&*inode)); -// entrybytes = interface::serde_serialize_to_bytes(&serialpair).unwrap(); -// } else { -// serialpair = (inodenum, None); -// entrybytes = interface::serde_serialize_to_bytes(&serialpair).unwrap(); -// } - -// // write to file -// let mut mapopt = LOGMAP.write(); -// let map = mapopt.as_mut().unwrap(); -// map.write_to_map(&entrybytes).unwrap(); -// } - -// // Serialize Metadata Struct to CBOR, write to file -// pub fn persist_metadata(metadata: &FilesystemMetadata) { -// // Serialize metadata to string -// let metadatabytes = interface::serde_serialize_to_bytes(&metadata).unwrap(); - -// // remove file if it exists, assigning it to nothing to avoid the compiler yelling about unused result -// let _ = interface::removefile(METADATAFILENAME.to_string()); - -// // write to file -// let mut metadata_fileobj = interface::openmetadata(METADATAFILENAME.to_string()).unwrap(); -// metadata_fileobj -// .writefile_from_bytes(&metadatabytes) -// .unwrap(); -// metadata_fileobj.close().unwrap(); -// } - -pub fn convpath(cpath: &str) -> interface::RustPathBuf { - interface::RustPathBuf::from(cpath) -} - -// /// This function resolves the absolute path of a directory from its inode number in a filesystem. -// /// Here's how it operates: -// /// -// /// - Starts from the given inode and fetches its associated metadata from the filesystem's inode table. -// /// -// /// - Verifies that the inode represents a directory. -// /// -// /// - Attempts to find the parent directory by looking for the ".." entry in the current directory's entries. -// /// -// /// - Retrieves the directory name associated with the current inode using the `filenamefrominode` function and prepends it to the `path_string`. -// /// -// /// - Continues this process recursively, updating the current inode to the parent inode, and accumulating directory names in the `path_string`. -// /// -// /// - Stops when it reaches the root directory, where it prepends a "/" to the `path_string` and returns the complete path. -// /// -// /// This function effectively constructs the absolute path by backtracking the parent directories. However, if any issues arise during this process, such as missing metadata or inability to find the parent directory, it returns `None`. -// pub fn pathnamefrominodenum(inodenum: usize) -> Option { -// let mut path_string = String::new(); -// let mut first_iteration = true; -// let mut current_inodenum = inodenum; - -// loop { -// let mut thisinode = match FS_METADATA.inodetable.get_mut(¤t_inodenum) { -// Some(inode) => inode, -// None => { -// return None; -// } -// }; - -// match *thisinode { -// Inode::Dir(ref mut dir_inode) => { -// // We try to get the parent directory inode. -// if let Some(parent_dir_inode) = dir_inode.filename_to_inode_dict.get("..") { -// // If the parent node is 1 (indicating the root directory) and this is not the first iteration, this indicates that we have arrived at the root directory. Here we add a '/' to the beginning of the path string and return it. -// if *parent_dir_inode == (1 as usize) { -// if !first_iteration { -// path_string.insert(0, '/'); -// return Some(path_string); -// } -// first_iteration = false; -// } - -// match filenamefrominode(*parent_dir_inode, current_inodenum) { -// Some(filename) => { -// path_string = filename + "/" + &path_string; -// current_inodenum = *parent_dir_inode; -// } -// None => return None, -// }; -// } else { -// return None; -// } -// } -// _ => { -// return None; -// } -// } -// } -// } - -// // Find the file by the given inode number in the given directory -// pub fn filenamefrominode(dir_inode_no: usize, target_inode: usize) -> Option { -// let cur_node = Some(FS_METADATA.inodetable.get(&dir_inode_no).unwrap()); - -// match &*cur_node.unwrap() { -// Inode::Dir(d) => { -// let mut target_variable_name: Option = None; - -// for entry in d.filename_to_inode_dict.iter() { -// if entry.value() == &target_inode { -// target_variable_name = Some(entry.key().to_owned()); -// break; -// } -// } -// return target_variable_name; -// } -// _ => return None, -// } -// } - -// //returns tuple consisting of inode number of file (if it exists), and inode number of parent (if it exists) -// pub fn metawalkandparent(path: &interface::RustPath) -> (Option, Option) { -// let mut curnode = Some(FS_METADATA.inodetable.get(&ROOTDIRECTORYINODE).unwrap()); -// let mut inodeno = Some(ROOTDIRECTORYINODE); -// let mut previnodeno = None; - -// //Iterate over the components of the pathbuf in order to walk the file tree -// for comp in path.components() { -// match comp { -// //We've already done what initialization needs to be done -// interface::RustPathComponent::RootDir => {} - -// interface::RustPathComponent::Normal(f) => { -// //If we're trying to get the child of a nonexistent directory, exit out -// if inodeno.is_none() { -// return (None, None); -// } -// match &*curnode.unwrap() { -// Inode::Dir(d) => { -// previnodeno = inodeno; - -// //populate child inode number from parent directory's inode dict -// inodeno = match d -// .filename_to_inode_dict -// .get(&f.to_str().unwrap().to_string()) -// { -// Some(num) => { -// curnode = FS_METADATA.inodetable.get(&num); -// Some(*num) -// } - -// //if no such child exists, update curnode, inodeno accordingly so that -// //we can check against none as we do at the beginning of the Normal match arm -// None => { -// curnode = None; -// None -// } -// } -// } -// //if we're trying to get a child of a non-directory inode, exit out -// _ => { -// return (None, None); -// } -// } -// } - -// //If it's a component of the pathbuf that we don't expect given a normed path, exit out -// _ => { -// return (None, None); -// } -// } -// } -// //return inode number and it's parent's number -// (inodeno, previnodeno) -// } -// pub fn metawalk(path: &interface::RustPath) -> Option { -// metawalkandparent(path).0 -// } pub fn normpath(origp: interface::RustPathBuf, cage: &Cage) -> interface::RustPathBuf { //If path is relative, prefix it with the current working directory, otherwise populate it with rootdir let mut newp = if origp.is_relative() { @@ -568,52 +33,3 @@ pub fn normpath(origp: interface::RustPathBuf, cage: &Cage) -> interface::RustPa } newp } - -// pub fn remove_domain_sock(truepath: interface::RustPathBuf) { -// match metawalkandparent(truepath.as_path()) { -// //If the file does not exist -// (None, ..) => { -// panic!("path does not exist") -// } -// //If the file exists but has no parent, it's the root directory -// (Some(_), None) => { -// panic!("cannot unlink root directory") -// } - -// //If both the file and the parent directory exists -// (Some(inodenum), Some(parentinodenum)) => { -// Cage::remove_from_parent_dir(parentinodenum, &truepath); - -// FS_METADATA.inodetable.remove(&inodenum); -// NET_METADATA.domsock_paths.remove(&truepath); -// } -// } -// } - -// pub fn incref_root() { -// if let Inode::Dir(ref mut rootdir_dirinode_obj) = -// *(FS_METADATA.inodetable.get_mut(&ROOTDIRECTORYINODE).unwrap()) -// { -// rootdir_dirinode_obj.refcount += 1; -// } else { -// panic!("Root directory inode was not a directory"); -// } -// } - -// pub fn decref_dir(cwd_container: &interface::RustPathBuf) { -// if let Some(cwdinodenum) = metawalk(&cwd_container) { -// if let Inode::Dir(ref mut cwddir) = *(FS_METADATA.inodetable.get_mut(&cwdinodenum).unwrap()) -// { -// cwddir.refcount -= 1; - -// //if the directory has been removed but this cwd was the last open handle to it -// if cwddir.refcount == 0 && cwddir.linkcount == 0 { -// FS_METADATA.inodetable.remove(&cwdinodenum); -// } -// } else { -// panic!("Cage had a cwd that was not a directory!"); -// } -// } else { -// panic!("Cage had a cwd which did not exist!"); -// } //we probably want to handle this case, maybe cwd should be an inode number?? Not urgent -// } diff --git a/src/safeposix/mod.rs b/src/safeposix/mod.rs index 6f648bc..9957c39 100644 --- a/src/safeposix/mod.rs +++ b/src/safeposix/mod.rs @@ -1,6 +1,5 @@ pub mod cage; pub mod dispatcher; pub mod filesystem; -pub mod net; pub mod shm; pub mod syscalls; diff --git a/src/safeposix/net.rs b/src/safeposix/net.rs deleted file mode 100644 index 2fbf980..0000000 --- a/src/safeposix/net.rs +++ /dev/null @@ -1,564 +0,0 @@ -// use super::cage::{Cage, FileDescriptor}; -// use super::syscalls::net_constants::*; -// use crate::interface; -// use crate::interface::errnos::{syscall_error, Errno}; - -// //Because other processes on the OS may allocate ephemeral ports, we allocate them from high to -// //low whereas the OS allocates them from low to high -// //Additionally, we can't tell whether a port is truly rebindable, this is because even when a port -// //is closed sometimes there still is cleanup that the OS needs to do (for ephemeral ports which end -// //up in the TIME_WAIT state). Therefore, we will assign ephemeral ports rather than simply from the -// //highest available one, in a cyclic fashion skipping over unavailable ports. While this still may -// //cause issues if specific port adresses in the ephemeral port range are allocated and closed before -// //an ephemeral port would be bound there, it is much less likely that this will happen and is easy -// //to avoid and nonstandard in user programs. See the code for _get_available_udp_port and its tcp -// //counterpart for the implementation details. -// const EPHEMERAL_PORT_RANGE_START: u16 = 32768; //sane default on linux -// const EPHEMERAL_PORT_RANGE_END: u16 = 60999; -// pub const TCPPORT: bool = true; -// pub const UDPPORT: bool = false; - -// pub static NET_METADATA: interface::RustLazyGlobal> = -// interface::RustLazyGlobal::new(|| { -// interface::RustRfc::new(NetMetadata { -// used_port_set: interface::RustHashMap::new(), -// next_ephemeral_port_tcpv4: interface::RustRfc::new(interface::RustLock::new( -// EPHEMERAL_PORT_RANGE_END, -// )), -// next_ephemeral_port_udpv4: interface::RustRfc::new(interface::RustLock::new( -// EPHEMERAL_PORT_RANGE_END, -// )), -// next_ephemeral_port_tcpv6: interface::RustRfc::new(interface::RustLock::new( -// EPHEMERAL_PORT_RANGE_END, -// )), -// next_ephemeral_port_udpv6: interface::RustRfc::new(interface::RustLock::new( -// EPHEMERAL_PORT_RANGE_END, -// )), -// listening_port_set: interface::RustHashSet::new(), -// pending_conn_table: interface::RustHashMap::new(), -// domsock_accept_table: interface::RustHashMap::new(), // manages domain socket connection process -// domsock_paths: interface::RustHashSet::new(), // set of all currently bound domain sockets -// }) -// }); //we want to check if fs exists before doing a blank init, but not for now - -// //A list of all network devices present on the machine -// //It is populated from a file that should be present prior to running rustposix, see -// //the implementation of read_netdevs for specifics -// pub static NET_IFADDRS_STR: interface::RustLazyGlobal = -// interface::RustLazyGlobal::new(|| interface::getifaddrs_from_file()); - -// pub static NET_DEVICE_IPLIST: interface::RustLazyGlobal> = -// interface::RustLazyGlobal::new(|| ips_from_ifaddrs()); - -// fn ips_from_ifaddrs() -> Vec { -// let mut ips = vec![]; -// for net_device in NET_IFADDRS_STR.as_str().split('\n') { -// if net_device == "" { -// continue; -// } -// let ifaddrstr: Vec<&str> = net_device.split(' ').collect(); -// let genipopt = interface::GenIpaddr::from_string(ifaddrstr[2]); -// ips.push(genipopt.expect("Could not parse device ip address from net_devices file")); -// } - -// let genipopt0 = interface::GenIpaddr::from_string("0.0.0.0"); -// ips.push(genipopt0.expect("Could not parse device ip address from net_devices file")); -// return ips; -// } - -// #[derive(Debug, Hash, Eq, PartialEq, Clone)] -// pub enum PortType { -// IPv4UDP, -// IPv4TCP, -// IPv6UDP, -// IPv6TCP, -// } - -// pub fn mux_port( -// addr: interface::GenIpaddr, -// port: u16, -// domain: i32, -// istcp: bool, -// ) -> (interface::GenIpaddr, u16, PortType) { -// match domain { -// PF_INET => ( -// addr, -// port, -// if istcp { -// PortType::IPv4TCP -// } else { -// PortType::IPv4UDP -// }, -// ), -// PF_INET6 => ( -// addr, -// port, -// if istcp { -// PortType::IPv6TCP -// } else { -// PortType::IPv6UDP -// }, -// ), -// _ => panic!("How did you manage to set an unsupported domain on the socket?"), -// } -// } - -// //A substructure for information only populated in a unix domain socket -// #[derive(Debug)] -// pub struct UnixSocketInfo { -// pub mode: i32, -// pub sendpipe: Option>, -// pub receivepipe: Option>, -// pub inode: usize, -// } - -// //This structure contains all socket-associated data that is not held in the fd -// #[derive(Debug)] -// pub struct SocketHandle { -// pub innersocket: Option, -// pub socket_options: i32, -// pub tcp_options: i32, -// pub state: ConnState, -// pub protocol: i32, -// pub domain: i32, -// pub last_peek: interface::RustDeque, -// pub localaddr: Option, -// pub remoteaddr: Option, -// pub unix_info: Option, -// pub socktype: i32, -// pub sndbuf: i32, -// pub rcvbuf: i32, -// pub errno: i32, -// } - -// //This cleanup-on-drop strategy is used in lieu of manual refcounting in order to allow the close -// //syscall not to have to wait to increase the refcnt manually in case for example it is in a -// //blocking recv. This clean-on-drop strategy is made possible by the fact that file descriptors -// //hold reference to a SocketHandle via an Arc, so only when the last reference to a SocketHandle is -// //gone--that is when the last cage has closed it--do we actually attempt to shut down the inner -// //socket, which is what we could have done manually in close instead. This should be both cleaner -// //and faster, because we don't have to wait for the recv timeout like we do in shutdown -// impl Drop for SocketHandle { -// fn drop(&mut self) { -// Cage::_cleanup_socket_inner_helper(self, -1, false); -// } -// } - -// #[derive(Debug)] -// pub struct ConnCondVar { -// lock: interface::RustRfc>, -// cv: interface::Condvar, -// } - -// impl ConnCondVar { -// pub fn new() -> Self { -// Self { -// lock: interface::RustRfc::new(interface::Mutex::new(0)), -// cv: interface::Condvar::new(), -// } -// } - -// pub fn wait(&self) { -// let mut guard = self.lock.lock(); -// *guard += 1; -// self.cv.wait(&mut guard); -// } - -// pub fn broadcast(&self) -> bool { -// let guard = self.lock.lock(); -// if *guard == 1 { -// self.cv.notify_all(); -// return true; -// } else { -// return false; -// } -// } -// } - -// pub struct DomsockTableEntry { -// pub sockaddr: interface::GenSockaddr, -// pub receive_pipe: interface::RustRfc, -// pub send_pipe: interface::RustRfc, -// pub cond_var: Option>, -// } - -// impl DomsockTableEntry { -// pub fn get_cond_var(&self) -> Option<&interface::RustRfc> { -// self.cond_var.as_ref() -// } -// pub fn get_sockaddr(&self) -> &interface::GenSockaddr { -// &self.sockaddr -// } -// pub fn get_send_pipe(&self) -> &interface::RustRfc { -// &self.send_pipe -// } -// pub fn get_receive_pipe(&self) -> &interface::RustRfc { -// &self.receive_pipe -// } -// } - -// pub struct NetMetadata { -// pub used_port_set: interface::RustHashMap<(u16, PortType), Vec<(interface::GenIpaddr, u32)>>, //maps port tuple to whether rebinding is allowed: 0 means there's a user but rebinding is not allowed, positive number means that many users, rebinding is allowed -// next_ephemeral_port_tcpv4: interface::RustRfc>, -// next_ephemeral_port_udpv4: interface::RustRfc>, -// next_ephemeral_port_tcpv6: interface::RustRfc>, -// next_ephemeral_port_udpv6: interface::RustRfc>, -// pub listening_port_set: interface::RustHashSet<(interface::GenIpaddr, u16, PortType)>, -// pub pending_conn_table: interface::RustHashMap< -// (interface::GenIpaddr, u16, PortType), -// Vec<(Result, interface::GenSockaddr)>, -// >, -// pub domsock_accept_table: interface::RustHashMap, -// pub domsock_paths: interface::RustHashSet, -// } - -// impl NetMetadata { -// fn initialize_port( -// &self, -// tup: &(interface::GenIpaddr, u16, PortType), -// rebindability: u32, -// ) -> bool { -// let used_port_tup = (tup.1, tup.2.clone()); -// if tup.0.is_unspecified() { -// let tupclone = used_port_tup.clone(); -// let entry = self.used_port_set.entry(tupclone.clone()); -// match entry { -// interface::RustHashEntry::Occupied(_) => { -// return false; -// } -// interface::RustHashEntry::Vacant(v) => { -// let mut intervec = vec![]; -// for interface_addr in &*NET_DEVICE_IPLIST { -// intervec.push((interface_addr.clone(), rebindability)); -// } -// v.insert(intervec); -// } -// } -// true -// } else { -// match self.used_port_set.entry(used_port_tup) { -// interface::RustHashEntry::Occupied(mut o) => { -// let addrsused = o.get_mut(); -// for addrtup in addrsused.clone() { -// if addrtup.0 == tup.0 { -// return false; -// } -// } -// addrsused.push((tup.0.clone(), rebindability)); -// } -// interface::RustHashEntry::Vacant(v) => { -// v.insert(vec![(tup.0.clone(), rebindability)]); -// } -// } -// true -// } -// } - -// pub fn _get_available_udp_port( -// &self, -// addr: interface::GenIpaddr, -// domain: i32, -// rebindability: bool, -// ) -> Result { -// if !NET_DEVICE_IPLIST.contains(&addr) { -// return Err(syscall_error( -// Errno::EADDRNOTAVAIL, -// "bind", -// "Specified network device is not set up for lind or does not exist!", -// )); -// } -// let mut porttuple = mux_port(addr, 0, domain, UDPPORT); - -// //start from the starting location we specified in a previous attempt to get an ephemeral port -// let mut next_ephemeral = if domain == AF_INET { -// self.next_ephemeral_port_udpv4.write() -// } else if domain == AF_INET6 { -// self.next_ephemeral_port_udpv6.write() -// } else { -// unreachable!() -// }; -// for range in [ -// (EPHEMERAL_PORT_RANGE_START..=*next_ephemeral), -// (*next_ephemeral + 1..=EPHEMERAL_PORT_RANGE_END), -// ] { -// for ne_port in range.rev() { -// let port = ne_port.to_be(); //ports are stored in network endian order -// porttuple.1 = port; - -// //if we think we can bind to this port -// if self.initialize_port(&porttuple, if rebindability { 1 } else { 0 }) { -// //rebindability of 0 means not rebindable, 1 means it's rebindable and there's 1 bound to it -// *next_ephemeral -= 1; -// if *next_ephemeral < EPHEMERAL_PORT_RANGE_START { -// *next_ephemeral = EPHEMERAL_PORT_RANGE_END; -// } -// return Ok(port); -// } -// } -// } -// return Err(syscall_error( -// Errno::EADDRINUSE, -// "bind", -// "No available ephemeral port could be found", -// )); -// } -// pub fn _get_available_tcp_port( -// &self, -// addr: interface::GenIpaddr, -// domain: i32, -// rebindability: bool, -// ) -> Result { -// if !NET_DEVICE_IPLIST.contains(&addr) { -// return Err(syscall_error( -// Errno::EADDRNOTAVAIL, -// "bind", -// "Specified network device is not set up for lind or does not exist!", -// )); -// } -// let mut porttuple = mux_port(addr.clone(), 0, domain, TCPPORT); - -// //start from the starting location we specified in a previous attempt to get an ephemeral port -// let mut next_ephemeral = if domain == AF_INET { -// self.next_ephemeral_port_tcpv4.write() -// } else if domain == AF_INET6 { -// self.next_ephemeral_port_tcpv6.write() -// } else { -// unreachable!() -// }; -// for range in [ -// (EPHEMERAL_PORT_RANGE_START..=*next_ephemeral), -// (*next_ephemeral + 1..=EPHEMERAL_PORT_RANGE_END), -// ] { -// for ne_port in range.rev() { -// let port = ne_port.to_be(); //ports are stored in network endian order -// porttuple.1 = port; - -// if self.initialize_port(&porttuple, if rebindability { 1 } else { 0 }) { -// //rebindability of 0 means not rebindable, 1 means it's rebindable and there's 1 bound to it - -// *next_ephemeral -= 1; -// if *next_ephemeral < EPHEMERAL_PORT_RANGE_START { -// *next_ephemeral = EPHEMERAL_PORT_RANGE_END; -// } - -// return Ok(port); -// } -// } -// } -// return Err(syscall_error( -// Errno::EADDRINUSE, -// "bind", -// "No available ephemeral port could be found", -// )); -// } - -// pub fn _reserve_localport( -// &self, -// addr: interface::GenIpaddr, -// port: u16, -// protocol: i32, -// domain: i32, -// rebindability: bool, -// ) -> Result { -// if !NET_DEVICE_IPLIST.contains(&addr) { -// return Err(syscall_error( -// Errno::EADDRNOTAVAIL, -// "bind", -// "Specified network device is not set up for lind or does not exist!", -// )); -// } - -// let muxed; -// if protocol == IPPROTO_UDP { -// if port == 0 { -// return self._get_available_udp_port(addr, domain, rebindability); -// //assign ephemeral port -// } else { -// muxed = mux_port(addr, port, domain, UDPPORT); -// } -// } else if protocol == IPPROTO_TCP { -// if port == 0 { -// return self._get_available_tcp_port(addr, domain, rebindability); -// //assign ephemeral port -// } else { -// muxed = mux_port(addr, port, domain, TCPPORT); -// } -// } else { -// panic!("Unknown protocol was set on socket somehow"); -// } - -// let usedport_muxed = (muxed.1, muxed.2); -// let entry = self.used_port_set.entry(usedport_muxed); -// if addr.is_unspecified() { -// match entry { -// interface::RustHashEntry::Occupied(_) => { -// return Err(syscall_error( -// Errno::EADDRINUSE, -// "reserve port", -// "port is already in use", -// )); -// } -// interface::RustHashEntry::Vacant(v) => { -// v.insert( -// NET_DEVICE_IPLIST -// .iter() -// .map(|x| (x.clone(), if rebindability { 1 } else { 0 })) -// .collect(), -// ); -// } -// } -// } else { -// match entry { -// interface::RustHashEntry::Occupied(mut userentry) => { -// for portuser in userentry.get_mut() { -// if portuser.0 == muxed.0 { -// if portuser.1 == 0 { -// return Err(syscall_error( -// Errno::EADDRINUSE, -// "reserve port", -// "port is already in use", -// )); -// } else { -// portuser.1 += 1; -// } -// break; -// } -// } -// } -// interface::RustHashEntry::Vacant(v) => { -// v.insert(vec![(muxed.0.clone(), if rebindability { 1 } else { 0 })]); -// } -// } -// } -// Ok(port) -// } - -// pub fn _release_localport( -// &self, -// addr: interface::GenIpaddr, -// port: u16, -// protocol: i32, -// domain: i32, -// ) -> Result<(), i32> { -// if !NET_DEVICE_IPLIST.contains(&addr) { -// return Err(syscall_error( -// Errno::EADDRNOTAVAIL, -// "bind", -// "Specified network device is not set up for lind or does not exist!", -// )); -// } - -// let muxed; -// if protocol == IPPROTO_TCP { -// muxed = mux_port(addr.clone(), port, domain, TCPPORT); -// } else if protocol == IPPROTO_UDP { -// muxed = mux_port(addr.clone(), port, domain, UDPPORT); -// } else { -// return Err(syscall_error( -// Errno::EINVAL, -// "release", -// "provided port has nonsensical protocol", -// )); -// } - -// let usedport_muxed = (muxed.1, muxed.2); -// let entry = self.used_port_set.entry(usedport_muxed); -// match entry { -// interface::RustHashEntry::Occupied(mut userentry) => { -// let mut index = 0; -// let userarr = userentry.get_mut(); -// if addr.is_unspecified() { -// for portuser in userarr.clone() { -// if portuser.1 <= 1 { -// userarr.swap_remove(index); -// } else { -// //if it's rebindable and there are others bound to it -// userarr[index].1 -= 1; -// } -// } -// if userarr.len() == 0 { -// userentry.remove(); -// } -// return Ok(()); -// } else { -// for portuser in userarr.clone() { -// if portuser.0 == muxed.0 { -// //if it's rebindable and we're removing the last bound port or it's just not rebindable -// if portuser.1 <= 1 { -// if userarr.len() == 1 { -// userentry.remove(); -// } else { -// userarr.swap_remove(index); -// } -// } else { -// //if it's rebindable and there are others bound to it -// userarr[index].1 -= 1; -// } -// return Ok(()); -// } -// index += 1; -// } -// unreachable!(); -// } -// } -// interface::RustHashEntry::Vacant(_) => { -// return Err(syscall_error( -// Errno::EINVAL, -// "release", -// "provided port is not being used", -// )); -// } -// } -// } - -// pub fn get_domainsock_paths(&self) -> Vec { -// let mut domainsock_paths: Vec = vec![]; -// for ds_path in self.domsock_paths.iter() { -// domainsock_paths.push(ds_path.clone()); -// } // get vector of domain sock table keys -// domainsock_paths -// } -// } - -// pub struct SelectInetInfo { -// pub rawfd_lindfd_tuples: Vec<(i32, i32)>, -// pub kernel_fds: interface::FdSet, -// pub highest_raw_fd: i32, -// } - -// impl SelectInetInfo { -// pub fn new() -> Self { -// SelectInetInfo { -// rawfd_lindfd_tuples: Vec::new(), -// kernel_fds: interface::FdSet::new(), -// highest_raw_fd: 0, -// } -// } -// } - -// pub fn update_readfds_from_kernel_select( -// readfds: &mut interface::FdSet, -// inet_info: &mut SelectInetInfo, -// retval: &mut i32, -// ) -> i32 { -// let kernel_ret; -// // note that this select call always have timeout = 0, so it doesn't block - -// kernel_ret = interface::kernel_select( -// inet_info.highest_raw_fd + 1, -// Some(&mut inet_info.kernel_fds), -// None, -// None, -// ); -// if kernel_ret > 0 { -// // increment retval of our select -// *retval += kernel_ret; -// // translate the kernel checked fds to lindfds, and add to our new_writefds -// readfds.set_from_kernelfds_and_translate( -// &mut inet_info.kernel_fds, -// inet_info.highest_raw_fd + 1, -// &inet_info.rawfd_lindfd_tuples, -// ); -// } -// return kernel_ret; -// } diff --git a/src/safeposix/syscalls/fs_calls.rs b/src/safeposix/syscalls/fs_calls.rs index 681213e..18b6f3a 100644 --- a/src/safeposix/syscalls/fs_calls.rs +++ b/src/safeposix/syscalls/fs_calls.rs @@ -13,8 +13,6 @@ use crate::safeposix::cage::Errno::EINVAL; use crate::safeposix::cage::*; use crate::safeposix::filesystem::convpath; use crate::safeposix::filesystem::normpath; -// use crate::safeposix::filesystem::*; -// use crate::safeposix::net::NET_METADATA; use crate::safeposix::shm::*; use crate::interface::ShmidsStruct; use crate::interface::StatData; diff --git a/src/safeposix/syscalls/net_calls.rs b/src/safeposix/syscalls/net_calls.rs index 655320f..471b85b 100644 --- a/src/safeposix/syscalls/net_calls.rs +++ b/src/safeposix/syscalls/net_calls.rs @@ -1,7 +1,4 @@ #![allow(dead_code)] -// Network related system calls -// outlines and implements all of the networking system calls that are being emulated/faked in Lind - use super::net_constants; use crate::{interface::FdSet, safeposix::cage::*}; use crate::interface::*; @@ -24,7 +21,6 @@ use std::ffi::CString; use std::ffi::CStr; use std::sync::Arc; -use crate::safeposix::filesystem::convpath; use crate::safeposix::filesystem::normpath; use libc::*; diff --git a/src/safeposix/syscalls/sys_calls.rs b/src/safeposix/syscalls/sys_calls.rs index fbe1eed..cd7f977 100644 --- a/src/safeposix/syscalls/sys_calls.rs +++ b/src/safeposix/syscalls/sys_calls.rs @@ -48,23 +48,6 @@ impl Cage { pub fn fork_syscall(&self, child_cageid: u64) -> i32 { // Modify the fdtable manually fdtables::copy_fdtable_for_cage(self.cageid, child_cageid).unwrap(); - - // println!("[FORK]"); - // io::stdout().flush().unwrap(); - // if child_cageid == 22 { - // let mut count = 0; - // FDTABLE.iter().for_each(|entry| { - // println!("Cage ID: {}", entry.key()); - // for (index, fd_entry) in entry.value().iter().enumerate() { - // if let Some(entry) = fd_entry { - // println!(" Index {}: {:?}", index, entry); - // count = count+1; - // } - // } - // }); - // println!("Total: {:?}", count); - // io::stdout().flush().unwrap(); - // } //construct a new mutex in the child cage where each initialized mutex is in the parent cage let mutextable = self.mutex_table.read(); @@ -124,19 +107,6 @@ impl Cage { } drop(cvtable); - // let cwd_container = self.cwd.read(); - // if let Some(cwdinodenum) = metawalk(&cwd_container) { - // if let Inode::Dir(ref mut cwddir) = - // *(FS_METADATA.inodetable.get_mut(&cwdinodenum).unwrap()) - // { - // cwddir.refcount += 1; - // } else { - // panic!("We changed from a directory that was not a directory in chdir!"); - // } - // } else { - // panic!("We changed from a directory that was not a directory in chdir!"); - // } - // we grab the parent cages main threads sigset and store it at 0 // we do this because we haven't established a thread for the cage yet, and dont have a threadid to store it at // this way the child can initialize the sigset properly when it establishes its own mainthreadid @@ -174,7 +144,6 @@ impl Cage { cageid: child_cageid, cwd: interface::RustLock::new(self.cwd.read().clone()), parent: self.cageid, - // filedescriptortable: newfdtable, cancelstatus: interface::RustAtomicBool::new(false), // This happens because self.getgid tries to copy atomic value which does not implement "Copy" trait; self.getgid.load returns i32. getgid: interface::RustAtomicI32::new( @@ -255,7 +224,6 @@ impl Cage { cageid: child_cageid, cwd: interface::RustLock::new(self.cwd.read().clone()), parent: self.parent, - // filedescriptortable: self.filedescriptortable.clone(), cancelstatus: interface::RustAtomicBool::new(false), getgid: interface::RustAtomicI32::new(-1), getuid: interface::RustAtomicI32::new(-1), @@ -279,9 +247,6 @@ impl Cage { } pub fn exit_syscall(&self, status: i32) -> i32 { - // println!("[[EXIT]] - {:?}", self.cageid); - // io::stdout().flush().unwrap(); - //flush anything left in stdout interface::flush_stdout(); self.unmap_shm_mappings(); @@ -310,8 +275,10 @@ impl Cage { self.parent as i32 // mimicing the call above -- easy to change later if necessary } - /*if its negative 1 - return -1, but also set the values in the cage struct to the DEFAULTs for future calls*/ + /* + * if its negative 1 + * return -1, but also set the values in the cage struct to the DEFAULTs for future calls + */ pub fn getgid_syscall(&self) -> i32 { if self.getgid.load(interface::RustAtomicOrdering::Relaxed) == -1 { self.getgid @@ -440,14 +407,6 @@ impl Cage { res } - // pub fn setitimer_syscall( - // &self, - // which: i32, - // new_value: &itimerval, - // old_value: &mut itimerval, - // ) -> i32 { - // unsafe { libc::syscall(SYS_setitimer, which, new_value, old_value) as i32 } - // } pub fn setitimer_syscall( &self, which: i32,