Struct yash_env::system::virtual::VirtualSystem
source · pub struct VirtualSystem {
pub state: Rc<RefCell<SystemState>>,
pub process_id: Pid,
}Expand description
Simulated system.
See the module-level documentation to grasp a basic understanding of
VirtualSystem.
A VirtualSystem instance has two members: state and process_id. The
former is a SystemState that effectively contains the state of the
system. The state is contained in Rc so that processes can share the same
state. The latter is a process ID that identifies a process calling the
System interface.
When you clone a virtual system, the clone will have the same process_id
as the original. To simulate the fork system call, you would probably want
to assign a new process ID and add a new Process to the system state.
Fields§
§state: Rc<RefCell<SystemState>>State of the system.
process_id: PidProcess ID of the process that is interacting with the system.
Implementations§
source§impl VirtualSystem
impl VirtualSystem
sourcepub fn new() -> VirtualSystem
pub fn new() -> VirtualSystem
Creates a virtual system with an almost empty state.
The process_id of the returned VirtualSystem will be 2.
(Process ID 1 has special meaning in some system calls, so we don’t use
it as a default value.)
The state of the returned VirtualSystem will have a Process with
process ID 2 in the process set (SystemState::processes). The file
system will contain files named /dev/stdin, /dev/stdout, and
/dev/stderr that are opened in the process with file descriptor 0, 1,
and 2, respectively. The file system also contains an empty directory
/tmp.
sourcepub fn current_process(&self) -> Ref<'_, Process>
pub fn current_process(&self) -> Ref<'_, Process>
Finds the current process from the system state.
§Panics
This function will panic if it cannot find a process having
self.process_id.
sourcepub fn current_process_mut(&mut self) -> RefMut<'_, Process>
pub fn current_process_mut(&mut self) -> RefMut<'_, Process>
Finds the current process from the system state.
§Panics
This function will panic if it cannot find a process having
self.process_id.
sourcepub fn with_open_file_description<F, R>(&self, fd: Fd, f: F) -> Result<R>
pub fn with_open_file_description<F, R>(&self, fd: Fd, f: F) -> Result<R>
Calls the given closure passing the open file description for the FD.
Returns Err(Errno::EBADF) if the FD is not open.
sourcepub fn with_open_file_description_mut<F, R>(
&mut self,
fd: Fd,
f: F
) -> Result<R>
pub fn with_open_file_description_mut<F, R>( &mut self, fd: Fd, f: F ) -> Result<R>
Calls the given closure passing the open file description for the FD.
Returns Err(Errno::EBADF) if the FD is not open.
Trait Implementations§
source§impl Clone for VirtualSystem
impl Clone for VirtualSystem
source§fn clone(&self) -> VirtualSystem
fn clone(&self) -> VirtualSystem
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for VirtualSystem
impl Debug for VirtualSystem
source§impl Default for VirtualSystem
impl Default for VirtualSystem
source§impl System for VirtualSystem
impl System for VirtualSystem
source§fn fstat(&self, fd: Fd) -> Result<FileStat>
fn fstat(&self, fd: Fd) -> Result<FileStat>
Retrieves metadata of a file.
The current implementation fills only the following values of the
returned FileStat:
st_modest_sizest_dev(always 1)st_ino(computed from the address ofINode)
source§fn fstatat(&self, dir_fd: Fd, path: &CStr, flags: AtFlags) -> Result<FileStat>
fn fstatat(&self, dir_fd: Fd, path: &CStr, flags: AtFlags) -> Result<FileStat>
Retrieves metadata of a file.
The current implementation fills only the following values of the
returned FileStat:
st_modest_sizest_dev(always 1)st_ino(computed from the address ofINode)
source§fn is_executable_file(&self, path: &CStr) -> bool
fn is_executable_file(&self, path: &CStr) -> bool
Tests whether the specified file is executable or not.
The current implementation only checks if the file has any executable bit in the permissions. The file owner and group are not considered.
source§fn fcntl_setfl(&mut self, _fd: Fd, _flags: OFlag) -> Result<()>
fn fcntl_setfl(&mut self, _fd: Fd, _flags: OFlag) -> Result<()>
Current implementation does nothing but return Ok(()).
source§fn now(&self) -> Instant
fn now(&self) -> Instant
Returns now in SystemState.
Panics if it is None.
source§fn kill(
&mut self,
target: Pid,
signal: Option<Signal>
) -> Pin<Box<dyn Future<Output = Result<()>>>>
fn kill( &mut self, target: Pid, signal: Option<Signal> ) -> Pin<Box<dyn Future<Output = Result<()>>>>
Sends a signal to the target process.
This function returns a future that enables the executor to block the calling thread until the current process is ready to proceed. If the signal is sent to the current process and it causes the process to stop, the future will be ready only when the process is resumed. Similarly, if the signal causes the current process to terminate, the future will never be ready.
source§fn select(
&mut self,
readers: &mut FdSet,
writers: &mut FdSet,
timeout: Option<&TimeSpec>,
signal_mask: Option<&SigSet>
) -> Result<c_int>
fn select( &mut self, readers: &mut FdSet, writers: &mut FdSet, timeout: Option<&TimeSpec>, signal_mask: Option<&SigSet> ) -> Result<c_int>
Waits for a next event.
The VirtualSystem implementation for this method does not actually
block the calling thread. The method returns immediately in any case.
The timeout is ignored if this function returns because of a ready FD
or a caught signal. Otherwise, the timeout is added to
SystemState::now, which must not be None then.
source§fn setpgid(&mut self, pid: Pid, pgid: Pid) -> Result<()>
fn setpgid(&mut self, pid: Pid, pgid: Pid) -> Result<()>
Modifies the process group ID of a process.
The current implementation does not yet support the concept of sessions.
source§fn tcgetpgrp(&self, fd: Fd) -> Result<Pid>
fn tcgetpgrp(&self, fd: Fd) -> Result<Pid>
Returns the current foreground process group ID.
The current implementation does not yet support the concept of controlling terminals and sessions. It accepts any open file descriptor.
source§fn tcsetpgrp(&mut self, fd: Fd, pgid: Pid) -> Result<()>
fn tcsetpgrp(&mut self, fd: Fd, pgid: Pid) -> Result<()>
Switches the foreground process.
The current implementation does not yet support the concept of controlling terminals and sessions. It accepts any open file descriptor.
source§fn new_child_process(&mut self) -> Result<ChildProcessStarter>
fn new_child_process(&mut self) -> Result<ChildProcessStarter>
Creates a new child process.
This implementation does not create any real child process. Instead, it returns a child process starter that runs its task concurrently in the same process.
To run the concurrent task, this function needs an executor that has
been set in the system state. If the system state does not have an
executor, this function fails with Errno::ENOSYS.
The process ID of the child will be the maximum of existing process IDs plus 1. If there are no other processes, it will be 2.
source§fn wait(&mut self, target: Pid) -> Result<Option<(Pid, ProcessState)>>
fn wait(&mut self, target: Pid) -> Result<Option<(Pid, ProcessState)>>
Waits for a child.
TODO: Currently, this function only supports target == -1 || target > 0.
source§fn execve(
&mut self,
path: &CStr,
args: &[CString],
envs: &[CString]
) -> Result<Infallible>
fn execve( &mut self, path: &CStr, args: &[CString], envs: &[CString] ) -> Result<Infallible>
Stub for the execve system call.
The execve system call cannot be simulated in the userland. This
function returns ENOSYS if the file at path is a native executable,
ENOEXEC if a non-executable file, and ENOENT otherwise.
source§fn chdir(&mut self, path: &CStr) -> Result<()>
fn chdir(&mut self, path: &CStr) -> Result<()>
Changes the current working directory.
The current implementation does not canonicalize “.”, “..”, or symbolic links in the new path set to the process.
source§fn confstr_path(&self) -> Result<OsString>
fn confstr_path(&self) -> Result<OsString>
Returns the standard path for the system.
This function returns the value of SystemState::path. If it is empty,
it returns the ENOSYS error.
source§fn is_directory(&self, path: &CStr) -> bool
fn is_directory(&self, path: &CStr) -> bool
source§fn dup(&mut self, from: Fd, to_min: Fd, flags: FdFlag) -> Result<Fd>
fn dup(&mut self, from: Fd, to_min: Fd, flags: FdFlag) -> Result<Fd>
source§fn open(&mut self, path: &CStr, option: OFlag, mode: Mode) -> Result<Fd>
fn open(&mut self, path: &CStr, option: OFlag, mode: Mode) -> Result<Fd>
source§fn open_tmpfile(&mut self, _parent_dir: &Path) -> Result<Fd>
fn open_tmpfile(&mut self, _parent_dir: &Path) -> Result<Fd>
source§fn fcntl_getfl(&self, fd: Fd) -> Result<OFlag>
fn fcntl_getfl(&self, fd: Fd) -> Result<OFlag>
source§fn fcntl_getfd(&self, fd: Fd) -> Result<FdFlag>
fn fcntl_getfd(&self, fd: Fd) -> Result<FdFlag>
source§fn fcntl_setfd(&mut self, fd: Fd, flags: FdFlag) -> Result<()>
fn fcntl_setfd(&mut self, fd: Fd, flags: FdFlag) -> Result<()>
source§fn isatty(&self, _fd: Fd) -> Result<bool>
fn isatty(&self, _fd: Fd) -> Result<bool>
source§fn read(&mut self, fd: Fd, buffer: &mut [u8]) -> Result<usize>
fn read(&mut self, fd: Fd, buffer: &mut [u8]) -> Result<usize>
source§fn write(&mut self, fd: Fd, buffer: &[u8]) -> Result<usize>
fn write(&mut self, fd: Fd, buffer: &[u8]) -> Result<usize>
source§fn lseek(&mut self, fd: Fd, position: SeekFrom) -> Result<u64>
fn lseek(&mut self, fd: Fd, position: SeekFrom) -> Result<u64>
source§fn fdopendir(&mut self, fd: Fd) -> Result<Box<dyn Dir>>
fn fdopendir(&mut self, fd: Fd) -> Result<Box<dyn Dir>>
source§fn opendir(&mut self, path: &CStr) -> Result<Box<dyn Dir>>
fn opendir(&mut self, path: &CStr) -> Result<Box<dyn Dir>>
source§fn sigmask(
&mut self,
how: SigmaskHow,
set: Option<&SigSet>,
oldset: Option<&mut SigSet>
) -> Result<()>
fn sigmask( &mut self, how: SigmaskHow, set: Option<&SigSet>, oldset: Option<&mut SigSet> ) -> Result<()>
source§fn sigaction(
&mut self,
signal: Signal,
action: SignalHandling
) -> Result<SignalHandling>
fn sigaction( &mut self, signal: Signal, action: SignalHandling ) -> Result<SignalHandling>
source§fn caught_signals(&mut self) -> Vec<Signal>
fn caught_signals(&mut self) -> Vec<Signal>
source§fn getpwnam_dir(&self, name: &str) -> Result<Option<PathBuf>>
fn getpwnam_dir(&self, name: &str) -> Result<Option<PathBuf>>
Auto Trait Implementations§
impl Freeze for VirtualSystem
impl !RefUnwindSafe for VirtualSystem
impl !Send for VirtualSystem
impl !Sync for VirtualSystem
impl Unpin for VirtualSystem
impl !UnwindSafe for VirtualSystem
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more