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 whole state of the
system. The state is contained in Rc so that virtual processes can share
the same state. The latter is a process ID that identifies a process calling
the system interfaces.
When you clone a virtual system, the clone will have the same process_id
and state as the original. To simulate the fork system call, you should
call a method of the Fork trait implemented by VirtualSystem.
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(&self) -> RefMut<'_, Process>
pub fn current_process_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>(&self, fd: Fd, f: F) -> Result<R>
pub fn with_open_file_description_mut<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.
Trait Implementations§
Source§impl CaughtSignals for VirtualSystem
impl CaughtSignals for VirtualSystem
Source§impl Chdir for VirtualSystem
impl Chdir for VirtualSystem
Source§impl Clock for VirtualSystem
impl Clock for VirtualSystem
Source§fn now(&self) -> Instant
fn now(&self) -> Instant
Returns now in SystemState.
Panics if it is None.
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 Close for VirtualSystem
impl Close for VirtualSystem
Source§impl Debug for VirtualSystem
impl Debug for VirtualSystem
Source§impl Default for VirtualSystem
impl Default for VirtualSystem
Source§impl Dup for VirtualSystem
impl Dup for VirtualSystem
Source§impl Exec for VirtualSystem
impl Exec for VirtualSystem
Source§fn execve(
&self,
path: &CStr,
args: &[CString],
envs: &[CString],
) -> impl Future<Output = Result<Infallible>> + use<>
fn execve( &self, path: &CStr, args: &[CString], envs: &[CString], ) -> impl Future<Output = Result<Infallible>> + use<>
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§impl Exit for VirtualSystem
impl Exit for VirtualSystem
Source§fn exit(
&self,
exit_status: ExitStatus,
) -> impl Future<Output = Infallible> + use<>
fn exit( &self, exit_status: ExitStatus, ) -> impl Future<Output = Infallible> + use<>
Source§impl Fcntl for VirtualSystem
impl Fcntl for VirtualSystem
Source§fn ofd_access(&self, fd: Fd) -> Result<OfdAccess>
fn ofd_access(&self, fd: Fd) -> Result<OfdAccess>
Source§fn get_and_set_nonblocking(&self, fd: Fd, _nonblocking: bool) -> Result<bool>
fn get_and_set_nonblocking(&self, fd: Fd, _nonblocking: bool) -> Result<bool>
Source§impl Fork for VirtualSystem
impl Fork for VirtualSystem
Source§fn new_child_process(&self) -> Result<ChildProcessStarter<Self>>
fn new_child_process(&self) -> Result<ChildProcessStarter<Self>>
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 SystemState. 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§impl Fstat for VirtualSystem
impl Fstat for VirtualSystem
Source§fn fstatat(
&self,
dir_fd: Fd,
path: &CStr,
follow_symlinks: bool,
) -> Result<Stat>
fn fstatat( &self, dir_fd: Fd, path: &CStr, follow_symlinks: bool, ) -> Result<Stat>
Source§fn is_directory(&self, path: &CStr) -> bool
fn is_directory(&self, path: &CStr) -> bool
Source§fn fd_is_pipe(&self, fd: Fd) -> bool
fn fd_is_pipe(&self, fd: Fd) -> bool
Source§impl GetCwd for VirtualSystem
impl GetCwd for VirtualSystem
Source§impl GetPid for VirtualSystem
impl GetPid for VirtualSystem
Source§impl GetPw for VirtualSystem
impl GetPw for VirtualSystem
Source§impl GetRlimit for VirtualSystem
impl GetRlimit for VirtualSystem
Source§impl GetSigaction for VirtualSystem
impl GetSigaction for VirtualSystem
Source§fn get_sigaction(&self, signal: Number) -> Result<Disposition>
fn get_sigaction(&self, signal: Number) -> Result<Disposition>
Source§impl GetUid for VirtualSystem
impl GetUid for VirtualSystem
Source§impl IsExecutableFile for VirtualSystem
impl IsExecutableFile for VirtualSystem
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§impl Isatty for VirtualSystem
impl Isatty for VirtualSystem
Source§impl Open for VirtualSystem
impl Open for VirtualSystem
Source§fn open(
&self,
path: &CStr,
access: OfdAccess,
flags: EnumSet<OpenFlag>,
mode: Mode,
) -> Result<Fd>
fn open( &self, path: &CStr, access: OfdAccess, flags: EnumSet<OpenFlag>, mode: Mode, ) -> Result<Fd>
Source§fn open_tmpfile(&self, _parent_dir: &Path) -> Result<Fd>
fn open_tmpfile(&self, _parent_dir: &Path) -> Result<Fd>
Source§impl Pipe for VirtualSystem
impl Pipe for VirtualSystem
Source§impl Read for VirtualSystem
impl Read for VirtualSystem
Source§impl Seek for VirtualSystem
impl Seek for VirtualSystem
Source§impl Select for VirtualSystem
impl Select for VirtualSystem
Source§fn select(
&self,
readers: &mut Vec<Fd>,
writers: &mut Vec<Fd>,
timeout: Option<Duration>,
signal_mask: Option<&[Number]>,
) -> Result<c_int>
fn select( &self, readers: &mut Vec<Fd>, writers: &mut Vec<Fd>, timeout: Option<Duration>, signal_mask: Option<&[Number]>, ) -> 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§impl SendSignal for VirtualSystem
impl SendSignal for VirtualSystem
Source§fn kill(
&self,
target: Pid,
signal: Option<Number>,
) -> impl Future<Output = Result<()>> + use<>
fn kill( &self, target: Pid, signal: Option<Number>, ) -> impl Future<Output = Result<()>> + use<>
Sends a signal to the target process.
The current implementation accepts any positive signal number and None
(no signal) for signal. Negative signal numbers are rejected with
Errno::EINVAL.
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§impl SetPgid for VirtualSystem
impl SetPgid for VirtualSystem
Source§impl SetRlimit for VirtualSystem
impl SetRlimit for VirtualSystem
Source§impl ShellPath for VirtualSystem
impl ShellPath for VirtualSystem
Source§fn shell_path(&self) -> CString
fn shell_path(&self) -> CString
Returns the path to the shell.
The current implementation returns “/bin/sh”.
Source§impl Sigaction for VirtualSystem
impl Sigaction for VirtualSystem
Source§fn sigaction(
&self,
signal: Number,
disposition: Disposition,
) -> Result<Disposition>
fn sigaction( &self, signal: Number, disposition: Disposition, ) -> Result<Disposition>
Source§impl Sigmask for VirtualSystem
impl Sigmask for VirtualSystem
Source§impl Signals for VirtualSystem
impl Signals for VirtualSystem
Source§fn sigrt_range(&self) -> Option<RangeInclusive<Number>>
fn sigrt_range(&self) -> Option<RangeInclusive<Number>>
Source§const NAMED_SIGNALS: &'static [(&'static str, Option<Number>)] = _
const NAMED_SIGNALS: &'static [(&'static str, Option<Number>)] = _
Source§fn iter_sigrt(&self) -> impl DoubleEndedIterator<Item = Number> + use<Self>
fn iter_sigrt(&self) -> impl DoubleEndedIterator<Item = Number> + use<Self>
Source§fn to_signal_number<N: Into<RawNumber>>(&self, number: N) -> Option<Number>
fn to_signal_number<N: Into<RawNumber>>(&self, number: N) -> Option<Number>
Source§fn sig2str<N: Into<RawNumber>>(&self, signal: N) -> Option<Cow<'static, str>>
fn sig2str<N: Into<RawNumber>>(&self, signal: N) -> Option<Cow<'static, str>>
Source§fn str2sig(&self, name: &str) -> Option<Number>
fn str2sig(&self, name: &str) -> Option<Number>
Source§fn validate_signal(&self, number: RawNumber) -> Option<(Name, Number)>
fn validate_signal(&self, number: RawNumber) -> Option<(Name, Number)>
Source§impl Sysconf for VirtualSystem
impl Sysconf for VirtualSystem
Source§fn confstr_path(&self) -> Result<UnixString>
fn confstr_path(&self) -> Result<UnixString>
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§impl TcGetPgrp for VirtualSystem
impl TcGetPgrp for VirtualSystem
Source§impl TcSetPgrp for VirtualSystem
impl TcSetPgrp for VirtualSystem
Source§impl Times for VirtualSystem
impl Times for VirtualSystem
Source§impl Umask for VirtualSystem
impl Umask for VirtualSystem
Source§impl Wait for VirtualSystem
impl Wait for VirtualSystem
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> SystemEx for T
impl<T> SystemEx for T
Source§fn move_fd_internal(&mut self, from: Fd) -> Result<Fd>
fn move_fd_internal(&mut self, from: Fd) -> Result<Fd>
yash_env::io::move_fd_internal insteadMIN_INTERNAL_FD or larger. Read moreSource§fn fd_is_pipe(&self, fd: Fd) -> bool
fn fd_is_pipe(&self, fd: Fd) -> bool
yash_env::system::Fstat::fd_is_pipe insteadSource§fn tcsetpgrp_with_block(
&mut self,
fd: Fd,
pgid: Pid,
) -> impl Future<Output = Result<()>>
fn tcsetpgrp_with_block( &mut self, fd: Fd, pgid: Pid, ) -> impl Future<Output = Result<()>>
yash_env::job::tcsetpgrp_with_block insteadSource§fn tcsetpgrp_without_block(
&mut self,
fd: Fd,
pgid: Pid,
) -> impl Future<Output = Result<()>>
fn tcsetpgrp_without_block( &mut self, fd: Fd, pgid: Pid, ) -> impl Future<Output = Result<()>>
yash_env::job::tcsetpgrp_without_block insteadSource§fn signal_name_from_number(&self, number: Number) -> Name
fn signal_name_from_number(&self, number: Number) -> Name
yash_env::system::Signals::signal_name_from_number insteadSource§fn exit_or_raise(
&mut self,
exit_status: ExitStatus,
) -> impl Future<Output = Infallible>
fn exit_or_raise( &mut self, exit_status: ExitStatus, ) -> impl Future<Output = Infallible>
yash_env::semantics::exit_or_raise insteadSource§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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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