92 lines
2.4 KiB
Rust
92 lines
2.4 KiB
Rust
// Copyright (c) 2025 shibedrill
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#![allow(unused_imports, dead_code)]
|
|
|
|
use enumflags2::{BitFlags, bitflags, make_bitflags};
|
|
|
|
use crate::arch::asm;
|
|
use crate::memory::MemoryRegion;
|
|
use crate::memory::MemoryRegionFlags;
|
|
use crate::memory::alloc;
|
|
use alloc::string::String;
|
|
use alloc::vec::Vec;
|
|
|
|
#[allow(dead_code)]
|
|
pub struct ProcessTable {}
|
|
|
|
#[allow(dead_code)]
|
|
pub struct Process {
|
|
/// Unique process ID.
|
|
proc_id: u32,
|
|
/// ID of the parent process.
|
|
parent_proc_id: u32,
|
|
/// List of all child processes.
|
|
child_proc_ids: Vec<u32>,
|
|
/// Human readable name of the process, should be the command.
|
|
name: String,
|
|
/// The base address of the process stack within its memory region.
|
|
stack_base_addr: usize,
|
|
/// The length of the stack. This, plus the start address, is the stack size.
|
|
stack_length: usize,
|
|
/// The stack pointer, which is relative to the memory region start.
|
|
stack_ptr: usize,
|
|
/// The region of memory allocated to the process.
|
|
mem_region: MemoryRegion,
|
|
/// Process priority. Lower number is higher priority.
|
|
prio: u16,
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub unsafe fn context_switch() -> ! {
|
|
#[allow(unused_unsafe)]
|
|
unsafe {
|
|
loop {
|
|
asm::halt();
|
|
}
|
|
}
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub enum ProcessState {
|
|
Running,
|
|
Waiting,
|
|
Sleeping,
|
|
Suspended,
|
|
}
|
|
|
|
// Interprocess communication system:
|
|
// Processes communicate through "sessions" which are mediated by the kernel.
|
|
// Sessions can only be opened if two processes both request a session with
|
|
// each other (mutual operation). Submitting a session request is a blocking
|
|
// system call that will return either once the other process accepts, or the
|
|
// kernel denies the request due to missing capability, or the other process
|
|
// not existing yet.
|
|
pub struct ProcessSession {
|
|
proc_id_a: u32,
|
|
proc_id_b: u32,
|
|
shared_mem: MemoryRegion,
|
|
}
|
|
|
|
impl ProcessSession {
|
|
pub fn new(a: ProcessSessionRequest, b: ProcessSessionRequest) -> Self {
|
|
ProcessSession {
|
|
proc_id_a: a.proc_id,
|
|
proc_id_b: b.proc_id,
|
|
shared_mem: MemoryRegion::new(
|
|
MemoryRegionFlags::Readable | MemoryRegionFlags::Writable,
|
|
),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct ProcessSessionRequest {
|
|
proc_id: u32,
|
|
}
|
|
|
|
impl ProcessSessionRequest {
|
|
pub fn accept(self, b: ProcessSessionRequest) -> ProcessSession {
|
|
ProcessSession::new(self, b)
|
|
}
|
|
}
|