FreeNOS
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends
Process Class Referenceabstract

Represents a process which may run on the host. More...

#include <Process.h>

Inheritance diagram for Process:
ARMProcess IntelProcess

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...
 
ProcessSharesgetShares ()
 Get process shares. More...
 
State getState () const
 Retrieves the current state. More...
 
MemoryContextgetMemoryContext ()
 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::InfogetSleepTimer () 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...
 
MemoryContextm_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...
 
MemoryChannelm_kernelChannel
 Channel for sending kernel events to the Process. More...
 

Friends

class ProcessManager
 
class Scheduler
 

Detailed Description

Represents a process which may run on the host.

Definition at line 44 of file Process.h.

Member Enumeration Documentation

◆ Result

Result codes.

Enumerator
Success 
InvalidArgument 
MemoryMapError 
OutOfMemory 
WakeupPending 

Definition at line 54 of file Process.h.

◆ State

Represents the execution state of the Process.

Enumerator
Ready 
Sleeping 
Waiting 
Stopped 

Definition at line 66 of file Process.h.

Constructor & Destructor Documentation

◆ Process()

Process::Process ( ProcessID  id,
Address  entry,
bool  privileged,
const MemoryMap map 
)

Constructor function.

Parameters
idProcess Identifier
entryInitial program counter value.
privilegedIf true, the process has unlimited access to hardware.
mapMemory 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.

◆ ~Process()

Process::~Process ( )
virtual

Member Function Documentation

◆ execute()

virtual void Process::execute ( Process previous)
protectedpure virtual

Allow the Process to run on the CPU.

Parameters
previousThe previous Process which ran on the CPU. ZERO if none.

Implemented in ARMProcess, and IntelProcess.

Referenced by ProcessManager::schedule().

◆ getID()

ProcessID Process::getID ( ) const

◆ getMemoryContext()

MemoryContext * Process::getMemoryContext ( )

Get MMU memory context.

Returns
MemoryContext pointer.

Definition at line 95 of file Process.cpp.

References m_memoryContext.

Referenced by Kernel::getMemoryContext(), Kernel::loadBootProgram(), VMCopyHandler(), and VMCtlHandler().

◆ getParent()

ProcessID Process::getParent ( ) const

Retrieve our parent ID.

Returns
Process ID of our parent.

Definition at line 65 of file Process.cpp.

References m_parent.

Referenced by ProcessCtlHandler().

◆ getShares()

ProcessShares & Process::getShares ( )

Get process shares.

Returns
Reference to memory shares.

Definition at line 85 of file Process.cpp.

References m_shares.

Referenced by ProcessShares::releaseShare(), and VMShareHandler().

◆ getSleepTimer()

const Timer::Info & Process::getSleepTimer ( ) const
protected

Get sleep timer.

Returns
Sleep timer value.

Definition at line 90 of file Process.cpp.

References m_sleepTimer.

Referenced by ProcessManager::schedule().

◆ getState()

Process::State Process::getState ( ) const

Retrieves the current state.

Returns
Current status of the Process.

Definition at line 80 of file Process.cpp.

References m_state.

Referenced by Scheduler::dequeue(), Scheduler::enqueue(), ProcessCtlHandler(), ProcessManager::remove(), and ProcessManager::stop().

◆ getWait()

ProcessID Process::getWait ( ) const

Get Wait ID.

Definition at line 70 of file Process.cpp.

References m_waitId.

◆ getWaitResult()

uint Process::getWaitResult ( ) const

Get wait result.

Definition at line 75 of file Process.cpp.

References m_waitResult.

Referenced by ProcessCtlHandler().

◆ initialize()

Process::Result Process::initialize ( )
protectedvirtual

◆ isPrivileged()

bool Process::isPrivileged ( ) const

Get privilege.

Returns
Privilege of the Process.

Definition at line 100 of file Process.cpp.

References m_privileged.

◆ join()

Process::Result Process::join ( const uint  result)
protectedvirtual

Complete waiting for another Process.

Parameters
resultExit 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().

◆ operator==()

bool Process::operator== ( Process proc)

Compare two processes.

Parameters
procProcess to compare with.
Returns
True if equal, false otherwise.

Definition at line 265 of file Process.cpp.

References getID(), and m_id.

◆ raiseEvent()

Process::Result Process::raiseEvent ( const struct ProcessEvent event)
protected

Raise kernel event.

Returns
Result code

Definition at line 161 of file Process.cpp.

References MemoryChannel::flush(), m_kernelChannel, wakeup(), and MemoryChannel::write().

Referenced by ProcessManager::raiseEvent().

◆ reset()

