pub struct Process {
pub file_struct: FileStruct,
pub mm_struct: MmStruct<EagerPager>,
}Expand description
A process state of project 2, which contains file struct and mm struct.
Fields§
§file_struct: FileStruct§mm_struct: MmStruct<EagerPager>Implementations§
Source§impl Process
impl Process
Sourcepub fn from_mm_struct(mm_struct: MmStruct<EagerPager>) -> Self
pub fn from_mm_struct(mm_struct: MmStruct<EagerPager>) -> Self
Create a process with given MmStruct.
Sourcepub fn exit(&self, abi: &SyscallAbi<'_>) -> Result<usize, KernelError>
pub fn exit(&self, abi: &SyscallAbi<'_>) -> Result<usize, KernelError>
Exit a process.
This function terminates the calling thread by invoking exit on the
current thread. The exit code is provided as the first argument
(arg1) of the system call.
§Syscall API
int exit(int status);status: The thread’s exit code.
§Parameters
abi: A reference toSyscallAbi, which holds the arguments passed to the system call.
§Returns
- Never returns.
§Behavior
§Example
syscall!(SyscallNumber::Exit as usize, 0); // Exit with code 0§Notes
- This function does not return in normal execution, as it terminates the thread.
- If an error occurs, it returns a
KernelError
Trait Implementations§
Source§impl Task for Process
impl Task for Process
Source§fn syscall(&mut self, regs: &mut Registers)
fn syscall(&mut self, regs: &mut Registers)
Handles a system call request from a user program.
This function is the entry point for system call handling. It retrieves
the system call ABI from the provided Registers structure, which
includes the system call number and its arguments. Based on the
system call number (sysno), it looks up the appropriate handler
function in a predefined list. If a handler is found, it is invoked
with the ABI, otherwise, an error (KernelError::NoSuchSyscall) is
returned.
After the handler function processes the system call, the return value
(either a success or error) is set back into the CPU registers via
the set_return_value method. The return value is stored in the %rax
register as per the x86-64 system call convention.
§Parameters
regs: A mutable reference to theRegistersstruct, which contains the current state of the CPU registers. This structure will be used to retrieve the system call number and its arguments, and also to set the return value.
§Functionality
The function processes the system call as follows:
- Extracts the system call number and arguments using the
SyscallAbi::from_registers. - Looks up the corresponding handler function from a predefined list of
system calls. The handler function is selected based on the system
call number (
sysno). - If a handler is found, it is executed with the ABI as an argument. If
no handler is found, the function returns a
KernelError::NoSuchSyscallerror.
The result of the system call handler (either success or error) is then
returned via the SyscallAbi::set_return_value method, which
modifies the CPU registers accordingly.
Source§fn access_ok(&self, addr: Range<Va>, is_write: bool) -> bool
fn access_ok(&self, addr: Range<Va>, is_write: bool) -> bool
Validates whether the given memory range is accessible for the process.
This function checks if a memory region is safe to read or write before performing a memory-related operation. It ensures that user-provided addresses do not access restricted memory regions, preventing potential security vulnerabilities or crashes.
§Parameters
addr: A range of virtual addresses to be accessed.is_write:trueif the access involves writing to memory,falsefor read-only access.
§Returns
trueif the memory range is valid and accessible.falseif access is denied due to invalid address range or insufficient permissions.