The Pedigree Project  0.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
Process Class Reference

#include <Process.h>

+ Inheritance diagram for Process:
+ Collaboration diagram for Process:

Classes

struct  ProcessMetadata
 

Public Types

enum  ProcessType { Stock, Posix }
 
enum  ProcessState {
  Active, Suspended, Terminating, Terminated,
  Reaped
}
 

Public Member Functions

 Process ()
 
 Process (Process *pParent, bool bCopyOnWrite=true)
 
virtual ~Process ()
 
size_t addThread (Thread *pThread)
 
void removeThread (Thread *pThread)
 
size_t getNumThreads ()
 
ThreadgetThread (size_t n)
 
size_t getId ()
 
LargeStaticStringdescription ()
 
VirtualAddressSpacegetAddressSpace ()
 
void setExitStatus (int code)
 
int getExitStatus ()
 
void reap ()
 
void kill () NORETURN
 
void suspend ()
 
void resume ()
 
ProcessgetParent ()
 
FilegetCwd ()
 
void setCwd (File *f)
 
FilegetCtty ()
 
void setCtty (File *f)
 
MemoryAllocatorgetSpaceAllocator ()
 
MemoryAllocatorgetDynamicSpaceAllocator ()
 
UsergetUser () const
 
void setUser (User *pUser)
 
UsergetEffectiveUser () const
 
void setEffectiveUser (User *pUser)
 
GroupgetGroup () const
 
void setGroup (Group *pGroup)
 
GroupgetEffectiveGroup () const
 
void setEffectiveGroup (Group *pGroup)
 
virtual int64_t getUserId () const
 
virtual int64_t getGroupId () const
 
virtual int64_t getEffectiveUserId () const
 
virtual int64_t getEffectiveGroupId () const
 
virtual void getSupplementalGroupIds (Vector< int64_t > &vec) const
 
void setLinker (DynamicLinker *pDl)
 
DynamicLinkergetLinker ()
 
void setSubsystem (Subsystem *pSubsystem)
 
SubsystemgetSubsystem ()
 
virtual ProcessType getType ()
 
void addWaiter (Semaphore *pWaiter)
 
void removeWaiter (Semaphore *pWaiter)
 
size_t waiterCount () const
 
bool hasSuspended ()
 
bool hasResumed ()
 
ProcessState getState () const
 
void markTerminating ()
 
void trackHeap (ssize_t nBytes)
 
void trackPages (ssize_t nVirtual, ssize_t nPhysical, ssize_t nShared)
 
void resetCounts ()
 
void recordTime (bool bUserspace)
 
void trackTime (bool bUserspace)
 
Time::Timestamp getUserTime () const
 
Time::Timestamp getKernelTime () const
 
Time::Timestamp getStartTime () const
 
ssize_t getHeapUsage () const
 
ssize_t getVirtualPageCount () const
 
ssize_t getPhysicalPageCount () const
 
ssize_t getSharedPageCount () const
 
void setRootFile (File *pFile)
 
FilegetRootFile () const
 
bool hasSharedAddressSpace () const
 

Static Public Member Functions

static ProcessgetInit ()
 
static void setInit (Process *pProcess)
 

Public Attributes

Semaphore m_DeadThreads
 

Private Member Functions

 Process (const Process &)
 
Processoperator= (const Process &)
 
virtual void reportTimesUpdated (Time::Timestamp user, Time::Timestamp system)
 
virtual void processTerminated ()
 
void notifyWaiters ()
 

Private Attributes

Vector< Thread * > m_Threads
 
Atomic< size_t > m_NextTid
 
size_t m_Id
 
LargeStaticString str
 
Processm_pParent
 
VirtualAddressSpacem_pAddressSpace
 
int m_ExitStatus
 
Filem_Cwd
 
Filem_Ctty
 
MemoryAllocator m_SpaceAllocator
 
MemoryAllocator m_DynamicSpaceAllocator
 
Userm_pUser
 
Groupm_pGroup
 
Userm_pEffectiveUser
 
Groupm_pEffectiveGroup
 
DynamicLinkerm_pDynamicLinker
 
Subsystemm_pSubsystem
 
List< Semaphore * > m_Waiters
 
bool m_bUnreportedSuspend
 
bool m_bUnreportedResume
 
ProcessState m_State
 
Thread::Status m_BeforeSuspendState
 
Spinlock m_Lock
 
struct Process::ProcessMetadata m_Metadata
 
Time::Timestamp m_LastKernelEntry
 
Time::Timestamp m_LastUserspaceEntry
 
Filem_pRootFile
 
bool m_bSharedAddressSpace
 

