The Pedigree Project 0.1
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
PosixProcess Class Reference
+ Inheritance diagram for PosixProcess:
+ Collaboration diagram for PosixProcess:

Public Types

enum  Membership { Leader = 0 , Member , NoGroup }
 
using CredentialSnapshot = PosixCredentials::Snapshot
 
using CredentialChange = PosixCredentials::Change
 
using CredentialStatus = PosixCredentials::Status
 
- Public Types inherited from Process
enum  ProcessType { Stock , Posix }
 
enum  ProcessState {
  Active , Suspended , Terminating , Terminated ,
  Reaped
}
 
enum class  ChildTransitionKind { None , Stopped , Continued }
 
enum class  FilesystemContextMode { Inherit , Deferred }
 
enum class  UserRegion { Normal , Dynamic }
 

Public Member Functions

 PosixProcess (Process *pParent, bool bCopyOnWrite=true, FilesystemContextMode filesystemContext=FilesystemContextMode::Inherit, bool emptyAddressSpace=false)
 
void publish ()
 
void setProcessGroup (ProcessGroup *newGroup)
 
void inheritProcessGroup (PosixProcess *parent)
 
ProcessGroup * getProcessGroup () const
 
bool getProcessGroupId (size_t &groupId, const UserspacePidNamespace *space=nullptr) const
 
void leaveProcessGroup ()
 
void setGroupMembership (Membership type)
 
Membership getGroupMembership () const
 
size_t getSessionId (const UserspacePidNamespace *space=nullptr) const
 
bool sharesSession (const PosixProcess &other) const
 
bool jobControlReady () const
 
void markExecCommitted ()
 
bool hasExecCommitted () const
 
Time::Timestamp getStartTimeTicks () const
 
void snapshotAccountingMemory ()
 
int createSession ()
 
int changeProcessGroup (PosixProcess &caller, int groupId)
 
void setMask (uint32_t mask)
 
uint32_t getMask () const
 
IntervalTimer & getRealIntervalTimer ()
 
IntervalTimer & getVirtualIntervalTimer ()
 
IntervalTimer & getProfileIntervalTimer ()
 
CredentialSnapshot snapshotCredentials () const
 
FilesystemCredentials realFilesystemCredentials () const
 
bool snapshotFilesystemCredentials (const Thread *, FilesystemCredentials &) const override
 
bool installUserIdentity (User *, Group *, const uint32_t *, size_t) override
 
CredentialStatus changeCredentials (Thread &, CredentialChange, uint32_t, uint32_t, uint32_t)
 
CredentialStatus replaceGroups (Thread &, const uint32_t *, size_t)
 
uint32_t changeFilesystemId (Thread &, bool group, uint32_t requested)
 
void setDumpable (bool)
 
void commitExecCredentials (Thread &, bool allExecutableFilesReadable)
 
int64_t getUserId () const final
 
virtual int64_t getGroupId () const
 
virtual int64_t getEffectiveUserId () const
 
virtual int64_t getEffectiveGroupId () const
 
virtual void getSupplementalGroupIds (Vector< int64_t > &vec) const
 
void setUserId (int64_t id) override
 
void setGroupId (int64_t id) override
 
void setEffectiveUserId (int64_t id) override
 
void setEffectiveGroupId (int64_t id) override
 
void setSupplementalGroupIds (const Vector< int64_t > &vec)
 
int64_t getSavedUserId () const
 
int64_t getSavedGroupId () const
 
void setSavedUserId (int64_t id)
 
void setSavedGroupId (int64_t id)
 
- Public Member Functions inherited from Process
 Process ()
 
 Process (Process *pParent, bool bCopyOnWrite=true)
 
virtual ~Process ()
 
size_t addThread (Thread *pThread)
 
void threadExiting (Thread *pThread)
 
void transferExecProcessSignals (Thread *pThread)
 
void removeThread (Thread *pThread)
 
size_t getNumThreads ()
 
MUST_USE_RESULT bool acquireThread (ThreadLease &lease, size_t n)
 
MUST_USE_RESULT bool acquireProcessSignalThread (ThreadLease &lease)
 
