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

#include <Thread.h>

+ Collaboration diagram for Thread:

Classes

struct  AlternateSignalStack
 
struct  DeferredProcessExit
 
struct  JoinDiscardContext
 
class  SecurityState
 
class  StackDiscardScope
 
struct  StateLevel
 
class  TemporarySignalMask
 
class  UserReturnFrameScope
 
struct  WaitDebugInfo
 

Public Types

enum  UserReturnWorkFlag : size_t {
  UserReturnExternalWork = 1 , UserReturnEventsDeferred = 1 << 1 , UserReturnSignalFrames = 1 << 3 , UserReturnDeferredException = 1 << 4 ,
  UserReturnOriginalSyscall = 1 << 5
}
 
enum  Status {
  Created , Ready , Running , Sleeping ,
  Zombie , AwaitingJoin
}
 
enum  DebugState {
  None , SemWait , CondWait , Joining ,
  FutexWait , EventWait , ProcessWait , CallbackDrain
}
 
enum  InterruptionReason { NotInterrupted , InterruptedByTimeout , InterruptedBySignal }
 
enum  UnwindType { Continue = 0 , Exit , TerminateThread }
 
typedef int(* ThreadStartFunc) (void *)
 
using SecurityStateRef = SharedPointer< SecurityState >
 

Public Member Functions

UserReturnFrame * currentUserReturnFrame () const
 
bool tryRequireSignalFrames ()
 
void clearSignalFrameRequirement ()
 
void setUserReturnSignalParked (bool parked)
 
bool canSkipUserReturnWork ()
 
bool clearUserReturnWorkIfIdle ()
 
bool userReturnWorkPending () const
 
bool requiresSignalFrames () const
 
 Thread (Process *pParent, ThreadStartFunc pStartFunction, void *pParam, void *pStack=0, bool semiUser=false, bool bDontPickCore=false, bool delayedStart=false, const ThreadPlacement *placement=nullptr)
 
 Thread (Process *pParent)
 
 Thread (Process *pParent, SyscallState &state, bool delayedStart=false, const ThreadPlacement *placement=nullptr)
 
void snapshotPlacement (ThreadPlacement &placement)
 
bool hasSecurityState () const
 
SecurityStateRef securityState ()
 
void setSecurityState (const SecurityStateRef &state)
 
void snapshotPlacementLocked (ThreadPlacement &placement) const
 
AffinityResult requestAffinity (const CpuAffinityMask &mask, uint64_t &generation)
 
AffinityResult waitAffinity (uint64_t generation)
 
AffinityResult completeAffinityAtSafePoint (bool *waited=nullptr)
 
bool affinityWorkPending () const
 
virtual ~Thread ()
 
void shutdown ()
 
void notifySubsystemExit ()
 
void forceToStartupProcessor ()
 
SchedulerState & state ()
 
SchedulerState * pushState ()
 
void popState (bool clean=true)
 
void abandonCurrentState (bool clean=false)
 
void abandonAllStates ()
 
VirtualAddressSpace::Stack * getStateUserStack ()
 
void setStateUserStack (VirtualAddressSpace::Stack *st)
 
void discardUserStackMetadataForExec ()
 
void adoptInitialUserStackForExec (VirtualAddressSpace::Stack *stack)
 
size_t getStateLevel () const
 
void * getSyscallDispatchContext () const
 
void setSyscallDispatchContext (void *context)
 
void allocateStackAtLevel (size_t stateLevel)
 
void setKernelStack ()
 
void pokeState (size_t stateLevel, SchedulerState &state)
 
Process * getParent () const
 
void setClearChildTid (uintptr_t address)
 
uintptr_t takeClearChildTid ()
 
void setRobustList (uintptr_t address, size_t ownerId)
 
uintptr_t getRobustList () const
 
uintptr_t takeRobustList (size_t &ownerId)
 
void recordTime (CpuTimeMode mode)
 
void trackTime (CpuTimeMode mode)
 
void transitionTime (CpuTimeMode from, CpuTimeMode to, bool interruptsAlreadyDisabled=false)
 
ALWAYS_INLINE void transitionTimeAtInterruptReturn (CpuTimeMode from, CpuTimeMode to)
 
CpuTimeMode currentTimeAccountingMode () const
 
void accountTimerTick (Time::Timestamp delta, bool kernelMode)
 
Time::Timestamp getUserTime () const
 
Time::Timestamp getKernelTime () const
 
void setParent (Process *p)
 
ExecutionPersonality & executionPersonality ()
 
Status getStatus () const
 
bool start ()
 
bool startDetached ()
 
int getExitCode ()
 
void * getKernelStack ()
 
void * getKernelStackBase (size_t *size) const
 
size_t getId ()
 
size_t getUserspaceTaskId (const UserspacePidNamespace *space=nullptr) const
 
size_t getTaskId () const
 
size_t getErrno ()
 
void setErrno (size_t err)
 
bool wasInterrupted ()
 
void clearInterruption ()
 
InterruptionReason getInterruptionReason ()
 
void setInterruptionReason (InterruptionReason reason)
 
void markTimeoutInterruptedWait ()
 
void markSignalInterruptedWait ()
 
UnwindType getUnwindState ()
 
void setUnwindState (UnwindType ut)
 
void deferProcessExit (int code)
 
void deferSignalExit (int signal)
 
DeferredProcessExit takeDeferredProcessExit ()
 
bool deferSubsystemException (size_t type, uintptr_t faultAddress, uintptr_t errorCode)
 
bool hasDeferredSubsystemException () const
 
bool takeDeferredSubsystemException (size_t &type, uintptr_t &faultAddress, uintptr_t &errorCode)
 
bool isTerminationDeferred () const
 
DebugState getDebugState (uintptr_t &address)
 
void setDebugState (DebugState state, uintptr_t address)
 
bool getWaitDebugInfo (WaitDebugInfo &info)
 
Spinlock & getLock ()
 
bool sendEvent (Event *pEvent)
 
void waitForEvent (WaitQueue::StackDiscardCleanup onStackDiscard=nullptr, void *stackDiscardContext=nullptr)
 
bool waitForEventOrSignalInterruption (WaitQueue::StackDiscardCleanup onStackDiscard=nullptr, void *stackDiscardContext=nullptr)
 
void inhibitEvent (size_t eventNumber, bool bInhibit)
 
uint64_t getSignalMask ()
 
void setSignalMask (uint64_t mask)
 
uint64_t getSignalMaskForReturnFrame ()
 
void commitSignalHandlerMask (uint64_t mask)
 
void restoreDeferredSignalMask (size_t stateLevel)
 
const SyscallState * getOriginalSyscallState () const
 
void setOriginalSyscallState (const SyscallState *state)
 
void setCurrentSignalDelivery (size_t signalNumber, size_t continuationEpoch)
 
bool getCurrentSignalDelivery (size_t &signalNumber, size_t &continuationEpoch)
 
void prepareSignalStateForExec ()
 
bool hasTemporarySignalWaitInterruption ()
 
bool hasActiveTemporarySignalMask ()
 
bool retainTemporarySignalWaitInterruptionOrClear ()
 
AlternateSignalStack & getAlternateSignalStack ()
 
void cullEvent (Event *pEvent)
 
void cullEvent (size_t eventNumber)
 
void cullSignalEvent (size_t signalNumber)
 
bool transferProcessSignalsTo (Thread &target)
 
bool replaceSignalEvent (size_t signalNumber, Event *replacement, int processDirected=-1, uint64_t rebindGeneration=0)
 
bool hasSignalEvent (size_t signalNumber, int processDirected=-1)
 
bool acceptingEvents ()
 
uint64_t pendingSignalMask (bool processOnly=false)
 
uint64_t pendingSignalOrder (size_t signal, bool processOnly=false)
 
Event::Delivery reservePendingSignal (uint64_t mask, bool processOnly=false, uint64_t expectedSequence=~uint64_t(0))
 
bool restorePendingSignal (Event::Delivery &delivery)
 
void cullSignalSource (const void *source)
 
void setSynchronousSignalMask (uint64_t mask)
 
uint64_t getSynchronousSignalMask ()
 
bool hasEvents ()
 
bool hasEvent (Event *pEvent)
 
bool hasEvent (size_t eventNumber)
 
void setPriority (size_t p)
 
size_t getPriority ()
 
void unexpectedExit ()
 
uintptr_t getTlsBase ()
 
void resetTlsBase ()
 
void setTlsBase (uintptr_t base)
 
uintptr_t getUserGsBase () const
 
void setUserGsBase (uintptr_t base)
 
void saveUserGsBase ()
 
size_t getCpuId ()
 
void setCpuId (size_t id)
 
bool join ()
 
bool joinForCompletion ()
 
bool detach ()
 
bool detached () const
 
bool eventsDeferred () const
 
ExecutionContext executionContext () const
 
class PerProcessorScheduler * getScheduler () const
 
const String & getName () const
 
void setName (const String &name)
 
template<size_t N>
void setName (const char(&name)[N])
 

Static Public Member Functions

static void threadExited () NORETURN
 

Protected Member Functions

void setScheduler (class PerProcessorScheduler *pScheduler)
 
void deferEvents ()
 
void resumeEvents ()
 
void deferTermination ()
 
void resumeTermination ()
 
void markUserReturnWorkFlag (UserReturnWorkFlag flag)
 
void clearUserReturnWorkFlag (UserReturnWorkFlag flag)
 
void markUserReturnWorkPending ()
 
void registerDeferredScope (DeferredScopeRecord &record, bool termination, bool events)
 
void armStateCleanup (DeferredScopeRecord &record, DeferredScopeRecord::Cleanup cleanup, void *context)
 
void unregisterDeferredScope (DeferredScopeRecord &record)
 
void disarmStateCleanup (DeferredScopeRecord &record)
 
void unregisterTerminationDeferral (DeferredScopeRecord &record)
 
void moveTerminationDeferral (DeferredScopeRecord &from, DeferredScopeRecord &to)
 
void retireDeferredScopes (bool allStateLevels, size_t stateLevel=0)
 
size_t stateCleanupCheckpoint ()
 
void retireDeferredScopesAfter (size_t checkpoint)
 
void retireDeferredScopesMatching (bool allStateLevels, size_t stateLevel, bool newerThanCheckpoint, size_t checkpoint)
 
void armAtomicStateCleanup (AtomicStateCleanupRecord &record, AtomicStateCleanupRecord::Cleanup cleanup, void *context)
 
void disarmAtomicStateCleanup (AtomicStateCleanupRecord &record)
 

Private Types

enum class  EventSelection { AnyDeliverable , WithoutExactUserReturn , KernelDeliverable , StoppedProcessKernel }
 

Private Member Functions

void publishDeferredScope (DeferredScopeRecord &record, bool termination, bool events, DeferredScopeRecord::Cleanup cleanup, void *context)
 
void unpublishDeferredScope (DeferredScopeRecord &record, bool deferrals)
 
void registerFreshTerminationDeferral (DeferredScopeRecord &record, DeferredScopeRecord::Cleanup cleanup=nullptr, void *context=nullptr)
 
 Thread (const Thread &)
 
Thread & operator= (const Thread &)
 
void publishTimeAccounting (CpuTimeMode mode, Time::Timestamp elapsed)
 
void initialisePlacement (const ThreadPlacement *placement)
 
void publishReadyNotification ()
 
void cleanStateLevel (size_t level)
 
size_t beginTemporarySignalMask (uint64_t signalMask)
 
bool finishTemporarySignalMask (size_t stateLevel, bool deferForUserReturn=true)
 
bool waitForEventInternal (bool stopOnSignalInterruption, WaitQueue::StackDiscardCleanup onStackDiscard, void *stackDiscardContext)
 
bool eventNeedsUserReturnFrameUnlocked (Event *event) const
 
bool eventIsDeliverableUnlocked (Event *event, EventSelection selection=EventSelection::AnyDeliverable)
 
bool hasEventsUnlocked (EventSelection selection=EventSelection::AnyDeliverable)
 
bool hasDeliverableEventsUnlocked (EventSelection selection=EventSelection::AnyDeliverable)
 
void markDeferredUserReturnSignalInterruption ()
 
void wakeForDeliverableEvents ()
 
MUST_USE_RESULT Event::Delivery getNextEvent (EventSelection selection=EventSelection::AnyDeliverable)
 
void setStatus (Status s)
 
void setStatusUnlocked (Status s)
 
bool markReapable ()
 
bool joinInternal (bool completion)
 
bool beginExternalLease ()
 
void endExternalLease ()
 
void closeExternalLeaseAdmission ()
 
void closeExternalLeaseAdmissionAndDrain ()
 
bool interruptWaitUnlocked (WaitQueue::WakeReason reason, PerProcessorScheduler *&readyScheduler)
 
bool hasActiveWaitUnlocked () const
 
bool hasActiveWaitAtAnyLevel () const
 
bool activeWaitPendingUnlocked () const
 
void unlinkWaitsForStackDiscard ()
 
void markTerminalWaitCancelledBeforeBlockUnlocked (size_t level)
 
bool consumeTerminalWaitCancelledBeforeBlockUnlocked ()
 
void clearTerminalWaitCancelledBeforeBlockUnlocked (size_t level)
 

Static Private Member Functions

static void discardJoin (void *context)
 

Private Attributes

String m_Name
 
size_t m_nStateLevel = 0
 
Process * m_pParent = nullptr
 
uint32_t m_FilesystemUid = 0
 
uint32_t m_FilesystemGid = 0
 
bool m_FilesystemIdsValid = false
 
const FilesystemCredentials * m_FilesystemOverride = nullptr
 
SecurityStateRef m_SecurityState
 
bool m_HasSecurityState = false
 
DeferredThreadReapNode m_DeferredReapNode
 
ThreadTimeAccounting m_TimeAccounting
 
Time::Timestamp m_UserTime = 0
 
Time::Timestamp m_KernelTime = 0
 
size_t m_CurrentTimeAccountingMode = static_cast<size_t>(CpuTimeMode::Kernel)
 
void * m_pAllocatedStack = nullptr
 
size_t m_Id = 0
 
size_t m_TaskId = 0
 
SharedPointer< UserspacePid > m_UserspacePid
 
uintptr_t m_DebugStateAddress = 0
 
size_t m_DebugStateGeneration = 0
 
class PerProcessorScheduler * m_pScheduler = nullptr
 
ThreadPlacement m_Placement
 
CpuAffinityMask m_RequestedAffinity
 
WaitQueue m_AffinityWaiters
 
uint64_t m_AffinityGeneration = 0
 
uint64_t m_AffinityCompleted = 0
 
bool m_AffinityPending = false
 
bool m_AffinityGatePending = false
 
bool m_AffinityWorkQueued = false
 
size_t m_AffinityReturnPending = 0
 
bool m_SignalFramesRequired = false
 
bool m_UserReturnSignalParked = false
 
size_t m_UserReturnWorkPending = 0
 
Thread * m_AffinityNext = nullptr
 
bool m_HasSchedulerContext = false
 
bool m_ReadyPublicationPending = false
 
size_t m_Priority = DEFAULT_PRIORITY
 
Thread * m_pReadyPrevious = nullptr
 
Thread * m_pReadyNext = nullptr
 
size_t m_ReadyQueuePriority = MAX_PRIORITIES
 
bool m_bReadyQueued = false
 
void * m_pTlsBase = nullptr
 
uintptr_t m_UserGsBase = 0
 
size_t m_ProcId = 0
 
Spinlock m_Lock
 
WaitQueue m_JoinWaiters
 
Spinlock m_ExternalLeaseLock
 
WaitQueue m_ExternalLeaseWaiters
 
size_t m_nExternalLeases = 0
 
bool m_bExternalLeaseAdmissionClosed = false
 
bool m_bExternalLeaseReleaseInProgress = false
 
WaitQueue m_EventWaiters
 
WaitQueue m_EventSenderDrainWaiters
 
List< Event * > m_EventQueue
 
size_t m_EventSendersInFlight = 0
 
StateLevel m_StateLevels [MAX_NESTED_EVENTS]
 
AlternateSignalStack m_AlternateSignalStack
 
const SyscallState * m_OriginalSyscallState = nullptr
 
void * m_SyscallDispatchContext = nullptr
 
size_t m_ActiveSyscalls [serviceEnd] = {}
 
volatile Status m_Status = Ready
 
ExecutionPersonality m_ExecutionPersonality
 
bool m_ExitToIdle = false
 
int m_ExitCode = 0
 
DebugState m_DebugState = None
 
UnwindType m_UnwindState = Continue
 
uint64_t m_DeferredProcessExitRequest = 0
 
uint64_t m_SynchronousSignalMask = 0
 
size_t m_DeferredSubsystemExceptionState = 0
 
size_t m_DeferredSubsystemExceptionType = 0
 
uintptr_t m_DeferredSubsystemExceptionFaultAddress = 0
 
uintptr_t m_DeferredSubsystemExceptionErrorCode = 0
 
bool m_bTlsBaseOverride = false
 
bool m_bShutdown = false
 
bool m_bSubsystemExitNotified = false
 
uintptr_t m_ClearChildTid = 0
 
uintptr_t m_RobustList = 0
 
size_t m_RobustListOwnerId = 0
 
bool m_bStartRequested = false
 
bool m_bDetached = false
 
bool m_bJoinClaimed = false
 
bool m_bDetachedRetirementClaimed = false
 
bool m_bThreadExitRequested = false
 
bool m_bExitStarted = false
 
bool m_bReapable = false
 
bool m_bProcessExitOwned = false
 
bool m_bProcessExitParticipant = false
 
size_t m_EventDeferralDepth = 0
 
size_t m_TerminationDeferralDepth = 0
 
DeferredScopeRecord * m_pDeferredScopes [MAX_NESTED_EVENTS] = {}
 
size_t m_NextStateCleanupSequence = 0
 

Friends

class PerProcessorScheduler
 
class Scheduler
 
class PageFaultHandler
 
class Process
 
class WaitQueue
 
class Uninterruptible
 
class TerminationDeferral
 
class SyscallManager
 
class IrqHandlerRegistry
 
class TimerHandlerRegistry
 
class HostedInterruptManager
 
class RoundRobin
 
class ExecutionContextGuard
 
class RequestQueueCallbackScope
 
class SchedulerTimerDispatchCleanup
 

Detailed Description

An abstraction of a thread of execution.

The thread maintains not just one execution context (SchedulerState) but a stack of them, along with a stack of masks for inhibiting event dispatch.

This enables event dispatch at any time without affecting the previous state, as well as changing the event mask from nested event handlers without affecting the state of any other running handler.

Definition at line 77 of file Thread.h.

Member Typedef Documentation

◆ SecurityStateRef

Definition at line 231 of file Thread.h.

◆ ThreadStartFunc

typedef int(* Thread::ThreadStartFunc) (void *)

Thread start function type.

Definition at line 189 of file Thread.h.

Member Enumeration Documentation

◆ DebugState

"Debug state" - higher level state of the thread.

Definition at line 177 of file Thread.h.

◆ EventSelection

enum class Thread::EventSelection
strongprivate

Definition at line 1020 of file Thread.h.

◆ InterruptionReason

enum Thread::InterruptionReason

Definition at line 486 of file Thread.h.

◆ Status

The state that a thread can possibly have.

Definition at line 167 of file Thread.h.

◆ UnwindType

Enum used by the following function.

Enumerator
Continue 

No unwind necessary, carry on as normal.

Exit 

Exit the owning process at the next safe boundary.

TerminateThread 

Exit only this thread during Process exit.

Definition at line 516 of file Thread.h.

◆ UserReturnWorkFlag

enum Thread::UserReturnWorkFlag : size_t

Definition at line 129 of file Thread.h.

Constructor & Destructor Documentation

◆ Thread() [1/4]

Thread::Thread ( Process *  pParent,
ThreadStartFunc  pStartFunction,
void *  pParam,
void *  pStack = 0,
bool  semiUser = false,
bool  bDontPickCore = false,
bool  delayedStart = false,
const ThreadPlacement *  placement = nullptr 
)

Creates a new Thread belonging to the given Process. It shares the Process' * virtual address space.

The constructor registers itself with the Scheduler and parent process - this * does not need to be done manually.

If kernelMode is true, and pStack is NULL, no stack space is assigned.

Parameters
pParentThe parent process. Can never be NULL.
kernelModeIs the thread going to be operating in kernel space only? *
pStartFunctionThe function to be run when the thread starts. *
pParamA parameter to give the startFunction. *
pStack(Optional) A (user mode) stack to give the thread - applicable for user mode threads * only. *
semiUser(Optional) Whether to start the thread as if it was a user mode thread, but begin in kernel mode (to do setup and jump to usermode manually). *
delayedStart(Optional) Start the thread in a halted state.

Definition at line 224 of file Thread.cc.

References Spinlock::acquire(), Process::addThread(), Scheduler::addThread(), ProcessorThreadAllocator::addThread(), allocateStackAtLevel(), getParent(), getScheduler(), getUnwindState(), ProcessorBase::information(), Scheduler::instance(), m_Id, Thread::StateLevel::m_InhibitMask, m_Lock, m_nStateLevel, m_pAllocatedStack, Thread::StateLevel::m_pAuxillaryStack, Thread::StateLevel::m_pKernelStack, m_pParent, Thread::StateLevel::m_SignalMask, m_Status, and TerminateThread.

◆ Thread() [2/4]

Thread::Thread ( Process *  pParent)

Alternative constructor - this should be used only by initialiseMultitasking() to define the first kernel thread.

Definition at line 304 of file Thread.cc.

References Process::addThread(), Scheduler::addThread(), Scheduler::instance(), m_Id, and m_pParent.

◆ Thread() [3/4]

Thread::Thread ( Process *  pParent,
SyscallState &  state,
bool  delayedStart = false,
const ThreadPlacement *  placement = nullptr 
)

Constructor for when forking a process. Assumes pParent has already been set up with a clone of the current address space and sets up the new thread to return to the caller in that address space.

Definition at line 322 of file Thread.cc.

References Spinlock::acquire(), Process::addThread(), ProcessorThreadAllocator::addThread(), allocateStackAtLevel(), getParent(), getUnwindState(), ProcessorBase::information(), NMFaultHandler::inheritCurrentThreadFpuState(), m_AlternateSignalStack, m_bTlsBaseOverride, m_Id, Thread::StateLevel::m_InhibitMask, m_Lock, m_nStateLevel, m_pAllocatedStack, m_pParent, m_pTlsBase, Thread::StateLevel::m_SignalMask, m_Status, state(), and TerminateThread.

◆ ~Thread()

Thread::~Thread ( )
virtual

◆ Thread() [4/4]

Thread::Thread ( const Thread &  )
private

Copy-constructor

Member Function Documentation

◆ abandonAllStates()

void Thread::abandonAllStates ( )

Abandons every nested event state before a no-return user transition.

Definition at line 965 of file Thread.cc.

References abandonCurrentState(), and getStateLevel().

Referenced by X64SyscallManager::syscall().

+ Here is the caller graph for this function:

◆ abandonCurrentState()

void Thread::abandonCurrentState ( bool  clean = false)

Abandons the current event state without running stack destructors.

Definition at line 956 of file Thread.cc.

References m_nStateLevel, and popState().

Referenced by abandonAllStates(), PerProcessorScheduler::eventHandlerReturned(), and X64SyscallManager::syscall().

+ Here is the caller graph for this function:

◆ acceptingEvents()

bool Thread::acceptingEvents ( )

Definition at line 2358 of file Thread.cc.

◆ accountTimerTick()

void Thread::accountTimerTick ( Time::Timestamp  delta,
bool  kernelMode 
)

Charges a scheduler tick using the saved interrupt mode, with IRQs masked.

Definition at line 422 of file Thread.cc.

References m_pParent, and publishTimeAccounting().

Referenced by PerProcessorScheduler::timer().

+ Here is the caller graph for this function:

◆ activeWaitPendingUnlocked()

bool Thread::activeWaitPendingUnlocked ( ) const
private

Definition at line 3690 of file Thread.cc.

◆ adoptInitialUserStackForExec()

void Thread::adoptInitialUserStackForExec ( VirtualAddressSpace::Stack *  stack)

Gives the replacement image's initial stack to this Thread's base state.

Definition at line 1018 of file Thread.cc.

References m_Lock.

Referenced by PosixSubsystem::invoke().

+ Here is the caller graph for this function:

◆ affinityWorkPending()

bool Thread::affinityWorkPending ( ) const
inline

Definition at line 249 of file Thread.h.

◆ allocateStackAtLevel()

void Thread::allocateStackAtLevel ( size_t  stateLevel)

Allocates a new stack for a specific nesting level, if required

Definition at line 1054 of file Thread.cc.

References VirtualAddressSpace::allocateStack(), VirtualAddressSpace::getKernelAddressSpace(), Thread::StateLevel::m_pKernelStack, Thread::StateLevel::m_State, and state().

Referenced by pushState(), Thread(), and Thread().

+ Here is the caller graph for this function:

◆ armAtomicStateCleanup()

void Thread::armAtomicStateCleanup ( AtomicStateCleanupRecord &  record,
AtomicStateCleanupRecord::Cleanup  cleanup,
void *  context 
)
protected

Definition at line 3494 of file Thread.cc.

◆ armStateCleanup()

void Thread::armStateCleanup ( DeferredScopeRecord &  record,
DeferredScopeRecord::Cleanup  cleanup,
void *  context 
)
protected

Definition at line 3295 of file Thread.cc.

◆ beginExternalLease()

bool Thread::beginExternalLease ( )
private

◆ beginTemporarySignalMask()

size_t Thread::beginTemporarySignalMask ( uint64_t  signalMask)
private

Definition at line 2080 of file Thread.cc.

◆ canSkipUserReturnWork()

bool Thread::canSkipUserReturnWork ( )

Definition at line 78 of file Thread-user-return.cc.

◆ cleanStateLevel()

void Thread::cleanStateLevel ( size_t  level)
private

◆ clearInterruption()

void Thread::clearInterruption ( )
inline

Definition at line 497 of file Thread.h.

◆ clearSignalFrameRequirement()

void Thread::clearSignalFrameRequirement ( )

Definition at line 58 of file Thread-user-return.cc.

◆ clearTerminalWaitCancelledBeforeBlockUnlocked()

void Thread::clearTerminalWaitCancelledBeforeBlockUnlocked ( size_t  level)
private

Definition at line 3716 of file Thread.cc.

◆ clearUserReturnWorkFlag()

void Thread::clearUserReturnWorkFlag ( UserReturnWorkFlag  flag)
inlineprotected

Definition at line 970 of file Thread.h.

◆ clearUserReturnWorkIfIdle()

bool Thread::clearUserReturnWorkIfIdle ( )

Definition at line 85 of file Thread-user-return.cc.

◆ closeExternalLeaseAdmission()

void Thread::closeExternalLeaseAdmission ( )
private

Prevents any further Process::ThreadLease acquisition.

Definition at line 2946 of file Thread.cc.

References m_bExternalLeaseAdmissionClosed, and m_ExternalLeaseLock.

◆ closeExternalLeaseAdmissionAndDrain()

void Thread::closeExternalLeaseAdmissionAndDrain ( )
private

Closes external admission and drains every previously admitted lease.

Definition at line 2951 of file Thread.cc.

References m_bExternalLeaseAdmissionClosed, m_bExternalLeaseReleaseInProgress, m_ExternalLeaseLock, m_ExternalLeaseWaiters, and m_nExternalLeases.

Referenced by detach(), joinInternal(), startDetached(), and Process::~Process().

+ Here is the caller graph for this function:

◆ commitSignalHandlerMask()

void Thread::commitSignalHandlerMask ( uint64_t  mask)

Transfers a deferred mask restoration into a successfully published frame.

Definition at line 1997 of file Thread.cc.

References m_Lock, m_nStateLevel, Thread::StateLevel::m_SignalMask, and state().

◆ completeAffinityAtSafePoint()

AffinityResult Thread::completeAffinityAtSafePoint ( bool *  waited = nullptr)

Current-thread gate for an audited continuation without CPU-local state. Applies the latest acknowledged mask without changing it; returns with interrupts disabled, including Terminal. Ordinary waits are not gates.

Definition at line 157 of file Thread-affinity.cc.

References Process::beginExternalLease(), beginExternalLease(), Continue, Process::endExternalLease(), endExternalLease(), getScheduler(), getUnwindState(), ProcessorBase::information(), m_bShutdown, m_Lock, m_pParent, and ProcessorBase::setInterrupts().

Referenced by X64InterruptManager::returnFromInterrupt(), and X64SyscallManager::syscall().

+ Here is the caller graph for this function:

◆ consumeTerminalWaitCancelledBeforeBlockUnlocked()

bool Thread::consumeTerminalWaitCancelledBeforeBlockUnlocked ( )
private

Definition at line 3703 of file Thread.cc.

◆ cullEvent() [1/2]

void Thread::cullEvent ( Event *  pEvent)

Walks the event queue, removing the event pEvent , if found.

Definition at line 2172 of file Thread.cc.

References List< T, nodePoolSize >::begin(), Event::deregisterThread(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), m_EventQueue, and m_Lock.

◆ cullEvent() [2/2]

void Thread::cullEvent ( size_t  eventNumber)

Walks the event queue, removing the event with number eventNumber , if found.

Definition at line 2194 of file Thread.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), m_EventQueue, m_Lock, and Vector< T >::pushBack().

◆ cullSignalEvent()

void Thread::cullSignalEvent ( size_t  signalNumber)

Removes only signal events matching signalNumber from the queue.

Definition at line 2216 of file Thread.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), m_EventQueue, m_Lock, and Vector< T >::pushBack().

Referenced by PosixSubsystem::queueSignalDelivery(), and PosixSubsystem::setSignalHandler().

+ Here is the caller graph for this function:

◆ cullSignalSource()

void Thread::cullSignalSource ( const void *  source)

Definition at line 2448 of file Thread.cc.

◆ currentTimeAccountingMode()

CpuTimeMode Thread::currentTimeAccountingMode ( ) const

Current accounting owner; never used to classify interrupt origin.

Definition at line 471 of file Thread.cc.

References m_CurrentTimeAccountingMode.

Referenced by InterruptTimeAccounting::finishUserReturn(), PerProcessorScheduler::serviceProcessStopAtUserReturn(), and HostedSyscallManager::syscall().

+ Here is the caller graph for this function:

◆ currentUserReturnFrame()

UserReturnFrame * Thread::currentUserReturnFrame ( ) const

Definition at line 42 of file Thread-user-return.cc.

◆ deferEvents()

void Thread::deferEvents ( )
protected

Definition at line 3192 of file Thread.cc.

◆ deferProcessExit()

void Thread::deferProcessExit ( int  code)

Defers process exit, including its status, to a safe thread boundary.

Definition at line 3605 of file Thread.cc.

References Exit, m_DeferredProcessExitRequest, and setUnwindState().

◆ deferSignalExit()

void Thread::deferSignalExit ( int  signal)

Defers signal-caused process exit to a safe thread boundary.

Definition at line 3612 of file Thread.cc.

References Exit, m_DeferredProcessExitRequest, and setUnwindState().

Referenced by PosixSubsystem::invoke(), and PosixSubsystem::threadException().

+ Here is the caller graph for this function:

◆ deferSubsystemException()

bool Thread::deferSubsystemException ( size_t  type,
uintptr_t  faultAddress,
uintptr_t  errorCode 
)

Publishes a synchronous userspace exception without taking locks or allocating from its raw interrupt frame.

Definition at line 3627 of file Thread.cc.

References m_DeferredSubsystemExceptionState.

Referenced by HostedInterruptManager::interrupt(), X64InterruptManager::interrupt(), and PageFaultHandler::interrupt().

+ Here is the caller graph for this function:

◆ deferTermination()

void Thread::deferTermination ( )
protected

Definition at line 3231 of file Thread.cc.

◆ detach()

bool Thread::detach ( )

Marks the thread as detached.

A detached thread cannot be joined and will be automatically cleaned up when the thread entry point returns, or the thread is otherwise terminated. A thread cannot be detached if another thread is already join()ing it.

Definition at line 2987 of file Thread.cc.

References Process::beginThreadJoin(), closeExternalLeaseAdmissionAndDrain(), Process::endThreadJoin(), m_bDetached, m_bDetachedRetirementClaimed, m_bJoinClaimed, m_bProcessExitOwned, m_bReapable, m_JoinWaiters, Process::m_Lock, and m_pParent.

◆ detached()

bool Thread::detached ( ) const
inline

Checks detached state of the thread.

Definition at line 910 of file Thread.h.

◆ disarmAtomicStateCleanup()

void Thread::disarmAtomicStateCleanup ( AtomicStateCleanupRecord &  record)
protected

Definition at line 3524 of file Thread.cc.

◆ disarmStateCleanup()

void Thread::disarmStateCleanup ( DeferredScopeRecord &  record)
protected

Definition at line 3340 of file Thread.cc.

◆ discardJoin()

void Thread::discardJoin ( void *  context)
staticprivate

Releases a join claim if an exceptional stack discard cannot return.

Definition at line 2969 of file Thread.cc.

References Process::endThreadJoin(), m_bJoinClaimed, and m_JoinWaiters.

Referenced by joinInternal().

+ Here is the caller graph for this function:

◆ discardUserStackMetadataForExec()

void Thread::discardUserStackMetadataForExec ( )

Drops descriptors for user stacks whose mappings were removed by exec. The discarded image has already been unmapped, so this must not ask the address space to free those virtual ranges again.

Definition at line 981 of file Thread.cc.

References ProcessorBase::information(), and m_Lock.

Referenced by PosixSubsystem::invoke().

+ Here is the caller graph for this function:

◆ endExternalLease()

void Thread::endExternalLease ( )
private

◆ eventIsDeliverableUnlocked()

bool Thread::eventIsDeliverableUnlocked ( Event *  event,
EventSelection  selection = EventSelection::AnyDeliverable 
)
private

Definition at line 2510 of file Thread.cc.

◆ eventNeedsUserReturnFrameUnlocked()

bool Thread::eventNeedsUserReturnFrameUnlocked ( Event *  event) const
private

Checks one event against masks and process state while m_Lock is held.

Definition at line 64 of file Thread-user-return.cc.

Referenced by markDeferredUserReturnSignalInterruption().

+ Here is the caller graph for this function:

◆ eventsDeferred()

bool Thread::eventsDeferred ( ) const

Gets whether event delivery is currently deferred.

Definition at line 3159 of file Thread.cc.

References m_EventDeferralDepth.

Referenced by PerProcessorScheduler::checkEventState(), and publishTimeAccounting().

+ Here is the caller graph for this function:

◆ executionContext()

ExecutionContext Thread::executionContext ( ) const

Returns this Thread's explicit logical execution context.

Definition at line 836 of file Thread.cc.

References Thread::StateLevel::m_ExecutionContext, and m_nStateLevel.

Referenced by ProcessorBase::executionContext().

+ Here is the caller graph for this function:

◆ executionPersonality()

ExecutionPersonality & Thread::executionPersonality ( )
inline

Definition at line 428 of file Thread.h.

◆ finishTemporarySignalMask()

bool Thread::finishTemporarySignalMask ( size_t  stateLevel,
bool  deferForUserReturn = true 
)
private

Definition at line 2104 of file Thread.cc.

◆ forceToStartupProcessor()

void Thread::forceToStartupProcessor ( )

Definition at line 679 of file Thread.cc.

◆ getAlternateSignalStack()

AlternateSignalStack & Thread::getAlternateSignalStack ( )
inline

Definition at line 764 of file Thread.h.

◆ getCpuId()

size_t Thread::getCpuId ( )
inline

Gets this thread's CPU ID

Definition at line 865 of file Thread.h.

◆ getCurrentSignalDelivery()

bool Thread::getCurrentSignalDelivery ( size_t &  signalNumber,
size_t &  continuationEpoch 
)

Retrieves trusted metadata for the signal dispatched at the current level.

Definition at line 2028 of file Thread.cc.

References Thread::StateLevel::m_DispatchedSignalNumber, m_Lock, m_nStateLevel, and state().

◆ getDebugState()

DebugState Thread::getDebugState ( uintptr_t &  address)
inline

Returns the thread's debug state.

Definition at line 574 of file Thread.h.

Referenced by Rtc::drainRemoteAlarmDispatch(), and IrqHandlerRegistry::unregisterHandler().

+ Here is the caller graph for this function:

◆ getErrno()

size_t Thread::getErrno ( )
inline

Returns the last error that occurred (errno).

Definition at line 477 of file Thread.h.

Referenced by HostedSyscallManager::syscall(), and X64SyscallManager::syscall().

+ Here is the caller graph for this function:

◆ getExitCode()

int Thread::getExitCode ( )
inline

Retrieves the exit status of the Thread.

Definition at line 454 of file Thread.h.

◆ getId()

size_t Thread::getId ( )
inline

◆ getInterruptionReason()

InterruptionReason Thread::getInterruptionReason ( )
inline

Definition at line 501 of file Thread.h.

◆ getKernelStack()

void * Thread::getKernelStack ( )

Retrieves a pointer to the top of the Thread's kernel stack.

Definition at line 1070 of file Thread.cc.

References m_nStateLevel, and Thread::StateLevel::m_pKernelStack.

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

+ Here is the caller graph for this function:

◆ getKernelStackBase()

void * Thread::getKernelStackBase ( size_t *  size) const

Retrieves a pointer to the bottom of the Thread's kernel stack, and its size.

Definition at line 1080 of file Thread.cc.

References m_nStateLevel, Thread::StateLevel::m_pAuxillaryStack, and Thread::StateLevel::m_pKernelStack.

◆ getKernelTime()

Time::Timestamp Thread::getKernelTime ( ) const
inline

Definition at line 415 of file Thread.h.

◆ getLock()

Spinlock & Thread::getLock ( )
inline

Returns the thread's scheduler lock.

Definition at line 613 of file Thread.h.

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

+ Here is the caller graph for this function:

◆ getName()

const String & Thread::getName ( ) const
inline

Definition at line 933 of file Thread.h.

◆ getNextEvent()

Event::Delivery Thread::getNextEvent ( EventSelection  selection = EventSelection::AnyDeliverable)
private

Scheduler-only dequeue that retains the Event delivery registration.

Definition at line 2466 of file Thread.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), m_EventDeferralDepth, m_EventQueue, and m_Lock.

Referenced by PerProcessorScheduler::checkEventState().

+ Here is the caller graph for this function:

◆ getOriginalSyscallState()

const SyscallState * Thread::getOriginalSyscallState ( ) const
inline

Original syscall image, available only during its normal user-return work.

Definition at line 723 of file Thread.h.

◆ getParent()

Process * Thread::getParent ( ) const
inline

◆ getPriority()

size_t Thread::getPriority ( )
inline

Definition at line 814 of file Thread.h.

◆ getRobustList()

uintptr_t Thread::getRobustList ( ) const
inline

Definition at line 354 of file Thread.h.

◆ getScheduler()

class PerProcessorScheduler * Thread::getScheduler ( ) const
inline

Gets the per-processor scheduler for this Thread.

Definition at line 929 of file Thread.h.

Referenced by PerProcessorScheduler::checkEventState(), completeAffinityAtSafePoint(), Scheduler::recordCpuTime(), requestAffinity(), PosixSubsystem::sendSignal(), Process::suspendInternal(), X64SyscallManager::syscall(), and Thread().

+ Here is the caller graph for this function:

◆ getSignalMask()

uint64_t Thread::getSignalMask ( )

Retrieves the POSIX signal mask for the current event nesting level.

Definition at line 1981 of file Thread.cc.

References m_Lock, m_nStateLevel, and Thread::StateLevel::m_SignalMask.

Referenced by PosixSubsystem::queueSignalDelivery(), and SignalEvent::serialize().

+ Here is the caller graph for this function:

◆ getSignalMaskForReturnFrame()

uint64_t Thread::getSignalMaskForReturnFrame ( )

Saves the pre-wait mask when delivery completes an interrupted masked wait.

Definition at line 1991 of file Thread.cc.

References m_Lock, m_nStateLevel, and state().

◆ getStateLevel()

size_t Thread::getStateLevel ( ) const
inline

Returns the state nesting level.

Definition at line 316 of file Thread.h.

Referenced by abandonAllStates(), PerProcessorScheduler::checkEventState(), prepareSignalStateForExec(), and threadExited().

+ Here is the caller graph for this function:

◆ getStateUserStack()

VirtualAddressSpace::Stack * Thread::getStateUserStack ( )

Definition at line 973 of file Thread.cc.

◆ getStatus()

Status Thread::getStatus ( ) const
inline

Retrieves our current status.

Definition at line 433 of file Thread.h.

Referenced by PerProcessorScheduler::addThread(), PerProcessorScheduler::addThread(), Scheduler::sampleLoadAverage(), and Process::~Process().

+ Here is the caller graph for this function:

◆ getSynchronousSignalMask()

uint64_t Thread::getSynchronousSignalMask ( )

Definition at line 2368 of file Thread.cc.

◆ getSyscallDispatchContext()

void * Thread::getSyscallDispatchContext ( ) const
inline

Definition at line 320 of file Thread.h.

◆ getTaskId()

size_t Thread::getTaskId ( ) const
inline

Definition at line 472 of file Thread.h.

◆ getTlsBase()

uintptr_t Thread::getTlsBase ( )

◆ getUnwindState()

UnwindType Thread::getUnwindState ( )
inline

Returns nonzero if the thread has been asked to unwind quickly.

This happens if this thread (or a thread blocking on this thread) is scheduled for deletion. The intended behaviour is that the stack is unwound as quickly as possible with all semaphores and buffers deleted to a point where

(a) no threads can possibly be blocking on this or (b) The thread has no more locks taken and is ready to be destroyed, at which point it should call the subsys exit() function.

Whether to adopt option A or B depends on whether this thread or not has been asked to terminate, given by the return value.

Definition at line 535 of file Thread.h.

Referenced by Process::acquireProcessSignalThread(), PerProcessorScheduler::commitUserReturnTerminalState(), completeAffinityAtSafePoint(), PosixSubsystem::invoke(), Process::prepareThreadExit(), PosixSubsystem::queueSignalDelivery(), requestAffinity(), PerProcessorScheduler::serviceProcessStopAtUserReturn(), PerProcessorScheduler::serviceUserReturnWork(), start(), startDetached(), HostedSyscallManager::syscall(), X64SyscallManager::syscall(), Thread(), Thread(), and threadExited().

+ Here is the caller graph for this function:

◆ getUserGsBase()

uintptr_t Thread::getUserGsBase ( ) const
inline

Definition at line 851 of file Thread.h.

◆ getUserspaceTaskId()

size_t Thread::getUserspaceTaskId ( const UserspacePidNamespace *  space = nullptr) const

Linux task IDs share the PID namespace; internal slots remain local.

Definition at line 3743 of file Thread.cc.

References Process::getId(), Process::getUserspaceId(), and m_pParent.

◆ getUserTime()

Time::Timestamp Thread::getUserTime ( ) const
inline

Gets CPU time charged specifically to this Thread.

Definition at line 412 of file Thread.h.

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

+ Here is the caller graph for this function:

◆ getWaitDebugInfo()

bool Thread::getWaitDebugInfo ( WaitDebugInfo &  info)

Takes a best-effort snapshot of the active wait for the debugger.

Definition at line 3163 of file Thread.cc.

References m_nStateLevel, and Thread::StateLevel::m_Waiter.

◆ hasActiveTemporarySignalMask()

bool Thread::hasActiveTemporarySignalMask ( )

True while the current state owns a temporary signal mask.

Definition at line 2151 of file Thread.cc.

References m_Lock, and m_nStateLevel.

◆ hasActiveWaitAtAnyLevel()

bool Thread::hasActiveWaitAtAnyLevel ( ) const
private

Definition at line 3681 of file Thread.cc.

◆ hasActiveWaitUnlocked()

bool Thread::hasActiveWaitUnlocked ( ) const
private

Definition at line 3677 of file Thread.cc.

◆ hasDeferredSubsystemException()

bool Thread::hasDeferredSubsystemException ( ) const
inline

Definition at line 561 of file Thread.h.

◆ hasDeliverableEventsUnlocked()

bool Thread::hasDeliverableEventsUnlocked ( EventSelection  selection = EventSelection::AnyDeliverable)
private

Definition at line 2597 of file Thread.cc.

◆ hasEvent() [1/2]

bool Thread::hasEvent ( Event *  pEvent)

Determines if the given event is currently in the event queue.

Definition at line 2618 of file Thread.cc.

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

◆ hasEvent() [2/2]

bool Thread::hasEvent ( size_t  eventNumber)

Definition at line 2630 of file Thread.cc.

◆ hasEvents()

bool Thread::hasEvents ( )

Definition at line 2504 of file Thread.cc.

◆ hasEventsUnlocked()

bool Thread::hasEventsUnlocked ( EventSelection  selection = EventSelection::AnyDeliverable)
private

Checks for an event that can run while m_Lock is already held.

Definition at line 2587 of file Thread.cc.

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

◆ hasSecurityState()

bool Thread::hasSecurityState ( ) const
inline

Definition at line 232 of file Thread.h.

◆ hasSignalEvent()

bool Thread::hasSignalEvent ( size_t  signalNumber,
int  processDirected = -1 
)

Filters process/thread provenance when specified; -1 matches either.

Definition at line 2345 of file Thread.cc.

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

Referenced by PosixSubsystem::queueSignalDelivery().

+ Here is the caller graph for this function:

◆ hasTemporarySignalWaitInterruption()

bool Thread::hasTemporarySignalWaitInterruption ( )

True only while the current state owns an interrupted temporary signal wait.

Definition at line 2144 of file Thread.cc.

References m_Lock, m_nStateLevel, and state().

◆ inhibitEvent()

void Thread::inhibitEvent ( size_t  eventNumber,
bool  bInhibit 
)

Sets the given event number as inhibited.

Parameters
bInhibitTrue if the event is to be inhibited, false if the event is to be allowed.

Definition at line 1973 of file Thread.cc.

References ExtensibleBitmap::clear(), Thread::StateLevel::m_InhibitMask, m_Lock, m_nStateLevel, and ExtensibleBitmap::set().

◆ initialisePlacement()

void Thread::initialisePlacement ( const ThreadPlacement *  placement)
private

Definition at line 54 of file Thread-affinity.cc.

◆ interruptWaitUnlocked()

bool Thread::interruptWaitUnlocked ( WaitQueue::WakeReason  reason,
PerProcessorScheduler *&  readyScheduler 
)
private

Interrupts the active wait at the current event nesting level.

Definition at line 3657 of file Thread.cc.

References m_nStateLevel, m_Status, and Thread::StateLevel::m_Waiter.

Referenced by sendEvent(), setUnwindState(), and wakeForDeliverableEvents().

+ Here is the caller graph for this function:

◆ isTerminationDeferred()

bool Thread::isTerminationDeferred ( ) const
inline

True while an explicit terminal-teardown deferral is active.

Definition at line 569 of file Thread.h.

Referenced by PerProcessorScheduler::commitUserReturnTerminalState(), and PerProcessorScheduler::serviceUserReturnWork().

+ Here is the caller graph for this function:

◆ join()

bool Thread::join ( )

Blocks until the Thread returns.

After join() returns successfully, the thread object is NOT valid.

Returns
whether the thread was joined or not.

Definition at line 2746 of file Thread.cc.

References joinInternal().

Referenced by pocketknife::attachTo().

+ Here is the caller graph for this function:

◆ joinForCompletion()

bool Thread::joinForCompletion ( )

Joins as a lifetime barrier which terminal teardown cannot abandon.

Use only for owned worker destruction/cleanup. Ordinary callers should use join(), which remains interruptible.

Definition at line 2750 of file Thread.cc.

References joinInternal().

Referenced by pocketknife::attachToForCompletion(), OwnedThread::join(), and InputManager::shutdown().

+ Here is the caller graph for this function:

◆ joinInternal()

bool Thread::joinInternal ( bool  completion)
private

◆ markDeferredUserReturnSignalInterruption()

void Thread::markDeferredUserReturnSignalInterruption ( )
private

Marks a caught signal deferred until an exact user-return boundary.

Definition at line 2551 of file Thread.cc.

References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), eventNeedsUserReturnFrameUnlocked(), Event::isSignalEvent(), Thread::StateLevel::m_bDispatchingWaitEvent, m_EventQueue, m_EventWaiters, m_Lock, and m_nStateLevel.

Referenced by PerProcessorScheduler::checkEventState().

+ Here is the caller graph for this function:

◆ markReapable()

bool Thread::markReapable ( )
private

Completes exit after the scheduler has switched away from our stack. Returns true when a concurrent detach made immediate deletion safe.

Definition at line 3721 of file Thread.cc.

References m_bDetached, m_bDetachedRetirementClaimed, m_bExternalLeaseAdmissionClosed, m_bExternalLeaseReleaseInProgress, m_bProcessExitOwned, m_bReapable, m_ExternalLeaseLock, m_JoinWaiters, and m_nExternalLeases.

◆ markSignalInterruptedWait()

void Thread::markSignalInterruptedWait ( )

Marks a signal only when its delivery actually interrupted a wait.

Definition at line 3131 of file Thread.cc.

References Thread::StateLevel::m_bDispatchingWaitEvent, m_EventWaiters, m_Lock, and m_nStateLevel.

Referenced by SignalEvent::serialize().

+ Here is the caller graph for this function:

◆ markTerminalWaitCancelledBeforeBlockUnlocked()

void Thread::markTerminalWaitCancelledBeforeBlockUnlocked ( size_t  level)
private

A terminal cancel can unlink a published waiter before its owner has entered the scheduler sleep transition. These helpers carry that handoff under m_Lock without leaving a stale waiter visible to future sleeps.

Definition at line 3695 of file Thread.cc.

References state().

◆ markTimeoutInterruptedWait()

void Thread::markTimeoutInterruptedWait ( )

Marks a timeout in the context interrupted by the current event.

Definition at line 3126 of file Thread.cc.

References m_nStateLevel.

◆ markUserReturnWorkFlag()

void Thread::markUserReturnWorkFlag ( UserReturnWorkFlag  flag)
inlineprotected

Definition at line 967 of file Thread.h.

◆ markUserReturnWorkPending()

void Thread::markUserReturnWorkPending ( )
inlineprotected

Definition at line 973 of file Thread.h.

◆ moveTerminationDeferral()

void Thread::moveTerminationDeferral ( DeferredScopeRecord &  from,
DeferredScopeRecord &  to 
)
protected

Definition at line 3374 of file Thread.cc.

◆ notifySubsystemExit()

void Thread::notifySubsystemExit ( )

Runs subsystem exit hooks once, while the lifecycle owner can still block and before the final scheduler handoff.

Definition at line 547 of file Thread.cc.

References VirtualAddressSpace::freeStack(), Process::getAddressSpace(), m_bSubsystemExitNotified, m_pParent, and Process::threadExiting().

Referenced by PosixSubsystem::exit(), and shutdown().

+ Here is the caller graph for this function:

◆ operator=()

Thread & Thread::operator= ( const Thread &  )
private

Assignment operator

◆ pendingSignalMask()

uint64_t Thread::pendingSignalMask ( bool  processOnly = false)

Definition at line 2373 of file Thread.cc.

◆ pendingSignalOrder()

uint64_t Thread::pendingSignalOrder ( size_t  signal,
bool  processOnly = false 
)

Definition at line 2388 of file Thread.cc.

◆ pokeState()

void Thread::pokeState ( size_t  stateLevel,
SchedulerState &  state 
)

Overwrites the state at the given nesting level.

Parameters
stateLevelThe nesting level to edit.
stateThe state to copy.

Definition at line 1107 of file Thread.cc.

References Thread::StateLevel::m_State, and state().

◆ popState()

void Thread::popState ( bool  clean = true)

Decreases the state nesting level by one, popping both the state stack and the inhibit mask stack. If clean == true, the stacks and other resources will also be cleaned up. Pass clean = false if losing the stack would be dangerous in a particular context.

Definition at line 913 of file Thread.cc.

References cleanStateLevel(), ProcessorBase::getInterrupts(), m_AlternateSignalStack, Thread::StateLevel::m_bOwnsAlternateSignalStack, m_Lock, m_nStateLevel, m_pDeferredScopes, ProcessorBase::setInterrupts(), and setKernelStack().

Referenced by abandonCurrentState(), and PerProcessorScheduler::checkEventState().

+ Here is the caller graph for this function:

◆ prepareSignalStateForExec()

void Thread::prepareSignalStateForExec ( )

◆ publishDeferredScope()

ALWAYS_INLINE void Thread::publishDeferredScope ( DeferredScopeRecord &  record,
bool  termination,
bool  events,
DeferredScopeRecord::Cleanup  cleanup,
void *  context 
)
inlineprivate

Definition at line 3243 of file Thread.cc.

◆ publishReadyNotification()

void Thread::publishReadyNotification ( )
private

Definition at line 245 of file Thread-affinity.cc.

◆ publishTimeAccounting()

void Thread::publishTimeAccounting ( CpuTimeMode  mode,
Time::Timestamp  elapsed 
)
private

Adds one elapsed interval and requests any interested process timer report.

Definition at line 435 of file Thread.cc.

References eventsDeferred(), Scheduler::instance(), m_pParent, m_UserTime, and Scheduler::recordCpuTime().

Referenced by accountTimerTick(), trackTime(), and transitionTime().

+ Here is the caller graph for this function:

◆ pushState()

SchedulerState * Thread::pushState ( )

Increases the state nesting level by one - pushes a new state to the top of the state stack. This also pushes the event mask and per-context syscall state.

Returns
A reference to the previous state. Pushes an event state, or returns null when nesting is exhausted.

Definition at line 841 of file Thread.cc.

References allocateStackAtLevel(), ProcessorBase::getInterrupts(), Thread::StateLevel::m_bDispatchingWaitEvent, Thread::StateLevel::m_bOwnsAlternateSignalStack, Thread::StateLevel::m_DispatchedSignalNumber, Thread::StateLevel::m_Errno, Thread::StateLevel::m_ExecutionContext, Thread::StateLevel::m_InhibitMask, m_Lock, m_nStateLevel, m_pDeferredScopes, Thread::StateLevel::m_pRequestQueueCallback, Thread::StateLevel::m_SavedSignalMask, Thread::StateLevel::m_SignalMask, Thread::StateLevel::m_State, ProcessorBase::setInterrupts(), and setKernelStack().

Referenced by PerProcessorScheduler::checkEventState().

+ Here is the caller graph for this function:

◆ recordTime()

void Thread::recordTime ( CpuTimeMode  mode)

Records this Thread's monotonic entry baseline for one CPU-time mode.

Definition at line 384 of file Thread.cc.

References m_CurrentTimeAccountingMode, m_TimeAccounting, and ThreadTimeAccounting::recordAtInterruptDisabled().

Referenced by PerProcessorScheduler::addThread(), PerProcessorScheduler::addThread(), and PerProcessorScheduler::initialise().

+ Here is the caller graph for this function:

◆ registerDeferredScope()

void Thread::registerDeferredScope ( DeferredScopeRecord &  record,
bool  termination,
bool  events 
)
protected

Definition at line 3286 of file Thread.cc.

◆ registerFreshTerminationDeferral()

void Thread::registerFreshTerminationDeferral ( DeferredScopeRecord &  record,
DeferredScopeRecord::Cleanup  cleanup = nullptr,
void *  context = nullptr 
)
private

Definition at line 3279 of file Thread.cc.

◆ replaceSignalEvent()

bool Thread::replaceSignalEvent ( size_t  signalNumber,
Event *  replacement,
int  processDirected = -1,
uint64_t  rebindGeneration = 0 
)

◆ requestAffinity()

AffinityResult Thread::requestAffinity ( const CpuAffinityMask &  mask,
uint64_t &  generation 
)

Success admits the returned generation; Busy names the existing one.

Definition at line 72 of file Thread-affinity.cc.

References Process::beginExternalLease(), beginExternalLease(), Continue, Process::endExternalLease(), endExternalLease(), getScheduler(), getUnwindState(), m_bShutdown, m_Lock, m_pParent, and m_Status.

◆ requiresSignalFrames()

bool Thread::requiresSignalFrames ( ) const
inline

Definition at line 143 of file Thread.h.

◆ reservePendingSignal()

Event::Delivery Thread::reservePendingSignal ( uint64_t  mask,
bool  processOnly = false,
uint64_t  expectedSequence = ~uint64_t(0) 
)

Definition at line 2402 of file Thread.cc.

◆ resetTlsBase()

void Thread::resetTlsBase ( )

Resets the TLS base address for this thread and re-maps it. Note: doesn't free the memory - only call after a call to something like revertToKernelAddressSpace!

Definition at line 2691 of file Thread.cc.

References getTlsBase(), m_bTlsBaseOverride, m_pTlsBase, and ProcessorBase::setTlsBase().

Referenced by PosixSubsystem::invoke().

+ Here is the caller graph for this function:

◆ restoreDeferredSignalMask()

void Thread::restoreDeferredSignalMask ( size_t  stateLevel)

Restores an interrupted wait's mask when no signal frame took ownership.

Definition at line 2007 of file Thread.cc.

References m_Lock, Thread::StateLevel::m_SignalMask, and state().

Referenced by cleanStateLevel().

+ Here is the caller graph for this function:

◆ restorePendingSignal()

bool Thread::restorePendingSignal ( Event::Delivery &  delivery)

Definition at line 2431 of file Thread.cc.

◆ resumeEvents()

void Thread::resumeEvents ( )
protected

Definition at line 3204 of file Thread.cc.

◆ resumeTermination()

void Thread::resumeTermination ( )
protected

Definition at line 3235 of file Thread.cc.

◆ retainTemporarySignalWaitInterruptionOrClear()

bool Thread::retainTemporarySignalWaitInterruptionOrClear ( )

Retains an armed temporary-wait signal, or atomically clears stale interruption state.

Definition at line 2156 of file Thread.cc.

References Spinlock::acquire(), ProcessorBase::getInterrupts(), m_Lock, m_nStateLevel, Spinlock::release(), ProcessorBase::setInterrupts(), and state().

◆ retireDeferredScopes()

void Thread::retireDeferredScopes ( bool  allStateLevels,
size_t  stateLevel = 0 
)
protected

Definition at line 3408 of file Thread.cc.

◆ retireDeferredScopesAfter()

void Thread::retireDeferredScopesAfter ( size_t  checkpoint)
protected

Definition at line 3416 of file Thread.cc.

◆ retireDeferredScopesMatching()

void Thread::retireDeferredScopesMatching ( bool  allStateLevels,
size_t  stateLevel,
bool  newerThanCheckpoint,
size_t  checkpoint 
)
protected

Definition at line 3420 of file Thread.cc.

◆ saveUserGsBase()

void Thread::saveUserGsBase ( )

Definition at line 2740 of file Thread.cc.

◆ securityState()

Thread::SecurityStateRef Thread::securityState ( )

Definition at line 53 of file Thread.cc.

◆ sendEvent()

bool Thread::sendEvent ( Event *  pEvent)

◆ setClearChildTid()

void Thread::setClearChildTid ( uintptr_t  address)

Replaces the userspace address cleared when this thread exits.

Definition at line 653 of file Thread.cc.

References m_bShutdown, m_ClearChildTid, and m_Lock.

Referenced by PosixSubsystem::invoke().

+ Here is the caller graph for this function:

◆ setCpuId()

void Thread::setCpuId ( size_t  id)
inline

Sets this thread's CPU ID

Definition at line 870 of file Thread.h.

Referenced by PerProcessorScheduler::addThread(), PerProcessorScheduler::addThread(), and PerProcessorScheduler::initialise().

+ Here is the caller graph for this function:

◆ setCurrentSignalDelivery()

void Thread::setCurrentSignalDelivery ( size_t  signalNumber,
size_t  continuationEpoch 
)

Records trusted metadata for the signal dispatched at the current level.

Definition at line 2021 of file Thread.cc.

References Thread::StateLevel::m_DispatchedSignalNumber, m_Lock, m_nStateLevel, and state().

Referenced by SignalEvent::serialize().

+ Here is the caller graph for this function:

◆ setDebugState()

void Thread::setDebugState ( DebugState  state,
uintptr_t  address 
)
inline

Sets the thread's debug state.

Definition at line 593 of file Thread.h.

Referenced by Rtc::drainRemoteAlarmDispatch(), and IrqHandlerRegistry::unregisterHandler().

+ Here is the caller graph for this function:

◆ setErrno()

void Thread::setErrno ( size_t  err)
inline

Sets the last error - errno.

Definition at line 482 of file Thread.h.

Referenced by HostedSyscallManager::syscall(), and X64SyscallManager::syscall().

+ Here is the caller graph for this function:

◆ setInterruptionReason()

void Thread::setInterruptionReason ( InterruptionReason  reason)
inline

Definition at line 505 of file Thread.h.

◆ setKernelStack()

void Thread::setKernelStack ( )

Sets the new kernel stack for the current state level in the TSS

Definition at line 1099 of file Thread.cc.

References ProcessorBase::information(), m_nStateLevel, and Thread::StateLevel::m_pKernelStack.

Referenced by popState(), and pushState().

+ Here is the caller graph for this function:

◆ setName() [1/2]

template<size_t N>
void Thread::setName ( const char(&)  name[N])
inline

Definition at line 942 of file Thread.h.

◆ setName() [2/2]

void Thread::setName ( const String &  name)
inline

Definition at line 937 of file Thread.h.

◆ setOriginalSyscallState()

void Thread::setOriginalSyscallState ( const SyscallState *  state)
inline

Definition at line 727 of file Thread.h.

◆ setParent()

void Thread::setParent ( Process *  p)
inline

Definition at line 424 of file Thread.h.

◆ setPriority()

void Thread::setPriority ( size_t  p)
inline

Definition at line 811 of file Thread.h.

◆ setRobustList()

void Thread::setRobustList ( uintptr_t  address,
size_t  ownerId 
)

Definition at line 664 of file Thread.cc.

◆ setScheduler()

void Thread::setScheduler ( class PerProcessorScheduler *  pScheduler)
protected

Sets the scheduler for the Thread.

Definition at line 3531 of file Thread.cc.

Referenced by Scheduler::addThread(), PerProcessorScheduler::addThread(), and PerProcessorScheduler::addThread().

+ Here is the caller graph for this function:

◆ setSecurityState()

void Thread::setSecurityState ( const SecurityStateRef &  state)

Definition at line 58 of file Thread.cc.

◆ setSignalMask()

void Thread::setSignalMask ( uint64_t  mask)

Sets the POSIX signal mask for the current event nesting level.

Definition at line 1986 of file Thread.cc.

References m_Lock, m_nStateLevel, and Thread::StateLevel::m_SignalMask.

Referenced by SignalEvent::serialize().

+ Here is the caller graph for this function:

◆ setStateUserStack()

void Thread::setStateUserStack ( VirtualAddressSpace::Stack *  st)

Definition at line 977 of file Thread.cc.

◆ setStatus()

void Thread::setStatus ( Thread::Status  s)
private

Scheduler-only status transition primitive.

Definition at line 719 of file Thread.cc.

References m_Lock.

Referenced by PerProcessorScheduler::initialise(), and shutdown().

+ Here is the caller graph for this function:

◆ setStatusUnlocked()

void Thread::setStatusUnlocked ( Thread::Status  s)
private

Definition at line 724 of file Thread.cc.

◆ setSynchronousSignalMask()

void Thread::setSynchronousSignalMask ( uint64_t  mask)

Definition at line 2363 of file Thread.cc.

◆ setSyscallDispatchContext()

void Thread::setSyscallDispatchContext ( void *  context)
inline

Definition at line 323 of file Thread.h.

◆ setTlsBase()

void Thread::setTlsBase ( uintptr_t  base)

Set the TLS base for this thread. Once set, it must be cleaned up by the caller when the thread terminates, which makes this primarily useful for userspace TLS segments. This does not access the supplied memory.

Todo:
clean up old base

Definition at line 2722 of file Thread.cc.

References getTlsBase(), ProcessorBase::information(), m_bTlsBaseOverride, m_pTlsBase, and ProcessorBase::setTlsBase().

◆ setUnwindState()

void Thread::setUnwindState ( UnwindType  ut)

Sets the above unwind state.

Definition at line 3580 of file Thread.cc.

References Continue, Scheduler::instance(), interruptWaitUnlocked(), m_Lock, m_Status, PerProcessorScheduler::publishReadyFromWait(), and TerminateThread.

Referenced by deferProcessExit(), deferSignalExit(), PosixSubsystem::exit(), and startDetached().

+ Here is the caller graph for this function:

◆ setUserGsBase()

void Thread::setUserGsBase ( uintptr_t  base)

Definition at line 2733 of file Thread.cc.

◆ setUserReturnSignalParked()

void Thread::setUserReturnSignalParked ( bool  parked)

Definition at line 69 of file Thread-user-return.cc.

◆ shutdown()

void Thread::shutdown ( )

Performs termination steps on the thread, while the thread is still able to reschedule. Required as ~Thread() is called in a context where the thread has been removed from the scheduler, and triggering a reschedule may add the thread back to the ready queue by accident.

Definition at line 570 of file Thread.cc.

References Event::completeDelivery(), List< T, nodePoolSize >::count(), m_bExitStarted, m_bShutdown, m_EventQueue, m_EventSenderDrainWaiters, m_EventSendersInFlight, m_JoinWaiters, m_Lock, m_pParent, notifySubsystemExit(), List< T, nodePoolSize >::popFront(), setStatus(), Process::transferExecProcessSignals(), and unlinkWaitsForStackDiscard().

Referenced by ~Thread().

+ Here is the caller graph for this function:

◆ snapshotPlacement()

void Thread::snapshotPlacement ( ThreadPlacement &  placement)

Definition at line 63 of file Thread-affinity.cc.

◆ snapshotPlacementLocked()

void Thread::snapshotPlacementLocked ( ThreadPlacement &  placement) const

The allocator already holds the new Thread's construction lock.

Definition at line 68 of file Thread-affinity.cc.

◆ start()

bool Thread::start ( )

Starts a thread constructed with delayedStart=true.

This is deliberately distinct from waking a blocked thread: only its WaitQueue may perform that transition.

Definition at line 751 of file Thread.cc.

References getUnwindState(), Scheduler::instance(), m_bStartRequested, m_Lock, m_Status, and TerminateThread.

Referenced by startDetached().

+ Here is the caller graph for this function:

◆ startDetached()

bool Thread::startDetached ( )

Publishes a delayed worker as detached while retaining its final-use claim. A terminal cancellation which already owns the thread is accepted as successful publication. Success may destroy this Thread before the call returns, so callers must not access it afterward.

Definition at line 769 of file Thread.cc.

References Process::beginThreadJoin(), closeExternalLeaseAdmissionAndDrain(), Process::endThreadJoin(), getUnwindState(), m_bDetached, m_bDetachedRetirementClaimed, m_bJoinClaimed, m_bProcessExitOwned, m_bReapable, m_JoinWaiters, Process::m_Lock, m_pParent, setUnwindState(), start(), and TerminateThread.

Referenced by PosixSubsystem::invoke().

+ Here is the caller graph for this function:

◆ state()

SchedulerState & Thread::state ( )

◆ stateCleanupCheckpoint()

size_t Thread::stateCleanupCheckpoint ( )
protected

Definition at line 3412 of file Thread.cc.

◆ takeClearChildTid()

uintptr_t Thread::takeClearChildTid ( )
inline

Claims and resets the clear-child-TID registration exactly once.

Definition at line 348 of file Thread.h.

◆ takeDeferredProcessExit()

Thread::DeferredProcessExit Thread::takeDeferredProcessExit ( )

Claims the status and cause attached to a deferred process exit.

Definition at line 3618 of file Thread.cc.

References m_DeferredProcessExitRequest.

Referenced by PerProcessorScheduler::commitUserReturnTerminalState(), HostedSyscallManager::syscall(), X64SyscallManager::syscall(), and threadExited().

+ Here is the caller graph for this function:

◆ takeDeferredSubsystemException()

bool Thread::takeDeferredSubsystemException ( size_t &  type,
uintptr_t &  faultAddress,
uintptr_t &  errorCode 
)

Claims a synchronous exception at an IRQ-enabled return boundary.

Definition at line 3643 of file Thread.cc.

References m_DeferredSubsystemExceptionState.

Referenced by PerProcessorScheduler::serviceDeferredSubsystemException().

+ Here is the caller graph for this function:

◆ takeRobustList()

uintptr_t Thread::takeRobustList ( size_t &  ownerId)

Definition at line 672 of file Thread.cc.

◆ threadExited()

void Thread::threadExited ( )
static

Sets the exit code of the Thread and sets the state to Zombie, if it is being waited on; if it is not being waited on the Thread is destroyed.

Note
This is meant to be called only by the thread trampoline - this is the only reason it is public. It should NOT be called by anyone else!

Definition at line 1030 of file Thread.cc.

References Exit, Subsystem::exit(), getParent(), getStateLevel(), getUnwindState(), ProcessorBase::information(), and takeDeferredProcessExit().

◆ trackTime()

void Thread::trackTime ( CpuTimeMode  mode)

Publishes elapsed time from this Thread into its Process aggregate.

Definition at line 392 of file Thread.cc.

References ThreadTimeAccounting::elapsedAtInterruptDisabled(), m_TimeAccounting, and publishTimeAccounting().

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

+ Here is the caller graph for this function:

◆ transferProcessSignalsTo()

bool Thread::transferProcessSignalsTo ( Thread &  target)

Moves queued process signals, retaining rejected deliveries on this thread. The caller pins both threads and serialises process signal publication.

Definition at line 2238 of file Thread.cc.

References List< T, nodePoolSize >::begin(), Event::completeDelivery(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), m_EventQueue, m_Lock, List< T, nodePoolSize >::pushFront(), and sendEvent().

Referenced by PosixSubsystem::prepareThreadsForExec(), and PosixSubsystem::preserveProcessSignalsForThreadExit().

+ Here is the caller graph for this function:

◆ transitionTime()

void Thread::transitionTime ( CpuTimeMode  from,
CpuTimeMode  to,
bool  interruptsAlreadyDisabled = false 
)

◆ transitionTimeAtInterruptReturn()

ALWAYS_INLINE void Thread::transitionTimeAtInterruptReturn ( CpuTimeMode  from,
CpuTimeMode  to 
)
inline

Accounts a transition while the architecture already has IRQ delivery physically masked.

Definition at line 373 of file Thread.h.

Referenced by InterruptTimeAccounting::finishUserReturn(), and X64SyscallManager::syscall().

+ Here is the caller graph for this function:

◆ tryRequireSignalFrames()

bool Thread::tryRequireSignalFrames ( )

Definition at line 49 of file Thread-user-return.cc.

◆ unexpectedExit()

void Thread::unexpectedExit ( )

An unexpected exit has occurred, perform cleanup

Definition at line 2642 of file Thread.cc.

Referenced by PosixSubsystem::exit().

+ Here is the caller graph for this function:

◆ unlinkWaitsForStackDiscard()

void Thread::unlinkWaitsForStackDiscard ( )
private

Unpublishes every waiter before exceptional stack cleanup can run.

Definition at line 640 of file Thread.cc.

References Thread::StateLevel::m_Waiter.

Referenced by PerProcessorScheduler::abandonCurrentThreadStack(), and shutdown().

+ Here is the caller graph for this function:

◆ unpublishDeferredScope()

ALWAYS_INLINE void Thread::unpublishDeferredScope ( DeferredScopeRecord &  record,
bool  deferrals 
)
inlineprivate

Definition at line 3309 of file Thread.cc.

◆ unregisterDeferredScope()

void Thread::unregisterDeferredScope ( DeferredScopeRecord &  record)
protected

Definition at line 3336 of file Thread.cc.

◆ unregisterTerminationDeferral()

void Thread::unregisterTerminationDeferral ( DeferredScopeRecord &  record)
protected

Definition at line 3344 of file Thread.cc.

◆ userReturnWorkPending()

bool Thread::userReturnWorkPending ( ) const
inline

Definition at line 139 of file Thread.h.

◆ waitAffinity()

AffinityResult Thread::waitAffinity ( uint64_t  generation)

Wait without retaining caller locks; the caller must retain this Thread.

Definition at line 136 of file Thread-affinity.cc.

References m_Lock.

◆ waitForEvent()

void Thread::waitForEvent ( WaitQueue::StackDiscardCleanup  onStackDiscard = nullptr,
void *  stackDiscardContext = nullptr 
)

Blocks until an event is delivered or terminal state is pending.

Definition at line 1202 of file Thread.cc.

◆ waitForEventInternal()

bool Thread::waitForEventInternal ( bool  stopOnSignalInterruption,
WaitQueue::StackDiscardCleanup  onStackDiscard,
void *  stackDiscardContext 
)
private

Definition at line 1212 of file Thread.cc.

◆ waitForEventOrSignalInterruption()

bool Thread::waitForEventOrSignalInterruption ( WaitQueue::StackDiscardCleanup  onStackDiscard = nullptr,
void *  stackDiscardContext = nullptr 
)

Blocks for one event unless an armed temporary signal wait was already interrupted. Returns whether a caught signal interrupted that wait.

Definition at line 1207 of file Thread.cc.

◆ wakeForDeliverableEvents()

void Thread::wakeForDeliverableEvents ( )
private

Rechecks queued events after the parent process becomes runnable.

Definition at line 2601 of file Thread.cc.

References interruptWaitUnlocked(), m_bShutdown, m_EventWaiters, m_Lock, m_Status, and PerProcessorScheduler::publishReadyFromWait().

Referenced by Process::resume().

+ Here is the caller graph for this function:

◆ wasInterrupted()

bool Thread::wasInterrupted ( )
inline

Returns whether the current context's wait was interrupted.

Definition at line 493 of file Thread.h.

Friends And Related Symbol Documentation

◆ ExecutionContextGuard

friend class ExecutionContextGuard
friend

Definition at line 90 of file Thread.h.

◆ HostedInterruptManager

friend class HostedInterruptManager
friend

Definition at line 88 of file Thread.h.

◆ IrqHandlerRegistry

friend class IrqHandlerRegistry
friend

Definition at line 86 of file Thread.h.

◆ PageFaultHandler

friend class PageFaultHandler
friend

Definition at line 80 of file Thread.h.

◆ PerProcessorScheduler

friend class PerProcessorScheduler
friend

Definition at line 78 of file Thread.h.

◆ Process

friend class Process
friend

Definition at line 81 of file Thread.h.

◆ RequestQueueCallbackScope

friend class RequestQueueCallbackScope
friend

Definition at line 91 of file Thread.h.

◆ RoundRobin

friend class RoundRobin
friend

Definition at line 89 of file Thread.h.

◆ Scheduler

friend class Scheduler
friend

Definition at line 79 of file Thread.h.

◆ SchedulerTimerDispatchCleanup

friend class SchedulerTimerDispatchCleanup
friend

Definition at line 92 of file Thread.h.

◆ SyscallManager

friend class SyscallManager
friend

Definition at line 85 of file Thread.h.

◆ TerminationDeferral

friend class TerminationDeferral
friend

Definition at line 84 of file Thread.h.

◆ TimerHandlerRegistry

friend class TimerHandlerRegistry
friend

Definition at line 87 of file Thread.h.

◆ Uninterruptible

friend class Uninterruptible
friend

Definition at line 83 of file Thread.h.

◆ WaitQueue

friend class WaitQueue
friend

Definition at line 82 of file Thread.h.

Member Data Documentation

◆ m_ActiveSyscalls

size_t Thread::m_ActiveSyscalls[serviceEnd] = {}
private

Owner-written admission, scanned under scheduler membership protection.

Definition at line 1307 of file Thread.h.

Referenced by ~Thread().

◆ m_AffinityCompleted

uint64_t Thread::m_AffinityCompleted = 0
private

Definition at line 1227 of file Thread.h.

◆ m_AffinityGatePending

bool Thread::m_AffinityGatePending = false
private

Definition at line 1229 of file Thread.h.

◆ m_AffinityGeneration

uint64_t Thread::m_AffinityGeneration = 0
private

Definition at line 1226 of file Thread.h.

◆ m_AffinityNext

Thread* Thread::m_AffinityNext = nullptr
private

Definition at line 1235 of file Thread.h.

◆ m_AffinityPending

bool Thread::m_AffinityPending = false
private

Definition at line 1228 of file Thread.h.

◆ m_AffinityReturnPending

size_t Thread::m_AffinityReturnPending = 0
private

Definition at line 1231 of file Thread.h.

◆ m_AffinityWaiters

WaitQueue Thread::m_AffinityWaiters
private

Definition at line 1225 of file Thread.h.

◆ m_AffinityWorkQueued

bool Thread::m_AffinityWorkQueued = false
private

Definition at line 1230 of file Thread.h.

◆ m_AlternateSignalStack

AlternateSignalStack Thread::m_AlternateSignalStack
private

Alternate signal stack configuration is per-thread.

Definition at line 1302 of file Thread.h.

Referenced by PerProcessorScheduler::checkEventState(), popState(), prepareSignalStateForExec(), and Thread().

◆ m_bDetached

bool Thread::m_bDetached = false
private

Whether this thread has been detached or not.

Definition at line 1355 of file Thread.h.

Referenced by detach(), endExternalLease(), joinInternal(), markReapable(), and startDetached().

◆ m_bDetachedRetirementClaimed

bool Thread::m_bDetachedRetirementClaimed = false
private

Exactly one path owns detached Thread destruction.

Definition at line 1361 of file Thread.h.

Referenced by detach(), endExternalLease(), markReapable(), and startDetached().

◆ m_bExitStarted

bool Thread::m_bExitStarted = false
private

Thread shutdown has started, but its stack may still be in use.

Definition at line 1367 of file Thread.h.

Referenced by Process::beginTermination(), Process::prepareThreadExit(), and shutdown().

◆ m_bExternalLeaseAdmissionClosed

bool Thread::m_bExternalLeaseAdmissionClosed = false
private

Whether no new external Thread leases may be acquired.

Definition at line 1277 of file Thread.h.

Referenced by beginExternalLease(), closeExternalLeaseAdmission(), closeExternalLeaseAdmissionAndDrain(), endExternalLease(), markReapable(), and ~Thread().

◆ m_bExternalLeaseReleaseInProgress

bool Thread::m_bExternalLeaseReleaseInProgress = false
private

The final releaser is still deciding detached retirement.

A zero lease count alone is not enough for scheduler-side deletion: the releasing call still has to inspect this Thread after decrementing.

Definition at line 1285 of file Thread.h.

Referenced by closeExternalLeaseAdmissionAndDrain(), endExternalLease(), markReapable(), and ~Thread().

◆ m_bJoinClaimed

bool Thread::m_bJoinClaimed = false
private

Whether join() has been claimed by another thread.

Definition at line 1358 of file Thread.h.

Referenced by detach(), discardJoin(), joinInternal(), startDetached(), and Process::~Process().

◆ m_bProcessExitOwned

bool Thread::m_bProcessExitOwned = false
private

Process destruction owns this Thread object once it is off-stack.

Definition at line 1373 of file Thread.h.

Referenced by Process::addThread(), Process::beginTermination(), detach(), endExternalLease(), joinInternal(), markReapable(), and startDetached().

◆ m_bProcessExitParticipant

bool Thread::m_bProcessExitParticipant = false
private

This thread is included in its Process' exit rendezvous.

Definition at line 1376 of file Thread.h.

Referenced by Process::addThread(), Process::beginTermination(), and Process::terminatingThreadReapable().

◆ m_bReadyQueued

bool Thread::m_bReadyQueued = false
private

Definition at line 1246 of file Thread.h.

◆ m_bReapable

bool Thread::m_bReapable = false
private

◆ m_bShutdown

bool Thread::m_bShutdown = false
private

◆ m_bStartRequested

bool Thread::m_bStartRequested = false
private

The add worker may publish a delayed thread after this request.

Definition at line 1352 of file Thread.h.

Referenced by start().

◆ m_bSubsystemExitNotified

bool Thread::m_bSubsystemExitNotified = false
private

Process teardown can notify before shutdown retires the final thread.

Definition at line 1342 of file Thread.h.

Referenced by notifySubsystemExit().

◆ m_bThreadExitRequested

bool Thread::m_bThreadExitRequested = false
private

One-way syscall exit intent, protected by the parent Process lock.

Definition at line 1364 of file Thread.h.

Referenced by Process::prepareThreadExit().

◆ m_bTlsBaseOverride

bool Thread::m_bTlsBaseOverride = false
private

Whether or not userspace has overridden its TLS base.

Definition at line 1336 of file Thread.h.

Referenced by getTlsBase(), resetTlsBase(), setTlsBase(), Thread(), and ~Thread().

◆ m_ClearChildTid

uintptr_t Thread::m_ClearChildTid = 0
private

Userspace TID word cleared by the subsystem during exit publication.

Definition at line 1345 of file Thread.h.

Referenced by setClearChildTid().

◆ m_CurrentTimeAccountingMode

size_t Thread::m_CurrentTimeAccountingMode = static_cast<size_t>(CpuTimeMode::Kernel)
private

Mode owning time since the most recent accounting baseline.

Definition at line 1199 of file Thread.h.

Referenced by currentTimeAccountingMode(), recordTime(), and transitionTime().

◆ m_DebugState

DebugState Thread::m_DebugState = None
private

Debug state - a higher level state information for display in the debugger for debugging races and deadlocks.

Definition at line 1321 of file Thread.h.

◆ m_DebugStateAddress

uintptr_t Thread::m_DebugStateAddress = 0
private

Address to supplement the DebugState information

Definition at line 1216 of file Thread.h.

◆ m_DebugStateGeneration

size_t Thread::m_DebugStateGeneration = 0
private

Even while the single-writer detached debug state is stable.

Definition at line 1219 of file Thread.h.

◆ m_DeferredProcessExitRequest

uint64_t Thread::m_DeferredProcessExitRequest = 0
private

Status preserved while Exit crosses nested/event/IRQ boundaries.

Definition at line 1326 of file Thread.h.

Referenced by deferProcessExit(), deferSignalExit(), and takeDeferredProcessExit().

◆ m_DeferredReapNode

DeferredThreadReapNode Thread::m_DeferredReapNode
private

Allocation-free publication storage for scheduler-side retirement.

Definition at line 1189 of file Thread.h.

◆ m_DeferredSubsystemExceptionErrorCode

uintptr_t Thread::m_DeferredSubsystemExceptionErrorCode = 0
private

Definition at line 1333 of file Thread.h.

◆ m_DeferredSubsystemExceptionFaultAddress

uintptr_t Thread::m_DeferredSubsystemExceptionFaultAddress = 0
private

Definition at line 1332 of file Thread.h.

◆ m_DeferredSubsystemExceptionState

size_t Thread::m_DeferredSubsystemExceptionState = 0
private

Empty, publishing, or pending state for the preallocated exception.

Definition at line 1330 of file Thread.h.

Referenced by deferSubsystemException(), and takeDeferredSubsystemException().

◆ m_DeferredSubsystemExceptionType

size_t Thread::m_DeferredSubsystemExceptionType = 0
private

Definition at line 1331 of file Thread.h.

◆ m_EventDeferralDepth

size_t Thread::m_EventDeferralDepth = 0
private

Nesting depth for deferred event delivery.

Definition at line 1379 of file Thread.h.

Referenced by PerProcessorScheduler::commitCurrentThreadExit(), eventsDeferred(), getNextEvent(), and ~Thread().

◆ m_EventQueue

List<Event*> Thread::m_EventQueue
private

◆ m_EventSenderDrainWaiters

WaitQueue Thread::m_EventSenderDrainWaiters
private

Drains sendEvent operations admitted before shutdown.

Definition at line 1291 of file Thread.h.

Referenced by replaceSignalEvent(), sendEvent(), and shutdown().

◆ m_EventSendersInFlight

size_t Thread::m_EventSendersInFlight = 0
private

sendEvent calls admitted before shutdown closed the event queue.

Definition at line 1297 of file Thread.h.

Referenced by replaceSignalEvent(), sendEvent(), and shutdown().

◆ m_EventWaiters

WaitQueue Thread::m_EventWaiters
private

◆ m_ExecutionPersonality

ExecutionPersonality Thread::m_ExecutionPersonality
private

Definition at line 1311 of file Thread.h.

◆ m_ExitCode

int Thread::m_ExitCode = 0
private

Our exit code.

Definition at line 1317 of file Thread.h.

◆ m_ExitToIdle

bool Thread::m_ExitToIdle = false
private

One-shot terminal handoff used by the orderly shutdown coordinator.

Definition at line 1314 of file Thread.h.

Referenced by PerProcessorScheduler::abandonCurrentThreadStack(), PerProcessorScheduler::commitCurrentThreadExit(), and PerProcessorScheduler::requestCurrentThreadExitToIdle().

◆ m_ExternalLeaseLock

Spinlock Thread::m_ExternalLeaseLock
private

Short predicate lock, never held while waking lease drainers.

Definition at line 1268 of file Thread.h.

Referenced by beginExternalLease(), closeExternalLeaseAdmission(), closeExternalLeaseAdmissionAndDrain(), endExternalLease(), markReapable(), and ~Thread().

◆ m_ExternalLeaseWaiters

WaitQueue Thread::m_ExternalLeaseWaiters
private

Lifetime barrier for Process::ThreadLease users.

Definition at line 1271 of file Thread.h.

Referenced by closeExternalLeaseAdmissionAndDrain(), and endExternalLease().

◆ m_FilesystemGid

uint32_t Thread::m_FilesystemGid = 0
private

Definition at line 1182 of file Thread.h.

◆ m_FilesystemIdsValid

bool Thread::m_FilesystemIdsValid = false
private

Definition at line 1183 of file Thread.h.

◆ m_FilesystemOverride

const FilesystemCredentials* Thread::m_FilesystemOverride = nullptr
private

Definition at line 1184 of file Thread.h.

◆ m_FilesystemUid

uint32_t Thread::m_FilesystemUid = 0
private

Definition at line 1182 of file Thread.h.

◆ m_HasSchedulerContext

bool Thread::m_HasSchedulerContext = false
private

Definition at line 1236 of file Thread.h.

◆ m_HasSecurityState

bool Thread::m_HasSecurityState = false
private

Definition at line 1186 of file Thread.h.

◆ m_Id

size_t Thread::m_Id = 0
private

Our thread ID.

Definition at line 1211 of file Thread.h.

Referenced by getTlsBase(), Thread(), Thread(), and Thread().

◆ m_JoinWaiters

WaitQueue Thread::m_JoinWaiters
private

◆ m_KernelTime

Time::Timestamp Thread::m_KernelTime = 0
private

Definition at line 1196 of file Thread.h.

◆ m_Lock

Spinlock Thread::m_Lock
private

◆ m_Name

String Thread::m_Name
private

An optional name for the thread for debugging.

Definition at line 1174 of file Thread.h.

◆ m_nExternalLeases

size_t Thread::m_nExternalLeases = 0
private

External leases admitted before retirement closed the target.

Definition at line 1274 of file Thread.h.

Referenced by beginExternalLease(), closeExternalLeaseAdmissionAndDrain(), endExternalLease(), markReapable(), and ~Thread().

◆ m_NextStateCleanupSequence

size_t Thread::m_NextStateCleanupSequence = 0
private

Definition at line 1391 of file Thread.h.

◆ m_nStateLevel

size_t Thread::m_nStateLevel = 0
private

◆ m_OriginalSyscallState

const SyscallState* Thread::m_OriginalSyscallState = nullptr
private

Definition at line 1304 of file Thread.h.

◆ m_pAllocatedStack

void* Thread::m_pAllocatedStack = nullptr
private

The stack that we allocated from the VMM. This may or may not also be the kernel stack - depends on whether we are a user or kernel mode thread. This is used solely for housekeeping/cleaning up purposes.

Definition at line 1208 of file Thread.h.

Referenced by Thread(), and Thread().

◆ m_pDeferredScopes

DeferredScopeRecord* Thread::m_pDeferredScopes[MAX_NESTED_EVENTS] = {}
private

Per-state LIFO of stack records which teardown must retire explicitly.

Definition at line 1390 of file Thread.h.

Referenced by cleanStateLevel(), PerProcessorScheduler::commitCurrentThreadExit(), popState(), pushState(), and ~Thread().

◆ m_Placement

ThreadPlacement Thread::m_Placement
private

Definition at line 1223 of file Thread.h.

◆ m_pParent

Process* Thread::m_pParent = nullptr
private

◆ m_pReadyNext

Thread* Thread::m_pReadyNext = nullptr
private

Definition at line 1244 of file Thread.h.

◆ m_pReadyPrevious

Thread* Thread::m_pReadyPrevious = nullptr
private

Intrusive ready-queue state; scheduler publication must not allocate.

Definition at line 1243 of file Thread.h.

◆ m_Priority

size_t Thread::m_Priority = DEFAULT_PRIORITY
private

Thread priority: 0..MAX_PRIORITIES-1, 0 being highest.

Definition at line 1240 of file Thread.h.

◆ m_ProcId

size_t Thread::m_ProcId = 0
private

Definition at line 1259 of file Thread.h.

◆ m_pScheduler

class PerProcessorScheduler* Thread::m_pScheduler = nullptr
private

Definition at line 1221 of file Thread.h.

◆ m_pTlsBase

void* Thread::m_pTlsBase = nullptr
private

Memory mapping for the TLS base of this thread (userspace-only)

Definition at line 1249 of file Thread.h.

Referenced by getTlsBase(), resetTlsBase(), setTlsBase(), Thread(), and ~Thread().

◆ m_ReadyPublicationPending

bool Thread::m_ReadyPublicationPending = false
private

Definition at line 1237 of file Thread.h.

◆ m_ReadyQueuePriority

size_t Thread::m_ReadyQueuePriority = MAX_PRIORITIES
private

Definition at line 1245 of file Thread.h.

◆ m_RequestedAffinity

CpuAffinityMask Thread::m_RequestedAffinity
private

Definition at line 1224 of file Thread.h.

◆ m_RobustList

uintptr_t Thread::m_RobustList = 0
private

The Linux robust-list head is registered independently by each thread.

Definition at line 1348 of file Thread.h.

◆ m_RobustListOwnerId

size_t Thread::m_RobustListOwnerId = 0
private

Definition at line 1349 of file Thread.h.

◆ m_SecurityState

SecurityStateRef Thread::m_SecurityState
private

Definition at line 1185 of file Thread.h.

◆ m_SignalFramesRequired

bool Thread::m_SignalFramesRequired = false
private

Definition at line 1232 of file Thread.h.

◆ m_StateLevels

StateLevel Thread::m_StateLevels[MAX_NESTED_EVENTS]
private

Definition at line 1299 of file Thread.h.

◆ m_Status

volatile Status Thread::m_Status = Ready
private

◆ m_SynchronousSignalMask

uint64_t Thread::m_SynchronousSignalMask = 0
private

Definition at line 1327 of file Thread.h.

◆ m_SyscallDispatchContext

void* Thread::m_SyscallDispatchContext = nullptr
private

Definition at line 1305 of file Thread.h.

◆ m_TaskId

size_t Thread::m_TaskId = 0
private

Definition at line 1212 of file Thread.h.

◆ m_TerminationDeferralDepth

size_t Thread::m_TerminationDeferralDepth = 0
private

Nesting depth for scopes which must run cleanup before teardown.

Definition at line 1387 of file Thread.h.

Referenced by PerProcessorScheduler::commitCurrentThreadExit(), and ~Thread().

◆ m_TimeAccounting

ThreadTimeAccounting Thread::m_TimeAccounting
private

Per-thread baselines avoid cross-CPU corruption within one Process.

Definition at line 1192 of file Thread.h.

Referenced by recordTime(), trackTime(), and transitionTime().

◆ m_UnwindState

UnwindType Thread::m_UnwindState = Continue
private

Definition at line 1323 of file Thread.h.

◆ m_UserGsBase

uintptr_t Thread::m_UserGsBase = 0
private

Definition at line 1251 of file Thread.h.

◆ m_UserReturnSignalParked

bool Thread::m_UserReturnSignalParked = false
private

Definition at line 1233 of file Thread.h.

◆ m_UserReturnWorkPending

size_t Thread::m_UserReturnWorkPending = 0
private

Definition at line 1234 of file Thread.h.

◆ m_UserspacePid

SharedPointer<UserspacePid> Thread::m_UserspacePid
private

Definition at line 1213 of file Thread.h.

◆ m_UserTime

Time::Timestamp Thread::m_UserTime = 0
private

CPU time charged to this Thread, split by user and kernel mode.

Definition at line 1195 of file Thread.h.

Referenced by publishTimeAccounting().


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