Static Private Attributes

static Processm_pInitProcess = 0
 

Friends

class Thread
 

Detailed Description

An abstraction of a Process - a container for one or more threads all running in the same address space.

Definition at line 50 of file Process.h.

Member Enumeration Documentation

Processes have their own state, aside from the state of their threads. These states are very general and don't reflect the current scheduling state of the process as a whole in intricate detail.

Definition at line 72 of file Process.h.

Subsystems may inherit Process to provide custom functionality. However, they need to know whether a Process pointer is subsystem-specific. This enumeration is designed to allow functions using Process objects in subsystems with inherited Process objects to be able to figure out what type the Process is without depending on any external accounting.

Definition at line 61 of file Process.h.

Constructor & Destructor Documentation

Process::Process ( )
Process::Process ( Process pParent,
bool  bCopyOnWrite = true 
)

Constructor for creating a new Process. Creates a new Process as a UNIX fork() would, from the given parent process. This constructor does not create any threads.

Parameters
pParentThe parent process.
bCopyOnWriteWhether to mark the address space copy-on-write (default) or to share it read/write with the new child.

Definition at line 78 of file Process.cc.

References Scheduler::addProcess(), VirtualAddressSpace::clone(), Scheduler::instance(), m_bSharedAddressSpace, m_Id, m_pAddressSpace, m_pParent, and str.

Process::~Process ( )
virtual

Member Function Documentation

size_t Process::addThread ( Thread pThread)

Adds a thread to this process.

Returns
The thread ID to be assigned to the new Thread.

Definition at line 189 of file Process.cc.

References m_Lock, m_NextTid, m_Threads, and Vector< T >::pushBack().

Referenced by Thread::Thread().

+ Here is the caller graph for this function:

LargeStaticString& Process::description ( )
inline

Returns the description string of this process.

Definition at line 114 of file Process.h.

Referenced by ThreadsCommand::execute(), PosixSubsystem::invoke(), and Rtc::irq().

+ Here is the caller graph for this function:

VirtualAddressSpace* Process::getAddressSpace ( )
inline
File* Process::getCtty ( )
inline

Returns the current controlling terminal.

Definition at line 167 of file Process.h.

File* Process::getCwd ( )
inline

Returns the current working directory.

Definition at line 156 of file Process.h.

Referenced by PosixSubsystem::findFile().

+ Here is the caller graph for this function:

MemoryAllocator& Process::getDynamicSpaceAllocator ( )
inline

Returns the memory space allocator for dynamic address space.

Definition at line 183 of file Process.h.

Referenced by Elf::allocate(), Thread::getTlsBase(), PosixSubsystem::invoke(), Process(), MemoryMapManager::sanitiseAddress(), and Thread::~Thread().

+ Here is the caller graph for this function:

Group* Process::getEffectiveGroup ( ) const
inline

Gets the current effective group.

Definition at line 222 of file Process.h.

References Subsystem::setProcess().

Referenced by getUserId().

+ Here is the caller graph for this function:

User* Process::getEffectiveUser ( ) const
inline

Gets the effective user.

Definition at line 200 of file Process.h.

Referenced by getUserId().

+ Here is the caller graph for this function:

int Process::getExitStatus ( )
inline

Gets the exit status of the process.

Definition at line 131 of file Process.h.

Referenced by PosixSubsystem::exit(), and WaitCleanup::terminated().

+ Here is the caller graph for this function:

Group* Process::getGroup ( ) const
inline

Gets the current group.

Definition at line 211 of file Process.h.

Referenced by ProcFs::addProcess(), and getUserId().

+ Here is the caller graph for this function:

ssize_t Process::getHeapUsage ( ) const
inline

Get process usage.

Definition at line 372 of file Process.h.

Referenced by Rtc::irq().

+ Here is the caller graph for this function:

size_t Process::getId ( )
inline
Process * Process::getInit ( )
static

Get the init process (first userspace process, parent of all userspace processes).

Definition at line 394 of file Process.cc.

References m_pInitProcess.

Referenced by kill().

+ Here is the caller graph for this function:

size_t Process::getNumThreads ( )

Returns the number of threads in this process.

Definition at line 219 of file Process.cc.

References Vector< T >::count(), m_Lock, and m_Threads.

Referenced by ThreadsCommand::execute(), and PosixSubsystem::invoke().

+ Here is the caller graph for this function:

Process* Process::getParent ( )
inline

Returns the parent process.

Definition at line 150 of file Process.h.

References Thread::m_pParent.

Referenced by PosixSubsystem::exit(), and WaitCleanup::terminated().

+ Here is the caller graph for this function:

File* Process::getRootFile ( ) const
inline

Get this process' root.

Definition at line 396 of file Process.h.

Referenced by Filesystem::getTrueRoot().

+ Here is the caller graph for this function:

MemoryAllocator& Process::getSpaceAllocator ( )
inline

Returns the memory space allocator for primary address space.

Definition at line 178 of file Process.h.

Referenced by Elf::allocate(), Thread::getTlsBase(), PosixSubsystem::invoke(), Process(), MemoryMapManager::sanitiseAddress(), and Thread::~Thread().

+ Here is the caller graph for this function:

Thread * Process::getThread ( size_t  n)
virtual ProcessType Process::getType ( )
inlinevirtual

Gets the type of the Process (subsystems may override)

Reimplemented in PosixProcess.

Definition at line 259 of file Process.h.

Referenced by PosixSubsystem::exit(), PosixSubsystem::invoke(), PosixSubsystem::kill(), PosixProcess::PosixProcess(), and WaitCleanup::terminated().

+ Here is the caller graph for this function:

User* Process::getUser ( ) const
inline

Gets the current user.

Definition at line 189 of file Process.h.

Referenced by ProcFs::addProcess(), and getUserId().

+ Here is the caller graph for this function:

int64_t Process::getUserId ( ) const
virtual
Time::Timestamp Process::getUserTime ( ) const
inline

Gets timestamps.

Definition at line 358 of file Process.h.

Referenced by WaitCleanup::terminated().

+ Here is the caller graph for this function:

bool Process::hasSharedAddressSpace ( ) const
inline

Get whether this process has a shared address space with its parent. Copy-on-write (i.e. not shared) is the default for processes.

Definition at line 405 of file Process.h.

References Thread::operator=().

void Process::kill ( )
void Process::notifyWaiters ( )
private

Releases all locks in m_Waiters once.

Definition at line 385 of file Process.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), and m_Waiters.

Referenced by resume(), Thread::setStatus(), and suspend().

+ Here is the caller graph for this function:

virtual void Process::processTerminated ( )
inlineprivatevirtual

Called when the process is terminated to allow for subclass cleanup.

Reimplemented in PosixProcess.

Definition at line 430 of file Process.h.

Referenced by kill().

+ Here is the caller graph for this function:

void Process::reap ( )
inline

Marks the process as reaped.

Definition at line 137 of file Process.h.

References NORETURN.

Referenced by WaitCleanup::terminated().

+ Here is the caller graph for this function:

void Process::recordTime ( bool  bUserspace)
inline

Record the current time in the relevant field for this process.

Use to set the point in time from which the next difference will be taken.

Definition at line 317 of file Process.h.

Referenced by PerProcessorScheduler::addThread(), PerProcessorScheduler::checkEventState(), PosixSubsystem::invoke(), and PerProcessorScheduler::schedule().

+ Here is the caller graph for this function:

void Process::removeThread ( Thread pThread)

Removes a thread from this process.

Definition at line 198 of file Process.cc.

References Vector< T >::begin(), Vector< T >::end(), Vector< T >::erase(), m_Lock, m_pSubsystem, m_State, m_Threads, and Subsystem::threadRemoved().

Referenced by Thread::~Thread().

+ Here is the caller graph for this function:

virtual void Process::reportTimesUpdated ( Time::Timestamp  user,
Time::Timestamp  system 
)
inlineprivatevirtual

Called when process times are updated.

Reimplemented in PosixProcess.

Definition at line 425 of file Process.h.

void Process::resume ( )

Resumes the process from suspend.

Definition at line 311 of file Process.cc.

References Processor::information(), m_bUnreportedResume, m_ExitStatus, m_State, and notifyWaiters().

void Process::setCtty ( File f)
inline

Sets the controlling terminal.

Definition at line 172 of file Process.h.

Referenced by WaitCleanup::terminated().

+ Here is the caller graph for this function:

void Process::setCwd ( File f)
inline

Sets the current working directory.

Definition at line 161 of file Process.h.

void Process::setEffectiveUser ( User pUser)
inline

Sets the effective user.

Definition at line 205 of file Process.h.

Referenced by User::login().

+ Here is the caller graph for this function:

void Process::setExitStatus ( int  code)
inline

Sets the exit status of the process.

Definition at line 126 of file Process.h.

Referenced by PosixSubsystem::exit().

+ Here is the caller graph for this function:

void Process::setGroup ( Group pGroup)
inline

Sets the current group.

Definition at line 216 of file Process.h.

Referenced by UserManager::initialise(), and User::login().

+ Here is the caller graph for this function:

void Process::setInit ( Process pProcess)
static

Set the init process.

Definition at line 399 of file Process.cc.

References m_pInitProcess.

void Process::setRootFile ( File pFile)
inline

Set this process' root.

Definition at line 390 of file Process.h.

void Process::setUser ( User pUser)
inline

Sets the current user.

Definition at line 194 of file Process.h.

Referenced by UserManager::initialise(), and User::login().

+ Here is the caller graph for this function:

void Process::suspend ( )
void Process::trackTime ( bool  bUserspace)
inline

Counts the time spent since the last recordTime(), and then updates the relevant time field to the current time.

Use when scheduling.

Definition at line 336 of file Process.h.

Referenced by PerProcessorScheduler::addThread(), PerProcessorScheduler::checkEventState(), and PerProcessorScheduler::schedule().

+ Here is the caller graph for this function:

Member Data Documentation

Thread::Status Process::m_BeforeSuspendState
private

State we were in before suspend. Ensures if we were sleeping before, we still will be after a resume.

Definition at line 509 of file Process.h.

Referenced by suspend().

bool Process::m_bSharedAddressSpace
private

Is our address space shared with the parent?

Definition at line 555 of file Process.h.

Referenced by Process().

bool Process::m_bUnreportedResume
private

Whether we have resumed but not reported it.

Definition at line 500 of file Process.h.

Referenced by resume().

bool Process::m_bUnreportedSuspend
private

Whether we have suspended but not reported it.

Definition at line 497 of file Process.h.

Referenced by suspend().

File* Process::m_Ctty
private

Current controlling terminal.

Definition at line 469 of file Process.h.

File* Process::m_Cwd
private

Current working directory.

Definition at line 465 of file Process.h.

MemoryAllocator Process::m_DynamicSpaceAllocator
private

Memory allocator for dynamic address space, if any.

Definition at line 477 of file Process.h.

int Process::m_ExitStatus
private

Process exit status.

Definition at line 461 of file Process.h.

Referenced by resume(), and suspend().

size_t Process::m_Id
private

Our Process ID.

Definition at line 445 of file Process.h.

Referenced by kill(), and Process().

Time::Timestamp Process::m_LastKernelEntry
private

Last time we entered the kernel.

Definition at line 546 of file Process.h.

Time::Timestamp Process::m_LastUserspaceEntry
private

Last time we entered userspace.

Definition at line 549 of file Process.h.

Spinlock Process::m_Lock
private
Atomic<size_t> Process::m_NextTid
private

The next available thread ID.

Definition at line 441 of file Process.h.

Referenced by addThread().

VirtualAddressSpace* Process::m_pAddressSpace
private

Our virtual address space.

Definition at line 457 of file Process.h.

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

DynamicLinker* Process::m_pDynamicLinker
private

The Process' dynamic linker.

Definition at line 488 of file Process.h.

Group* Process::m_pEffectiveGroup
private

Effective group.

Definition at line 485 of file Process.h.

User* Process::m_pEffectiveUser
private

Effective user.

Definition at line 483 of file Process.h.

Group* Process::m_pGroup
private

Current group.

Definition at line 481 of file Process.h.

Process * Process::m_pInitProcess = 0
staticprivate

Init process (terminated processes' children will reparent to this).

Definition at line 558 of file Process.h.

Referenced by getInit(), and setInit().

Process* Process::m_pParent
private

Our parent process.

Definition at line 453 of file Process.h.

Referenced by kill(), Process(), and suspend().

File* Process::m_pRootFile
private

Root directory for this process. NULL == system-wide default.

Definition at line 552 of file Process.h.

Subsystem* Process::m_pSubsystem
private

The subsystem for this process

Definition at line 491 of file Process.h.

Referenced by removeThread(), and ~Process().

User* Process::m_pUser
private

Current user.

Definition at line 479 of file Process.h.

MemoryAllocator Process::m_SpaceAllocator
private

Memory allocator for primary address space.

Definition at line 473 of file Process.h.

ProcessState Process::m_State
private

Our current state.

Definition at line 503 of file Process.h.

Referenced by kill(), removeThread(), resume(), suspend(), and ~Process().

Vector<Thread *> Process::m_Threads
private

Our list of threads.

Definition at line 437 of file Process.h.

Referenced by addThread(), getNumThreads(), getThread(), removeThread(), suspend(), and ~Process().

List<Semaphore *> Process::m_Waiters
private

Semaphores to release whenever we are killed, suspended, or resumed.

Definition at line 494 of file Process.h.

Referenced by getUserId(), and notifyWaiters().

LargeStaticString Process::str
private

Our description string.

Definition at line 449 of file Process.h.

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


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