virtual void Process::reset ( const Address  entry)
protectedpure virtual

Restart execution at the given entry point.

Parameters
entryAddress to begin execution.

Implemented in ARMProcess, and IntelProcess.

Referenced by ProcessManager::reset().

◆ resume()

Process::Result Process::resume ( )
protected

Resume execution when this process is stopped.

Returns
Result code

Definition at line 149 of file Process.cpp.

References ERROR, InvalidArgument, m_id, m_state, Ready, Stopped, and Success.

Referenced by ProcessManager::resume().

◆ setParent()

void Process::setParent ( ProcessID  id)
protected

Set parent process ID.

Definition at line 105 of file Process.cpp.

References m_parent.

Referenced by ProcessManager::create().

◆ sleep()

Process::Result Process::sleep ( const Timer::Info timer,
bool  ignoreWakeups 
)
protected

Stops the process for executing until woken up.

Parameters
timerTimer on which the process must be woken up (if expired), or ZERO for no limit
ignoreWakeupsTrue to enter Sleep state regardless of pending wakeups
Returns
Result code

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().

◆ stop()

Process::Result Process::stop ( )
protected

Stop execution of this process.

Returns
Result code

Definition at line 137 of file Process.cpp.

References ERROR, InvalidArgument, m_id, m_state, Ready, Sleeping, Stopped, and Success.

Referenced by ProcessManager::stop().

◆ wait()

Process::Result Process::wait ( ProcessID  id)
protected

Let Process wait for other Process to terminate.

Parameters
idProcess ID to wait for
Returns
Result code

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().

◆ wakeup()

Process::Result Process::wakeup ( )
protected

Prevent process from sleeping.

Returns
Result code

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().

Friends And Related Function Documentation

◆ ProcessManager

friend class ProcessManager
friend

Definition at line 46 of file Process.h.

◆ Scheduler

friend class Scheduler
friend

Definition at line 47 of file Process.h.

Field Documentation

◆ m_entry

Address Process::m_entry
protected

Entry point of the program.

Definition at line 265 of file Process.h.

Referenced by IntelProcess::initialize(), ARMProcess::initialize(), Process(), and IntelProcess::reset().

◆ m_id

const ProcessID Process::m_id
protected

Process Identifier.

Definition at line 247 of file Process.h.

Referenced by getID(), join(), operator==(), resume(), sleep(), stop(), and wait().

◆ m_kernelChannel

MemoryChannel* Process::m_kernelChannel
protected

Channel for sending kernel events to the Process.

Definition at line 287 of file Process.h.

Referenced by initialize(), Process(), raiseEvent(), and ~Process().

◆ m_map

MemoryMap Process::m_map
protected

Virtual memory layout.

Definition at line 268 of file Process.h.

Referenced by IntelProcess::initialize(), ARMProcess::initialize(), IntelProcess::reset(), ARMProcess::reset(), and ~Process().

◆ m_memoryContext

MemoryContext* Process::m_memoryContext
protected

◆ m_parent

ProcessID Process::m_parent
protected

Parent process.

Definition at line 250 of file Process.h.

Referenced by getParent(), Process(), and setParent().

◆ m_privileged

bool Process::m_privileged
protected

Privilege level.

Definition at line 262 of file Process.h.

Referenced by isPrivileged(), Process(), IntelProcess::reset(), and ARMProcess::reset().

◆ m_shares

ProcessShares Process::m_shares
protected

Contains virtual memory shares between this process and others.

Definition at line 284 of file Process.h.

Referenced by getShares(), and initialize().

◆ m_sleepTimer

Timer::Info Process::m_sleepTimer
protected

Sleep timer value.

If non-zero, set the process in the Ready state when the System timer is greater than this value.

Definition at line 281 of file Process.h.

Referenced by getSleepTimer(), Process(), sleep(), and wakeup().

◆ m_state

State Process::m_state
protected

Current process status.

Definition at line 253 of file Process.h.

Referenced by getState(), join(), Process(), resume(), sleep(), stop(), wait(), and wakeup().

◆ m_waitId

ProcessID Process::m_waitId
protected

Waits for exit of this Process.

Definition at line 256 of file Process.h.

Referenced by getWait(), Process(), and wait().

◆ m_waitResult

uint Process::m_waitResult
protected

Wait exit result of the other Process.

Definition at line 259 of file Process.h.

Referenced by getWaitResult(), join(), and Process().

◆ m_wakeups

Size Process::m_wakeups
protected

Number of wakeups received.

Definition at line 274 of file Process.h.

Referenced by Process(), sleep(), and wakeup().


The documentation for this class was generated from the following files: