The Pedigree Project
0.1
|
#include <Process.h>
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 () |
Thread * | getThread (size_t n) |
size_t | getId () |
LargeStaticString & | description () |
VirtualAddressSpace * | getAddressSpace () |
void | setExitStatus (int code) |
int | getExitStatus () |
void | reap () |
void | kill () NORETURN |
void | suspend () |
void | resume () |
Process * | getParent () |
File * | getCwd () |
void | setCwd (File *f) |
File * | getCtty () |
void | setCtty (File *f) |
MemoryAllocator & | getSpaceAllocator () |
MemoryAllocator & | getDynamicSpaceAllocator () |
User * | getUser () const |
void | setUser (User *pUser) |
User * | getEffectiveUser () const |
void | setEffectiveUser (User *pUser) |
Group * | getGroup () const |
void | setGroup (Group *pGroup) |
Group * | getEffectiveGroup () 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) |
DynamicLinker * | getLinker () |
void | setSubsystem (Subsystem *pSubsystem) |
Subsystem * | getSubsystem () |
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) |
File * | getRootFile () const |
bool | hasSharedAddressSpace () const |
Static Public Member Functions | |
static Process * | getInit () |
static void | setInit (Process *pProcess) |
Public Attributes | |
Semaphore | m_DeadThreads |
Private Member Functions | |
Process (const Process &) | |
Process & | operator= (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 |
Process * | m_pParent |
VirtualAddressSpace * | m_pAddressSpace |
int | m_ExitStatus |
File * | m_Cwd |
File * | m_Ctty |
MemoryAllocator | m_SpaceAllocator |
MemoryAllocator | m_DynamicSpaceAllocator |
User * | m_pUser |
Group * | m_pGroup |
User * | m_pEffectiveUser |
Group * | m_pEffectiveGroup |
DynamicLinker * | m_pDynamicLinker |
Subsystem * | m_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 |
File * | m_pRootFile |
bool | m_bSharedAddressSpace |
Static Private Attributes | |
static Process * | m_pInitProcess = 0 |
Friends | |
class | Thread |
An abstraction of a Process - a container for one or more threads all running in the same address space.
enum Process::ProcessType |
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.
Process::Process | ( | ) |
Default constructor.
Definition at line 49 of file Process.cc.
References Scheduler::addProcess(), RangeList< T, Reversed >::free(), getAddressSpace(), getDynamicSpaceAllocator(), getSpaceAllocator(), Scheduler::instance(), m_Id, and Process::ProcessMetadata::startTime.
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.
pParent | The parent process. |
bCopyOnWrite | Whether 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.
|
virtual |
Destructor.
Definition at line 109 of file Process.cc.
References Subsystem::acquire(), Vector< T >::begin(), Thread::detached(), Vector< T >::end(), Processor::getInterrupts(), Processor::information(), Scheduler::instance(), m_Lock, m_pAddressSpace, m_pSubsystem, m_State, m_Threads, Scheduler::removeProcess(), VirtualAddressSpace::revertToKernelAddressSpace(), Processor::setInterrupts(), Thread::setStatus(), Thread::shutdown(), str, and Processor::switchAddressSpace().
size_t Process::addThread | ( | Thread * | pThread | ) |
Adds a thread to this process.
Definition at line 189 of file Process.cc.
References m_Lock, m_NextTid, m_Threads, and Vector< T >::pushBack().
Referenced by Thread::Thread().
|
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().
|
inline |
Returns our address space
Definition at line 120 of file Process.h.
Referenced by PerProcessorScheduler::addThread(), Thread::cleanStateLevel(), MemoryMapManager::clone(), Thread::getTlsBase(), PosixSubsystem::invoke(), PerProcessorScheduler::killCurrentThread(), X64VirtualAddressSpace::mapUnlocked(), Process(), PerProcessorScheduler::schedule(), X86VirtualAddressSpace::X86VirtualAddressSpace(), PosixSubsystem::~PosixSubsystem(), and Thread::~Thread().
|
inline |
|
inline |
Returns the current working directory.
Definition at line 156 of file Process.h.
Referenced by PosixSubsystem::findFile().
|
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().
|
inline |
Gets the current effective group.
Definition at line 222 of file Process.h.
References Subsystem::setProcess().
Referenced by getUserId().
|
inline |
Gets the effective user.
Definition at line 200 of file Process.h.
Referenced by getUserId().
|
inline |
Gets the exit status of the process.
Definition at line 131 of file Process.h.
Referenced by PosixSubsystem::exit(), and WaitCleanup::terminated().
|
inline |
Gets the current group.
Definition at line 211 of file Process.h.
Referenced by ProcFs::addProcess(), and getUserId().
|
inline |
Get process usage.
Definition at line 372 of file Process.h.
Referenced by Rtc::irq().
|
inline |
Returns the process ID.
Definition at line 108 of file Process.h.
References Thread::m_Id.
Referenced by ProcFs::addProcess(), MemoryPressureProcessKiller::compact(), ThreadsCommand::execute(), AllocationCommand::execute(), PosixSubsystem::exit(), Thread::getTlsBase(), X64InterruptManager::interrupt(), Rtc::irq(), kill(), PosixSubsystem::kill(), ProcFs::removeProcess(), PosixSubsystem::sendSignal(), Thread::setStatus(), X86CommonProcessorInformation::setTlsSelector(), PosixSyscallManager::syscall(), X64SyscallManager::syscall(), WaitCleanup::terminated(), PosixSubsystem::threadException(), and UnixSocket::writeBytewise().
|
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().
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().
|
inline |
Returns the parent process.
Definition at line 150 of file Process.h.
References Thread::m_pParent.
Referenced by PosixSubsystem::exit(), and WaitCleanup::terminated().
|
inline |
Get this process' root.
Definition at line 396 of file Process.h.
Referenced by Filesystem::getTrueRoot().
|
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().
Thread * Process::getThread | ( | size_t | n | ) |
Returns the n'th thread in this process.
Definition at line 225 of file Process.cc.
References Vector< T >::count(), Dec, FATAL, Hex, m_Lock, m_Threads, and Spinlock::release().
Referenced by MemoryPressureProcessKiller::compact(), ThreadsCommand::execute(), PosixSubsystem::exit(), PosixSubsystem::invoke(), kill(), VirtualTerminalManager::setTerminalMode(), IntervalTimer::signal(), suspend(), and WaitCleanup::terminated().
|
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().
|
inline |
Gets the current user.
Definition at line 189 of file Process.h.
Referenced by ProcFs::addProcess(), and getUserId().
|
virtual |
Direct, overrideable ways to get IDs (redirects to User/Group interface by default)
Reimplemented in PosixProcess.
Definition at line 320 of file Process.cc.
References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::count(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), getEffectiveGroup(), getEffectiveUser(), getGroup(), Group::getId(), User::getId(), getUser(), m_Waiters, and List< T, nodePoolSize >::pushBack().
Referenced by VFS::checkAccess(), PosixSubsystem::invoke(), PosixProcess::PosixProcess(), WaitCleanup::terminated(), and UnixSocket::writeBytewise().
|
inline |
Gets timestamps.
Definition at line 358 of file Process.h.
Referenced by WaitCleanup::terminated().
|
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 | ( | ) |
Kills the process.
Definition at line 239 of file Process.cc.
References Spinlock::acquire(), FATAL, getId(), getInit(), Scheduler::getNumProcesses(), Scheduler::getProcess(), Thread::getStatus(), getThread(), Processor::information(), Scheduler::instance(), m_Id, m_Lock, m_pParent, m_State, NOTICE, and processTerminated().
Referenced by PosixSubsystem::exit(), and Subsystem::Subsystem().
|
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().
|
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().
|
inline |
Marks the process as reaped.
Definition at line 137 of file Process.h.
References NORETURN.
Referenced by WaitCleanup::terminated().
|
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().
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().
|
inlineprivatevirtual |
Called when process times are updated.
Reimplemented in PosixProcess.
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().
|
inline |
Sets the controlling terminal.
Definition at line 172 of file Process.h.
Referenced by WaitCleanup::terminated().
|
inline |
|
inline |
Sets the effective user.
Definition at line 205 of file Process.h.
Referenced by User::login().
|
inline |
Sets the exit status of the process.
Definition at line 126 of file Process.h.
Referenced by PosixSubsystem::exit().
|
inline |
Sets the current group.
Definition at line 216 of file Process.h.
Referenced by UserManager::initialise(), and User::login().
|
static |
|
inline |
|
inline |
Sets the current user.
Definition at line 194 of file Process.h.
Referenced by UserManager::initialise(), and User::login().
void Process::suspend | ( | ) |
Suspends the process.
Definition at line 297 of file Process.cc.
References getThread(), Processor::information(), m_BeforeSuspendState, m_bUnreportedSuspend, m_ExitStatus, m_pParent, m_State, m_Threads, notifyWaiters(), and Subsystem::threadException().
|
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().
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Concurrency lock for complex Process data structures.
Definition at line 512 of file Process.h.
Referenced by addThread(), Cache::empty(), Cache::evict(), CacheManager::executeRequest(), Cache::exists(), TextIO::flip(), getNumThreads(), getThread(), TextIO::initialise(), Cache::insert(), kill(), Cache::lookup(), Cache::markEditing(), Cache::markNoLongerEditing(), Cache::pin(), Cache::release(), removeThread(), Cache::sync(), Cache::triggerChecksum(), Cache::trim(), TextIO::writeStr(), ~Process(), and Thread::~Thread().
|
private |
|
private |
Our virtual address space.
Definition at line 457 of file Process.h.
Referenced by Process(), and ~Process().
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
|
private |
The subsystem for this process
Definition at line 491 of file Process.h.
Referenced by removeThread(), and ~Process().
|
private |
|
private |
Our current state.
Definition at line 503 of file Process.h.
Referenced by kill(), removeThread(), resume(), suspend(), and ~Process().
Our list of threads.
Definition at line 437 of file Process.h.
Referenced by addThread(), getNumThreads(), getThread(), removeThread(), suspend(), and ~Process().
Semaphores to release whenever we are killed, suspended, or resumed.
Definition at line 494 of file Process.h.
Referenced by getUserId(), and notifyWaiters().
|
private |
Our description string.
Definition at line 449 of file Process.h.
Referenced by Process(), and ~Process().