Skip to main content

Module process

Module process 

Source
Expand description

Process Management Module

Chapter 6 - Process Management Experiment

Modules§

context
elf
ELF64 parser for user program loading.
pcb
pid
scheduler
state
PTA Exercise: Process state machine using Rust enum + match. Students implement ProcessState, Event, and next_state().
switch
Context switch assembly — bootstrap only.
user
User-mode task creation and address space management.
user_elf
Minimal RISC-V ELF64 user program embedded in the kernel.

Structs§

ProcessContext
ProcessControlBlock
ProcessId
RoundRobinScheduler
SCHEDULER

Enums§

ProcessState

Constants§

PROCESS_CONTEXT_SATP_OFFSET
PROCESS_CONTEXT_SEPC_OFFSET
PROCESS_CONTEXT_SSTATUS_OFFSET

Functions§

create_kernel_task⚠
Create a kernel task PCB backed by the supplied stack.
debug_scheduler_state
exec_current
Replace the current process image with a new ELF loaded from path. FD table is preserved; address space and context are rebuilt.
exec_current_into_trap_frame
Replace the current image and, on success, copy the new process context into the live trap frame that trap_return will restore.
exit_current_and_switch
Exit the current process. Does NOT return — jumps to trap_return.
fork_current
Fork the current user process by deep-copying the parent’s user pages. Returns child PID (to parent) or 0 (to child).
init_frame_allocator_from
kernel_page_table_paddr
scheduler_tick
Called on every timer tick with the current trap frame. If the scheduler picks a different task, the trap frame is updated in-place so that trap_return resumes the new task.
set_kernel_page_table_paddr
start_first_task⚠
Safety
wait_current
Wait for any child to exit. If a zombie exists, returns its PID. If children exist but none are zombies, blocks the current process and jumps directly to trap_return (does NOT return). If no ready task can run while the parent is blocked, returns EBUSY instead of parking the parent without a runnable handoff. Returns -1 if no children exist.
with_frame_allocator