pub struct Task {Show 24 fields
id: usize,
pub name: String,
pub priority: u32,
pub vcpu: Vcpu,
pub state: TaskState,
pub task_type: TaskType,
pub entry: usize,
pub brk: Option<usize>,
pub stack_size: usize,
pub data_size: usize,
pub text_size: usize,
pub max_stack_size: usize,
pub max_data_size: usize,
pub max_text_size: usize,
pub vm_manager: VirtualMemoryManager,
pub managed_pages: Vec<ManagedPage>,
parent_id: Option<usize>,
children: Vec<usize>,
exit_status: Option<i32>,
pub abi: Option<Box<dyn AbiModule>>,
fd_table: Vec<usize>,
files: [Option<File>; 256],
pub cwd: Option<String>,
pub vfs: Option<Arc<VfsManager>>,
}
Fields§
§id: usize
§name: String
§priority: u32
§vcpu: Vcpu
§state: TaskState
§task_type: TaskType
§entry: usize
§brk: Option<usize>
§stack_size: usize
§data_size: usize
§text_size: usize
§max_stack_size: usize
§max_data_size: usize
§max_text_size: usize
§vm_manager: VirtualMemoryManager
§managed_pages: Vec<ManagedPage>
Managed pages
Managed pages are freed automatically when the task is terminated.
parent_id: Option<usize>
§children: Vec<usize>
§exit_status: Option<i32>
§abi: Option<Box<dyn AbiModule>>
Dynamic ABI
fd_table: Vec<usize>
§files: [Option<File>; 256]
§cwd: Option<String>
§vfs: Option<Arc<VfsManager>>
Virtual File System Manager
Each task can have its own isolated VfsManager instance for containerization and namespace isolation. The VfsManager provides:
- Filesystem Isolation: Independent mount point namespaces allowing complete filesystem isolation between tasks or containers
- Selective Sharing: Arc-based filesystem object sharing enables controlled resource sharing while maintaining namespace independence
- Bind Mount Support: Advanced bind mount capabilities for flexible directory mapping and container orchestration scenarios
- Security: Path normalization and validation preventing directory traversal attacks and unauthorized filesystem access
§Usage Patterns
None
: Task uses global filesystem namespace (traditional Unix-like behavior)Some(Arc<VfsManager>)
: Task has isolated filesystem namespace (container-like behavior)
§Thread Safety
VfsManager is thread-safe and can be shared between tasks using Arc. All internal operations use RwLock for concurrent access protection.
Implementations§
Source§impl Task
impl Task
pub fn new(name: String, priority: u32, task_type: TaskType) -> Self
pub fn init(&mut self)
pub fn get_id(&self) -> usize
Sourcepub fn allocate_pages(
&mut self,
vaddr: usize,
num_of_pages: usize,
permissions: usize,
) -> Result<VirtualMemoryMap, &'static str>
pub fn allocate_pages( &mut self, vaddr: usize, num_of_pages: usize, permissions: usize, ) -> Result<VirtualMemoryMap, &'static str>
Allocate pages for the task.
§Arguments
vaddr
- The virtual address to allocate pages (NOTE: The address must be page aligned)num_of_pages
- The number of pages to allocatesegment
- The segment type to allocate pages
§Returns
The memory map of the allocated pages, if successful.
§Errors
If the address is not page aligned, or if the pages cannot be allocated.
§Note
This function don’t increment the size of the task. You must increment the size of the task manually.
Sourcepub fn free_pages(&mut self, vaddr: usize, num_of_pages: usize)
pub fn free_pages(&mut self, vaddr: usize, num_of_pages: usize)
Free pages for the task.
§Arguments
vaddr
- The virtual address to free pages (NOTE: The address must be page aligned)num_of_pages
- The number of pages to free
Sourcepub fn allocate_text_pages(
&mut self,
vaddr: usize,
num_of_pages: usize,
) -> Result<VirtualMemoryMap, &'static str>
pub fn allocate_text_pages( &mut self, vaddr: usize, num_of_pages: usize, ) -> Result<VirtualMemoryMap, &'static str>
Allocate text pages for the task. And increment the size of the task.
§Arguments
vaddr
- The virtual address to allocate pages (NOTE: The address must be page aligned)num_of_pages
- The number of pages to allocate
§Returns
The memory map of the allocated pages, if successful.
§Errors
If the address is not page aligned, or if the pages cannot be allocated.
Sourcepub fn free_text_pages(&mut self, vaddr: usize, num_of_pages: usize)
pub fn free_text_pages(&mut self, vaddr: usize, num_of_pages: usize)
Free text pages for the task. And decrement the size of the task.
§Arguments
vaddr
- The virtual address to free pages (NOTE: The address must be page aligned)num_of_pages
- The number of pages to free
Sourcepub fn allocate_stack_pages(
&mut self,
vaddr: usize,
num_of_pages: usize,
) -> Result<VirtualMemoryMap, &'static str>
pub fn allocate_stack_pages( &mut self, vaddr: usize, num_of_pages: usize, ) -> Result<VirtualMemoryMap, &'static str>
Allocate stack pages for the task. And increment the size of the task.
§Arguments
vaddr
- The virtual address to allocate pages (NOTE: The address must be page aligned)num_of_pages
- The number of pages to allocate
§Returns
The memory map of the allocated pages, if successful.
§Errors
If the address is not page aligned, or if the pages cannot be allocated.
Sourcepub fn free_stack_pages(&mut self, vaddr: usize, num_of_pages: usize)
pub fn free_stack_pages(&mut self, vaddr: usize, num_of_pages: usize)
Free stack pages for the task. And decrement the size of the task.
§Arguments
vaddr
- The virtual address to free pages (NOTE: The address must be page aligned)num_of_pages
- The number of pages to free
Sourcepub fn allocate_data_pages(
&mut self,
vaddr: usize,
num_of_pages: usize,
) -> Result<VirtualMemoryMap, &'static str>
pub fn allocate_data_pages( &mut self, vaddr: usize, num_of_pages: usize, ) -> Result<VirtualMemoryMap, &'static str>
Allocate data pages for the task. And increment the size of the task.
§Arguments
vaddr
- The virtual address to allocate pages (NOTE: The address must be page aligned)num_of_pages
- The number of pages to allocate
§Returns
The memory map of the allocated pages, if successful.
§Errors
If the address is not page aligned, or if the pages cannot be allocated.
Sourcepub fn free_data_pages(&mut self, vaddr: usize, num_of_pages: usize)
pub fn free_data_pages(&mut self, vaddr: usize, num_of_pages: usize)
Free data pages for the task. And decrement the size of the task.
§Arguments
vaddr
- The virtual address to free pages (NOTE: The address must be page aligned)num_of_pages
- The number of pages to free
Sourcepub fn allocate_guard_pages(
&mut self,
vaddr: usize,
num_of_pages: usize,
) -> Result<VirtualMemoryMap, &'static str>
pub fn allocate_guard_pages( &mut self, vaddr: usize, num_of_pages: usize, ) -> Result<VirtualMemoryMap, &'static str>
Allocate guard pages for the task.
§Arguments
vaddr
- The virtual address to allocate pages (NOTE: The address must be page aligned)num_of_pages
- The number of pages to allocate
§Returns
The memory map of the allocated pages, if successful.
§Errors
If the address is not page aligned, or if the pages cannot be allocated.
§Note
Gurad pages are not allocated in the physical memory space. This function only maps the pages to the virtual memory space.
Sourcepub fn add_managed_page(&mut self, pages: ManagedPage)
pub fn add_managed_page(&mut self, pages: ManagedPage)
Sourcefn get_managed_page(&self, vaddr: usize) -> Option<&ManagedPage>
fn get_managed_page(&self, vaddr: usize) -> Option<&ManagedPage>
Sourcefn remove_managed_page(&mut self, vaddr: usize) -> Option<Box<Page>>
fn remove_managed_page(&mut self, vaddr: usize) -> Option<Box<Page>>
pub fn set_entry_point(&mut self, entry: usize)
Sourcepub fn get_parent_id(&self) -> Option<usize>
pub fn get_parent_id(&self) -> Option<usize>
Sourcepub fn set_parent_id(&mut self, parent_id: usize)
pub fn set_parent_id(&mut self, parent_id: usize)
Sourcepub fn remove_child(&mut self, child_id: usize) -> bool
pub fn remove_child(&mut self, child_id: usize) -> bool
Sourcepub fn get_children(&self) -> &Vec<usize>
pub fn get_children(&self) -> &Vec<usize>
Sourcepub fn set_exit_status(&mut self, status: i32)
pub fn set_exit_status(&mut self, status: i32)
Sourcepub fn get_exit_status(&self) -> Option<i32>
pub fn get_exit_status(&self) -> Option<i32>
Sourcepub fn get_fd_table(&self) -> &Vec<usize>
pub fn get_fd_table(&self) -> &Vec<usize>
Sourcepub fn get_mut_file(&mut self, fd: usize) -> Option<&mut File>
pub fn get_mut_file(&mut self, fd: usize) -> Option<&mut File>
Sourcepub fn remove_file(&mut self, fd: usize) -> Result<(), &'static str>
pub fn remove_file(&mut self, fd: usize) -> Result<(), &'static str>
Sourcefn allocate_fd(&mut self) -> Option<usize>
fn allocate_fd(&mut self) -> Option<usize>
Allocate a file descriptor
§Returns
The allocated file descriptor, or None if no file descriptors are available