MUST_USE_RESULT bool acquireThreadById (ThreadLease &lease, size_t id)
 
MUST_USE_RESULT bool acquireThreadByTaskId (ThreadLease &lease, size_t id)
 
MUST_USE_RESULT bool acquireThreadByUserspaceId (ThreadLease &lease, size_t id, const UserspacePidNamespace *space)
 
MUST_USE_RESULT bool acquireThread (ThreadLease &lease, Thread *expected)
 
TerminalOwnerReservation reserveTerminalOwner ()
 
size_t getId ()
 
size_t getUserspaceId () const
 
size_t getUserspaceId (const UserspacePidNamespace *space) const
 
SharedPointer< UserspacePidNamespace > pidNamespace () const
 
SharedPointer< UserspacePid > pidIdentity () const
 
SharedPointer< UserspacePidNamespace > pidNamespaceForChildren ()
 
bool createPidNamespace ()
 
bool unsharePidNamespace ()
 
bool unsharePidNamespace (const SharedPointer< UserspacePidNamespace > &prepared)
 
bool pidNamespaceReady () const
 
LargeStaticString & description ()
 
VirtualAddressSpace * getAddressSpace ()
 
Process * addressSpaceOwner ()
 
bool isVforkChild () const
 
void borrowVforkAddressSpace (Process &parent, const SharedPointer< VforkCompletion > &completion)
 
void releaseVforkAddressSpace ()
 
void setExitStatus (int code)
 
int getExitStatus ()
 
void reap ()
 
bool prepareThreadExit ()
 
bool beginTermination (int code=0, Subsystem::ExitCause cause=Subsystem::ExitCause::Normal)
 
bool quiesceTermination ()
 
void finishTermination (bool notifyParent=false) NORETURN
 
ReaperClaim tryClaimReaper ()
 
void kill () NORETURN
 
void suspend (int stopSignal=0)
 
void suspendIfContinuationEpoch (int stopSignal, size_t continuationEpoch)
 
void resume ()
 
size_t getContinuationEpoch ()
 
Process * getParent ()
 
FilesystemContextRef acquireFilesystemContext () const
 
MUST_USE_RESULT bool installFilesystemContext (FilesystemContextOwner &&context)
 
bool replaceFilesystemContext (FilesystemContextOwner &&replacement, const FilesystemContextRef &expected)
 
bool filesystemContextReady () const
 
void releaseFilesystemContext ()
 
SharedPointer< ControllingTerminal > acquireCttyContext () const
 
MUST_USE_RESULT File * acquireCtty (FileContextLease &lease) const
 
void setCttyContext (const SharedPointer< ControllingTerminal > &context)
 
MUST_USE_RESULT bool setCtty (File *file)
 
bool snapshotUserReservations (UserReservationSnapshot &result)
 
bool commitUserReservations (uint64_t expectedGeneration, UserReservationSnapshot &replacement)
 
bool allocateUserRange (UserRegion region, size_t length, uintptr_t &address)
 
bool allocateSpecificUserRange (UserRegion region, uintptr_t address, size_t length)
 
void freeUserRange (UserRegion region, uintptr_t address, size_t length)
 
void resetUserReservations ()
 
void inheritFilesystemIds (Thread &child, const Thread *creator) const
 
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)
 
void setLinker (DynamicLinker *pDl)
 
DynamicLinker * getLinker ()
 
void setSubsystem (Subsystem *pSubsystem)
 
Subsystem * getSubsystem ()
 
ProcessType getType () const
 
WaitQueue::Guard acquireChildStateWait ()
 
bool waitUntilTerminationReapable ()
 
bool waitUntilTerminationReapableForTerminalCoordinator ()
 
bool selectPendingChildTransition (bool includeStopped, bool includeContinued, bool consume, ChildTransition &transition)
 
bool takePendingChildTransition (bool includeStopped, bool includeContinued, ChildTransition &transition)
 
ProcessState getState () const
 
bool isSuspended ()
 
void markTerminating ()
 
void trackHeap (ssize_t nBytes)
 
void trackPages (ssize_t nVirtual, ssize_t nPhysical, ssize_t nShared)
 
void resetCounts ()
 
Time::Timestamp getUserTime () const
 
Time::Timestamp getKernelTime () const
 
Time::Timestamp getReapedChildrenUserTime () const
 
Time::Timestamp getReapedChildrenKernelTime () const
 
void accountReapedChild (const Process *child, Time::Timestamp &user, Time::Timestamp &kernel)
 
Time::Timestamp getStartTime () const
 
ssize_t getHeapUsage () const
 
ssize_t getVirtualPageCount () const
 
ssize_t getPhysicalPageCount () const
 
ssize_t getSharedPageCount () const
 
bool hasSharedAddressSpace () const
 

Private Member Functions

void setTrustedIdentity (uint32_t CredentialSnapshot::*field, int64_t id)
 
void registerProcess ()
 
void unregisterProcess ()
 
virtual void reportTimesUpdated (Time::Timestamp userTotal, Time::Timestamp total)
 
virtual void processTerminated ()
 
 PosixProcess (const PosixProcess &)
 
PosixProcess & operator= (const PosixProcess &)
 
void initializeJobControl (Process *parent)
 
void publishCredentialReadCache ()
 

Private Attributes

ProcessAccountingLifetime m_AccountingLifetime
 
size_t m_SessionId
 
ProcessGroup * m_pProcessGroup
 
PosixProcess * m_GroupPrevious
 
PosixProcess * m_GroupNext
 
bool m_ExecCommitted
 
Membership m_GroupMembership
 
uint32_t m_Mask
 
IntervalTimer m_RealIntervalTimer
 
IntervalTimer m_VirtualIntervalTimer
 
IntervalTimer m_ProfileIntervalTimer
 
CredentialSnapshot m_Credentials
 
volatile uint32_t m_RealUserId
 
bool m_bRegistered
 

Friends

class ProcessGroup
 
class IntervalTimer
 

Additional Inherited Members

- Static Public Member Functions inherited from Process
static SharedPointer< UserspacePidNamespace > rootPidNamespace ()
 
static bool currentFilesystemCredentials (FilesystemCredentials &out)
 
static Process * getInit ()
 
static void setInit (Process *pProcess)
 
- Protected Member Functions inherited from Process
void publishAccountIdentity (User *, Group *)
 
 Process (DeferredPublication, ProcessType type=Stock)
 
 Process (DeferredPublication, Process *pParent, bool bCopyOnWrite=true, FilesystemContextMode filesystemContext=FilesystemContextMode::Inherit, bool emptyAddressSpace=false, ProcessType type=Stock)
 
void publish ()
 
void prepareForDestruction ()
 
void enableTimeAccountingReports (size_t initialInterest=~size_t(0))
 
void setTimeAccountingReportInterest (size_t interest, bool enabled)
 
- Static Protected Member Functions inherited from Process
static bool loadFilesystemIds (const Thread &, uint32_t &uid, uint32_t &gid)
 
static void publishFilesystemIds (Thread &, uint32_t uid, uint32_t gid)
 
- Protected Attributes inherited from Process
Spinlock m_CredentialLock
 

Detailed Description

Definition at line 117 of file PosixProcess.h.

Member Typedef Documentation

◆ CredentialChange

using PosixProcess::CredentialChange = PosixCredentials::Change

Definition at line 179 of file PosixProcess.h.

◆ CredentialSnapshot

Definition at line 178 of file PosixProcess.h.

◆ CredentialStatus

using PosixProcess::CredentialStatus = PosixCredentials::Status

Definition at line 180 of file PosixProcess.h.

Member Enumeration Documentation

◆ Membership

Defines what status this Process has within its group

Enumerator
Leader 

Group leader. The one who created the group, and whose PID was absorbed to become the Process Group ID.

Member 

Group member. These processes have a unique Process ID.

NoGroup 

Not in a group.

Definition at line 123 of file PosixProcess.h.

Constructor & Destructor Documentation

◆ PosixProcess() [1/2]

PosixProcess::PosixProcess ( )

Definition at line 31 of file PosixProcess.cc.

◆ PosixProcess() [2/2]

PosixProcess::PosixProcess ( Process *  pParent,
bool  bCopyOnWrite = true,
FilesystemContextMode  filesystemContext = FilesystemContextMode::Inherit,
bool  emptyAddressSpace = false 
)

Copy constructor.

Definition at line 53 of file PosixProcess.cc.

References Process::enableTimeAccountingReports().

◆ ~PosixProcess()

PosixProcess::~PosixProcess ( )
virtual

Definition at line 98 of file PosixProcess.cc.

Member Function Documentation

◆ changeCredentials()

PosixProcess::CredentialStatus PosixProcess::changeCredentials ( Thread &  task,
CredentialChange  change,
uint32_t  first,
uint32_t  second,
uint32_t  third 
)

Definition at line 72 of file PosixProcess-credentials.cc.

◆ changeFilesystemId()

uint32_t PosixProcess::changeFilesystemId ( Thread &  task,
bool  group,
uint32_t  requested 
)

Definition at line 146 of file PosixProcess-credentials.cc.

◆ changeProcessGroup()

int PosixProcess::changeProcessGroup ( PosixProcess &  caller,
int  groupId 
)

Definition at line 162 of file PosixProcess-job-control.cc.

◆ commitExecCredentials()

void PosixProcess::commitExecCredentials ( Thread &  task,
bool  allExecutableFilesReadable 
)

Definition at line 187 of file PosixProcess-credentials.cc.

◆ createSession()

int PosixProcess::createSession ( )

Definition at line 133 of file PosixProcess-job-control.cc.

◆ getEffectiveGroupId()

int64_t PosixProcess::getEffectiveGroupId ( ) const
virtual

Reimplemented from Process.

Definition at line 242 of file PosixProcess-credentials.cc.

◆ getEffectiveUserId()

int64_t PosixProcess::getEffectiveUserId ( ) const
virtual

Reimplemented from Process.

Definition at line 239 of file PosixProcess-credentials.cc.

◆ getGroupId()

int64_t PosixProcess::getGroupId ( ) const
virtual

Reimplemented from Process.

Definition at line 236 of file PosixProcess-credentials.cc.

◆ getGroupMembership()

PosixProcess::Membership PosixProcess::getGroupMembership ( ) const

Definition at line 103 of file PosixProcess-job-control.cc.

◆ getMask()

uint32_t PosixProcess::getMask ( ) const

Definition at line 116 of file PosixProcess.cc.

◆ getProcessGroup()

ProcessGroup * PosixProcess::getProcessGroup ( ) const

Definition at line 82 of file PosixProcess-job-control.cc.

◆ getProcessGroupId()

bool PosixProcess::getProcessGroupId ( size_t &  groupId,
const UserspacePidNamespace *  space = nullptr 
) const

Definition at line 86 of file PosixProcess-job-control.cc.

◆ getProfileIntervalTimer()

IntervalTimer & PosixProcess::getProfileIntervalTimer ( )

Definition at line 146 of file PosixProcess.cc.

◆ getRealIntervalTimer()

IntervalTimer & PosixProcess::getRealIntervalTimer ( )

Definition at line 138 of file PosixProcess.cc.

◆ getSavedGroupId()

int64_t PosixProcess::getSavedGroupId ( ) const

Definition at line 248 of file PosixProcess-credentials.cc.

◆ getSavedUserId()

int64_t PosixProcess::getSavedUserId ( ) const

Definition at line 245 of file PosixProcess-credentials.cc.

◆ getSessionId()

size_t PosixProcess::getSessionId ( const UserspacePidNamespace *  space = nullptr) const

Definition at line 108 of file PosixProcess-job-control.cc.

◆ getStartTimeTicks()

Time::Timestamp PosixProcess::getStartTimeTicks ( ) const
inline

Definition at line 164 of file PosixProcess.h.

◆ getSupplementalGroupIds()

void PosixProcess::getSupplementalGroupIds ( Vector< int64_t > &  vec) const
virtual

Reimplemented from Process.

Definition at line 251 of file PosixProcess-credentials.cc.

◆ getUserId()

int64_t PosixProcess::getUserId ( ) const
inlinefinalvirtual

Direct, overrideable ways to get IDs (redirects to User/Group interface by default)

Reimplemented from Process.

Definition at line 191 of file PosixProcess.h.

◆ getVirtualIntervalTimer()

IntervalTimer & PosixProcess::getVirtualIntervalTimer ( )

Definition at line 142 of file PosixProcess.cc.

◆ hasExecCommitted()

bool PosixProcess::hasExecCommitted ( ) const

Definition at line 128 of file PosixProcess-job-control.cc.

◆ inheritProcessGroup()

void PosixProcess::inheritProcessGroup ( PosixProcess *  parent)

Definition at line 75 of file PosixProcess-job-control.cc.

◆ initializeJobControl()

void PosixProcess::initializeJobControl ( Process *  parent)
private

Definition at line 16 of file PosixProcess-job-control.cc.

◆ installUserIdentity()

bool PosixProcess::installUserIdentity ( User *  user,
Group *  group,
const uint32_t *  groups,
size_t  count 
)
overridevirtual

Reimplemented from Process.

Definition at line 204 of file PosixProcess-credentials.cc.

◆ jobControlReady()

bool PosixProcess::jobControlReady ( ) const

Definition at line 118 of file PosixProcess-job-control.cc.

◆ leaveProcessGroup()

void PosixProcess::leaveProcessGroup ( )

Definition at line 94 of file PosixProcess-job-control.cc.

◆ markExecCommitted()

void PosixProcess::markExecCommitted ( )

Definition at line 123 of file PosixProcess-job-control.cc.

◆ processTerminated()

void PosixProcess::processTerminated ( )
privatevirtual

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

Reimplemented from Process.

Definition at line 155 of file PosixProcess.cc.

References IntervalTimer::disarm().

◆ publish()

void PosixProcess::publish ( )

Publishes a fully assembled POSIX process. Call after its subsystem, mappings, descriptors, and delayed initial Thread are ready.

Definition at line 104 of file PosixProcess.cc.

References Process::publish().

◆ publishCredentialReadCache()

void PosixProcess::publishCredentialReadCache ( )
private

Definition at line 94 of file PosixProcess.cc.

◆ realFilesystemCredentials()

FilesystemCredentials PosixProcess::realFilesystemCredentials ( ) const

Definition at line 26 of file PosixProcess-credentials.cc.

◆ registerProcess()

void PosixProcess::registerProcess ( )
private

Definition at line 120 of file PosixProcess.cc.

◆ replaceGroups()

PosixProcess::CredentialStatus PosixProcess::replaceGroups ( Thread &  task,
const uint32_t *  groups,
size_t  count 
)

Definition at line 113 of file PosixProcess-credentials.cc.

◆ reportTimesUpdated()

void PosixProcess::reportTimesUpdated ( Time::Timestamp  userTotal,
Time::Timestamp  total 
)
privatevirtual

Called by the accounting worker with absolute userspace and total time. This is never invoked by trackTime() or while scheduler locks are held.

Reimplemented from Process.

Definition at line 150 of file PosixProcess.cc.

References IntervalTimer::consumeCpuTime().

◆ setDumpable()

void PosixProcess::setDumpable ( bool  dumpable)

Definition at line 178 of file PosixProcess-credentials.cc.

◆ setEffectiveGroupId()

void PosixProcess::setEffectiveGroupId ( int64_t  id)
overridevirtual

Reimplemented from Process.

Definition at line 281 of file PosixProcess-credentials.cc.

◆ setEffectiveUserId()

void PosixProcess::setEffectiveUserId ( int64_t  id)
overridevirtual

Reimplemented from Process.

Definition at line 278 of file PosixProcess-credentials.cc.

◆ setGroupId()

void PosixProcess::setGroupId ( int64_t  id)
overridevirtual

Reimplemented from Process.

Definition at line 275 of file PosixProcess-credentials.cc.

◆ setGroupMembership()

void PosixProcess::setGroupMembership ( Membership  type)

Definition at line 98 of file PosixProcess-job-control.cc.

◆ setMask()

void PosixProcess::setMask ( uint32_t  mask)

Definition at line 112 of file PosixProcess.cc.

◆ setProcessGroup()

void PosixProcess::setProcessGroup ( ProcessGroup *  newGroup)

Definition at line 36 of file PosixProcess-job-control.cc.

◆ setSavedGroupId()

void PosixProcess::setSavedGroupId ( int64_t  id)

Definition at line 287 of file PosixProcess-credentials.cc.

◆ setSavedUserId()

void PosixProcess::setSavedUserId ( int64_t  id)

Definition at line 284 of file PosixProcess-credentials.cc.

◆ setSupplementalGroupIds()

void PosixProcess::setSupplementalGroupIds ( const Vector< int64_t > &  vec)

Definition at line 291 of file PosixProcess-credentials.cc.

◆ setTrustedIdentity()

void PosixProcess::setTrustedIdentity ( uint32_t CredentialSnapshot::*  field,
int64_t  id 
)
private

Definition at line 259 of file PosixProcess-credentials.cc.

◆ setUserId()

void PosixProcess::setUserId ( int64_t  id)
overridevirtual

Reimplemented from Process.

Definition at line 272 of file PosixProcess-credentials.cc.

◆ sharesSession()

bool PosixProcess::sharesSession ( const PosixProcess &  other) const

Definition at line 113 of file PosixProcess-job-control.cc.

◆ snapshotAccountingMemory()

void PosixProcess::snapshotAccountingMemory ( )

Definition at line 215 of file process-accounting.cc.

◆ snapshotCredentials()

PosixProcess::CredentialSnapshot PosixProcess::snapshotCredentials ( ) const

Definition at line 21 of file PosixProcess-credentials.cc.

◆ snapshotFilesystemCredentials()

bool PosixProcess::snapshotFilesystemCredentials ( const Thread *  task,
FilesystemCredentials &  out 
) const
overridevirtual

Reimplemented from Process.

Definition at line 47 of file PosixProcess-credentials.cc.

◆ unregisterProcess()

void PosixProcess::unregisterProcess ( )
private

Definition at line 131 of file PosixProcess.cc.

Friends And Related Symbol Documentation

◆ IntervalTimer

friend class IntervalTimer
friend

Definition at line 119 of file PosixProcess.h.

◆ ProcessGroup

friend class ProcessGroup
friend

Definition at line 118 of file PosixProcess.h.

Member Data Documentation

◆ m_AccountingLifetime

ProcessAccountingLifetime PosixProcess::m_AccountingLifetime
private

Definition at line 225 of file PosixProcess.h.

◆ m_bRegistered

bool PosixProcess::m_bRegistered
private

Definition at line 242 of file PosixProcess.h.

◆ m_Credentials

CredentialSnapshot PosixProcess::m_Credentials
private

Definition at line 238 of file PosixProcess.h.

◆ m_ExecCommitted

bool PosixProcess::m_ExecCommitted
private

Definition at line 230 of file PosixProcess.h.

◆ m_GroupMembership

Membership PosixProcess::m_GroupMembership
private

Definition at line 231 of file PosixProcess.h.

◆ m_GroupNext

PosixProcess* PosixProcess::m_GroupNext
private

Definition at line 229 of file PosixProcess.h.

◆ m_GroupPrevious

PosixProcess* PosixProcess::m_GroupPrevious
private

Definition at line 228 of file PosixProcess.h.

◆ m_Mask

uint32_t PosixProcess::m_Mask
private

Definition at line 232 of file PosixProcess.h.

◆ m_pProcessGroup

ProcessGroup* PosixProcess::m_pProcessGroup
private

Definition at line 227 of file PosixProcess.h.

◆ m_ProfileIntervalTimer

IntervalTimer PosixProcess::m_ProfileIntervalTimer
private

Definition at line 236 of file PosixProcess.h.

◆ m_RealIntervalTimer

IntervalTimer PosixProcess::m_RealIntervalTimer
private

Definition at line 234 of file PosixProcess.h.

◆ m_RealUserId

volatile uint32_t PosixProcess::m_RealUserId
private

Definition at line 241 of file PosixProcess.h.

◆ m_SessionId

size_t PosixProcess::m_SessionId
private

Definition at line 226 of file PosixProcess.h.

◆ m_VirtualIntervalTimer

IntervalTimer PosixProcess::m_VirtualIntervalTimer
private

Definition at line 235 of file PosixProcess.h.


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