FreeNOS
|
Represents a process which may run on the host. More...
#include <Process.h>
Public Types | |
enum | Result { Success, InvalidArgument, MemoryMapError, OutOfMemory, WakeupPending } |
Result codes. More... | |
enum | State { Ready, Sleeping, Waiting, Stopped } |
Represents the execution state of the Process. More... | |
Public Member Functions | |
Process (ProcessID id, Address entry, bool privileged, const MemoryMap &map) | |
Constructor function. More... | |
virtual | ~Process () |
Destructor function. More... | |
ProcessID | getID () const |
Retrieve our ID number. More... | |
ProcessID | getParent () const |
Retrieve our parent ID. More... | |
ProcessID | getWait () const |
Get Wait ID. More... | |
uint | getWaitResult () const |
Get wait result. More... | |
ProcessShares & | getShares () |
Get process shares. More... | |
State | getState () const |
Retrieves the current state. More... | |
MemoryContext * | getMemoryContext () |
Get MMU memory context. More... | |
bool | isPrivileged () const |
Get privilege. More... | |
bool | operator== (Process *proc) |
Compare two processes. More... | |
Protected Member Functions | |
virtual Result | initialize () |
Initialize the Process. More... | |
virtual void | reset (const Address entry)=0 |
Restart execution at the given entry point. More... | |
virtual void | execute (Process *previous)=0 |
Allow the Process to run on the CPU. More... | |
Result | wakeup () |
Prevent process from sleeping. More... | |
Result | sleep (const Timer::Info *timer, bool ignoreWakeups) |
Stops the process for executing until woken up. More... | |
Result | wait (ProcessID id) |
Let Process wait for other Process to terminate. More... | |
virtual Result | join (const uint result) |
Complete waiting for another Process. More... | |
Result | stop () |
Stop execution of this process. More... | |
Result | resume () |
Resume execution when this process is stopped. More... | |
Result | raiseEvent (const struct ProcessEvent *event) |
Raise kernel event. More... | |
const Timer::Info & | getSleepTimer () const |
Get sleep timer. More... | |
void | setParent (ProcessID id) |
Set parent process ID. More... | |
Protected Attributes | |
const ProcessID | m_id |
Process Identifier. More... | |
ProcessID | m_parent |
Parent process. More... | |
State | m_state |
Current process status. More... | |
ProcessID | m_waitId |
Waits for exit of this Process. More... | |
uint | m_waitResult |
Wait exit result of the other Process. More... | |
bool | m_privileged |
Privilege level. More... | |
Address | m_entry |
Entry point of the program. More... | |
MemoryMap | m_map |
Virtual memory layout. More... | |
MemoryContext * | m_memoryContext |
MMU memory context. More... | |
Size | m_wakeups |
Number of wakeups received. More... | |
Timer::Info | m_sleepTimer |
Sleep timer value. More... | |
ProcessShares | m_shares |
Contains virtual memory shares between this process and others. More... | |
MemoryChannel * | m_kernelChannel |
Channel for sending kernel events to the Process. More... | |
Friends | |
class | ProcessManager |
class | Scheduler |
enum Process::Result |
enum Process::State |
Constructor function.
id | Process Identifier |
entry | Initial program counter value. |
privileged | If true, the process has unlimited access to hardware. |
map | Memory map to use |
Definition at line 26 of file Process.cpp.
References entry, m_entry, m_kernelChannel, m_memoryContext, m_parent, m_privileged, m_sleepTimer, m_state, m_waitId, m_waitResult, m_wakeups, MemoryBlock::set(), Stopped, and ZERO.
|
virtual |
Destructor function.
Definition at line 41 of file Process.cpp.
References m_kernelChannel, m_map, m_memoryContext, MemoryMap::range(), MemoryContext::releaseSection(), MemoryMap::UserArgs, MemoryMap::UserData, MemoryMap::UserHeap, MemoryMap::UserPrivate, MemoryMap::UserShare, and MemoryMap::UserStack.
|
protectedpure virtual |
Allow the Process to run on the CPU.
previous | The previous Process which ran on the CPU. ZERO if none. |
Implemented in ARMProcess, and IntelProcess.
Referenced by ProcessManager::schedule().
ProcessID Process::getID | ( | ) | const |
Retrieve our ID number.
Definition at line 60 of file Process.cpp.
References m_id.
Referenced by ProcessManager::create(), ARMKernel::dataAbort(), Scheduler::dequeue(), ProcessManager::dequeueProcess(), Scheduler::enqueue(), ProcessManager::enqueueProcess(), IntelKernel::exception(), SunxiKernel::interrupt(), ARMKernel::interrupt(), RaspberryKernel::interrupt(), operator==(), ARMKernel::prefetchAbort(), ProcessCtlHandler(), ProcessManager::raiseEvent(), ProcessManager::remove(), ARMKernel::reserved(), ProcessManager::resume(), ProcessManager::schedule(), ProcessManager::setIdle(), ProcessManager::sleep(), ProcessManager::stop(), ARMKernel::trap(), ARMKernel::undefinedInstruction(), ProcessManager::wait(), and ProcessManager::wakeup().
MemoryContext * Process::getMemoryContext | ( | ) |
Get MMU memory context.
Definition at line 95 of file Process.cpp.
References m_memoryContext.
Referenced by Kernel::getMemoryContext(), Kernel::loadBootProgram(), VMCopyHandler(), and VMCtlHandler().
ProcessID Process::getParent | ( | ) | const |
Retrieve our parent ID.
Definition at line 65 of file Process.cpp.
References m_parent.
Referenced by ProcessCtlHandler().
ProcessShares & Process::getShares | ( | ) |
Get process shares.
Definition at line 85 of file Process.cpp.
References m_shares.
Referenced by ProcessShares::releaseShare(), and VMShareHandler().
|
protected |
Get sleep timer.
Definition at line 90 of file Process.cpp.
References m_sleepTimer.
Referenced by ProcessManager::schedule().
Process::State Process::getState | ( | ) | const |
Retrieves the current state.
Definition at line 80 of file Process.cpp.
References m_state.
Referenced by Scheduler::dequeue(), Scheduler::enqueue(), ProcessCtlHandler(), ProcessManager::remove(), and ProcessManager::stop().
ProcessID Process::getWait | ( | ) | const |
uint Process::getWaitResult | ( | ) | const |
Get wait result.
Definition at line 75 of file Process.cpp.
References m_waitResult.
Referenced by ProcessCtlHandler().
|
protectedvirtual |
Initialize the Process.
Allocates various (architecture specific) resources, creates MMU context and stacks.
Reimplemented in ARMProcess, and IntelProcess.
Definition at line 172 of file Process.cpp.
References Memory::Range::access, Allocator::Range::address, Allocator::Range::alignment, Cache::cleanData(), coreId, ProcessShares::createShare(), ERROR, MemoryContext::findFree(), WeakSingleton< Kernel >::instance(), KERNEL_PID, m_kernelChannel, m_memoryContext, m_shares, MemoryContext::map(), MemoryContext::mapRangeContiguous(), OutOfMemory, PAGESIZE, Memory::Range::phys, Channel::Producer, Memory::Readable, MemoryBlock::set(), ProcessShares::setMemoryContext(), MemoryChannel::setVirtual(), Memory::Range::size, Allocator::Range::size, Allocator::Success, Success, MemoryContext::unmap(), Memory::User, MemoryMap::UserShare, Memory::Range::virt, and Memory::Writable.
Referenced by ProcessManager::create(), IntelProcess::initialize(), and ARMProcess::initialize().
bool Process::isPrivileged | ( | ) | const |
Get privilege.
Definition at line 100 of file Process.cpp.
References m_privileged.
|
protectedvirtual |
Complete waiting for another Process.
result | Exit code of the other process |
Reimplemented in ARMProcess.
Definition at line 124 of file Process.cpp.
References ERROR, InvalidArgument, m_id, m_state, m_waitResult, Ready, Success, and Waiting.
Referenced by ARMProcess::join().
bool Process::operator== | ( | Process * | proc | ) |
Compare two processes.
proc | Process to compare with. |
Definition at line 265 of file Process.cpp.
|
protected |
Raise kernel event.
Definition at line 161 of file Process.cpp.
References MemoryChannel::flush(), m_kernelChannel, wakeup(), and MemoryChannel::write().
Referenced by ProcessManager::raiseEvent().
|
protectedpure virtual |
Restart execution at the given entry point.
entry | Address to begin execution. |
Implemented in ARMProcess, and IntelProcess.
Referenced by ProcessManager::reset().
|
protected |
Resume execution when this process is stopped.
Definition at line 149 of file Process.cpp.
References ERROR, InvalidArgument, m_id, m_state, Ready, Stopped, and Success.
Referenced by ProcessManager::resume().
|
protected |
Set parent process ID.
Definition at line 105 of file Process.cpp.
References m_parent.
Referenced by ProcessManager::create().
|
protected |
Stops the process for executing until woken up.
timer | Timer on which the process must be woken up (if expired), or ZERO for no limit |
ignoreWakeups | True to enter Sleep state regardless of pending wakeups |
Definition at line 244 of file Process.cpp.
References MemoryBlock::copy(), ERROR, InvalidArgument, m_id, m_sleepTimer, m_state, m_wakeups, Ready, Sleeping, Success, and WakeupPending.
Referenced by ProcessManager::sleep().
|
protected |
Stop execution of this process.
Definition at line 137 of file Process.cpp.
References ERROR, InvalidArgument, m_id, m_state, Ready, Sleeping, Stopped, and Success.
Referenced by ProcessManager::stop().
|
protected |
Let Process wait for other Process to terminate.
id | Process ID to wait for |
Definition at line 110 of file Process.cpp.
References ERROR, InvalidArgument, m_id, m_state, m_waitId, Ready, Success, and Waiting.
Referenced by ProcessManager::wait().
|
protected |
Prevent process from sleeping.
Definition at line 224 of file Process.cpp.
References m_sleepTimer, m_state, m_wakeups, Ready, MemoryBlock::set(), Sleeping, Success, and WakeupPending.
Referenced by raiseEvent(), and ProcessManager::wakeup().
|
friend |
|
protected |
Entry point of the program.
Definition at line 265 of file Process.h.
Referenced by IntelProcess::initialize(), ARMProcess::initialize(), Process(), and IntelProcess::reset().
|
protected |
|
protected |
Channel for sending kernel events to the Process.
Definition at line 287 of file Process.h.
Referenced by initialize(), Process(), raiseEvent(), and ~Process().
|
protected |
Virtual memory layout.
Definition at line 268 of file Process.h.
Referenced by IntelProcess::initialize(), ARMProcess::initialize(), IntelProcess::reset(), ARMProcess::reset(), and ~Process().
|
protected |
MMU memory context.
Definition at line 271 of file Process.h.
Referenced by IntelProcess::execute(), ARMProcess::execute(), getMemoryContext(), IntelProcess::initialize(), ARMProcess::initialize(), initialize(), Process(), and ~Process().
|
protected |
Parent process.
Definition at line 250 of file Process.h.
Referenced by getParent(), Process(), and setParent().
|
protected |
Privilege level.
Definition at line 262 of file Process.h.
Referenced by isPrivileged(), Process(), IntelProcess::reset(), and ARMProcess::reset().
|
protected |
Contains virtual memory shares between this process and others.
Definition at line 284 of file Process.h.
Referenced by getShares(), and initialize().
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |