|
The Pedigree Project 0.1
|
#include <PosixSubsystem.h>
Inheritance diagram for PosixSubsystem:
Collaboration diagram for PosixSubsystem:Classes | |
| struct | ExecutableImage |
| struct | FdEntry |
| class | PosixSyncObject |
| class | PosixThread |
| struct | PosixThreadKey |
| struct | SignalDisposition |
| struct | SignalHandler |
| struct | UserImageToken |
Public Types | |
| enum class | DescriptorDuplicationResult { Success , BadSource , TargetBusy } |
| enum | Abi { PosixAbi = 0 , LinuxAbi = 1 } |
| enum | UserStringResult { UserStringSuccess , UserStringBadAddress , UserStringTooLong } |
| enum class | SignalDeliveryResult { Unavailable , Ignored , Rejected , Queued , Full } |
Public Types inherited from Subsystem | |
| enum class | UserReturnResult { Continue , Terminal } |
| enum class | UserReturnEventResult { Deliver , Consumed , Terminal } |
| enum | SubsystemType { Posix = 0 , Native = 1 , None = 255 } |
| enum | KillReason { Interrupted = 0 , Terminated = 1 , Unknown = 255 } |
| enum class | ExitCause { Normal , Signal } |
| enum | ExceptionType { InvalidOpcode = 0 , PageFault = 1 , GeneralProtectionFault = 2 , DivideByZero = 3 , FpuError = 4 , SpecialFpuError = 5 , TerminalInput = 6 , TerminalOutput = 7 , Continue = 8 , Stop = 9 , Interrupt = 10 , Quit = 11 , Child = 12 , Pipe = 13 , FileMappingFault = 14 , Other = 255 } |
Public Member Functions | |
| PosixSubsystem () | |
| PosixSubsystem (PosixSubsystem &s, bool clearSignalHandlers=false) | |
| PosixSubsystem (SubsystemType type) | |
| SharedPointer< PosixNamespaceContext > | namespaceContext () const |
| bool | executablePath (String &result) const |
| bool | executablePath (FilesystemPathRef &result) const |
| bool | commandLine (Vector< String > &result) const |
| PosixTraceContext & | traceContext () |
| bool | tracePolicyAllowed () const |
| UserReturnResult | userReturnCheckpoint (Thread &, UserReturnFrame &) override |
| UserReturnEventResult | userReturnEvent (Thread &, Event &, UserReturnFrame &) override |
| bool | traceException (Thread &, int &signal, InterruptState &, ExceptionType, uintptr_t, uintptr_t) |
| TraceStatus | prepareTraceSignal (Thread &, int signal, int32_t pid, uint32_t uid, bool inheritReservation, UniquePointer< SignalEvent > &) |
| bool | publishTraceSignal (Thread &, UniquePointer< SignalEvent > &, SignalEvent *source) |
| virtual | ~PosixSubsystem () |
| virtual void | acquire () |
| Acquire full mutual exclusion for all Subsystem resources. | |
| virtual void | release () |
| virtual bool | kill (KillReason killReason, Thread *pThread) |
| virtual void | threadException (Thread *pThread, ExceptionType eType, InterruptState *pState=nullptr, uintptr_t faultAddress=0, uintptr_t errorCode=0) |
| bool | resolveUserPageFault (Thread &thread, InterruptState &state, uintptr_t faultAddress, uintptr_t errorCode) override |
| virtual void | sendSignal (Thread *pThread, int signal, bool yield=true, bool processDirected=false) |
| void | setSignalHandler (size_t sig, SignalHandler *handler) |
| bool | admitLegacyUserSignals () |
| bool | affinityPolicyAllowed () const |
| void | recordAffinityPolicyUse () |
| void | resetSignalHandlersForExec (Thread *thread, SignalHandler *const handlers[SignalDispositionCount]) |
| bool | getSignalDisposition (size_t sig, SignalDisposition &disposition, bool beginDelivery=false) |
| SignalDeliveryResult | queueSignalDelivery (Thread *target, size_t sig, uint32_t *flags=nullptr, int32_t signalCode=0, bool processDirected=false, uint64_t signalValue=0, const SharedPointer< SignalEventState > &state=SharedPointer< SignalEventState >()) |
| void | setProcess (Process *process) override |
| bool | snapshotUserImage (UserImageToken &token) const |
| bool | matchesUserImage (const UserImageToken &token) const |
| void | invalidateUserImage () |
| bool | publishUserImage (VirtualAddressSpace &space) |
| SharedPointer< PendingSignalContext > | pendingSignalContext () |
| Mutex & | pendingSignalLock () |
| ConditionVariable & | pendingSignalChanged () |
| void | retireDescriptor (FileDescriptor *descriptor) |
| AdvisoryOwner & | advisoryOwner () |
| PosixMemoryLockAccount & | memoryLockAccount () |
| SignalHandler * | getSignalHandler (size_t sig) |
| void | exit (int code, ExitCause cause=ExitCause::Normal) NORETURN |
| bool | copyDescriptors (PosixSubsystem *pSubsystem) |
| size_t | getFd (size_t minimum=0) |
| void | allocateFd (size_t fdNum) |
| void | freeFd (size_t fdNum) |
| void | freeMultipleFds (bool bOnlyCloExec=false, size_t iFirst=0, size_t iLast=-1) |
| bool | acquireFileDescriptor (size_t fd, DescriptorLease &descriptor) |
| bool | acquireNextFileDescriptor (size_t minimum, size_t &fd, DescriptorLease &descriptor) |
| bool | descriptorMatchesOpenDescription (size_t fd, const FileDescriptor::OpenFileDescriptionLease &expected) |
| bool | closeFileDescriptor (size_t fd, const DescriptorLease &descriptor) |
| void | addFileDescriptor (size_t fd, FileDescriptor *pFd) |
| DescriptorDuplicationResult | duplicateFileDescriptor (size_t source, size_t target, bool closeOnExec) |
| size_t | installFileDescriptor (FileDescriptor *descriptor, DescriptorLease &lease, size_t minimum=0) |
| PosixSyncObject * | getSyncObject (size_t n) |
| void | insertSyncObject (size_t n, PosixSyncObject *sem) |
| void | removeSyncObject (size_t n) |
| PosixThread * | getThread (size_t n) |
| void | insertThread (size_t n, PosixThread *thread) |
| void | removeThread (size_t n) |
| Semaphore * | getThreadWaiter (void *n) |
| void * | insertThreadWaiter (Semaphore *waiter) |
| void | removeThreadWaiter (void *n) |
| bool | checkAccess (const DescriptorLease &pFileDescriptor, bool bRead, bool bWrite, bool bExecute) const |
| uint64_t | filesystemAccess (const FilesystemPathRef *ancestry, size_t count) const override |
| bool | filesystemConstrained () const override |
| bool | filesystemReparent (const FilesystemPathRef *source, size_t sourceCount, const FilesystemPathRef *destination, size_t destinationCount) const override |
| virtual bool | invoke (const char *name, Vector< String > &argv, Vector< String > &env) |
| virtual bool | invoke (const char *name, Vector< String > &argv, Vector< String > &env, SyscallState &state) |
| virtual bool | invoke (File *originalFile, const String &originalName, Vector< String > &argv, Vector< String > &env) |
| virtual bool | invoke (File *originalFile, const String &originalName, Vector< String > &argv, Vector< String > &env, SyscallState &state) |
| bool | invoke (File *originalFile, const String &originalName, Vector< String > &argv, Vector< String > &env, SyscallState &state, bool descriptorPathInaccessible) |
| bool | invoke (const FilesystemPathRef &originalPath, const String &originalName, Vector< String > &argv, Vector< String > &env, SyscallState &state, bool descriptorPathInaccessible=false) |
| File * | findFileRetained (const String &path, ResolvedPath &result, const FilesystemPathRef &workingDir=FilesystemPathRef(), bool followFinal=false) |
| File * | followFile (ResolvedPath &selected) |
| Abi | getAbi () const |
| void | setAbi (Abi which) |
Public Member Functions inherited from Subsystem | |
| Subsystem () | |
| Subsystem (const Subsystem &s) | |
| Subsystem (SubsystemType type) | |
| virtual | ~Subsystem () |
| SubsystemType | getType () |
Static Public Member Functions | |
| static bool | checkAddress (uintptr_t addr, size_t extent, size_t flags) |
| static bool | checkedUserBufferSize (size_t count, size_t elementSize, size_t &extent) |
| static bool | checkUserAddressRange (uintptr_t addr, size_t count, size_t elementSize, size_t *extent=nullptr) |
| static bool | checkUserBuffer (uintptr_t addr, size_t count, size_t elementSize, size_t flags, size_t *extent=nullptr) |
| static bool | copyFromUser (void *destination, const void *source, size_t count, size_t elementSize=1) |
| static bool | copyToUser (void *destination, const void *source, size_t count, size_t elementSize=1) |
| static size_t | readCachedFile (File &file, uint64_t offset, void *destination, size_t count) |
| static UserStringResult | copyUserString (const char *userString, String ©, size_t maxLength) |
Static Public Attributes | |
| static const size_t | SafeRegion = 0x0 |
| static const size_t | SafeRead = 0x1 |
| static const size_t | SafeWrite = 0x2 |
| static const size_t | SafeExecute = 0x4 |
| static constexpr size_t | LinuxPrivateSignalFirst = 32 |
| static constexpr size_t | MaximumSupportedSignal = 64 |
| static constexpr size_t | SignalDispositionCount = MaximumSupportedSignal + 1 |
| static constexpr size_t | MaximumExecArgumentBytes = 131072 |
Private Types | |
| enum class | CallbackSchedulingDomain { Unrestricted , LegacySignals , Affinity } |
Private Member Functions | |
| void | acquireFdLock () |
| void | publishFdEntry (size_t fd) |
| void | publishFdEntries () |
| virtual void | prepareThreadsForExec (Thread *owner) |
| virtual void | preserveProcessSignalsForThreadExit (Thread *thread) |
| virtual void | threadExiting (Thread *pThread) |
| void | clearChildTid (Thread *thread) |
| virtual void | threadRemoved (Thread *pThread) |
| bool | prepareExecutable (File *pFile, ExecutableImage &image, bool isInterpreter) |
| bool | loadElf (const ExecutableImage &image, uintptr_t &loadBias) |
| bool | invoke (const char *name, Vector< String > &argv, Vector< String > &env, SyscallState *state) |
| bool | invoke (File *originalFile, const String &originalName, Vector< String > &argv, Vector< String > &env, SyscallState *state, bool descriptorPathInaccessible=false, const FilesystemPathRef &originalPath=FilesystemPathRef()) |
| bool | parseShebang (File *pFile, String &interpreter, String &optionalArgument, bool &hasOptionalArgument) |
Static Private Attributes | |
| static constexpr size_t | FdBuckets = 16 |
Additional Inherited Members | |
Protected Attributes inherited from Subsystem | |
| SubsystemType | m_Type |
| Process * | m_pProcess |
Defines the compatibility layer for the POSIX Subsystem
Definition at line 178 of file PosixSubsystem.h.
| enum PosixSubsystem::Abi |
ABI mode.
Definition at line 197 of file PosixSubsystem.h.
|
strongprivate |
Definition at line 802 of file PosixSubsystem.h.
|
strong |
Definition at line 180 of file PosixSubsystem.h.
|
strong |
Definition at line 425 of file PosixSubsystem.h.
| enum PosixSubsystem::UserStringResult |
Definition at line 339 of file PosixSubsystem.h.
|
inline |
Default constructor
Definition at line 203 of file PosixSubsystem.h.
| PosixSubsystem::PosixSubsystem | ( | PosixSubsystem & | s, |
| bool | clearSignalHandlers = false |
||
| ) |
Copy constructor
Definition at line 256 of file PosixSubsystem.cc.
References UnlikelyLock::acquire(), Tree< K, E >::begin(), Tree< K, E >::end(), UnlikelyLock::enter(), Tree< K, E >::insert(), UnlikelyLock::leave(), m_SignalHandlersLock, m_ThreadWaiters, PosixSubsystem::SignalHandler::pEvent, UnlikelyLock::release(), PosixSubsystem::SignalHandler::sig, and PosixSubsystem::SignalHandler::type.
|
inline |
Parameterised constructor
Definition at line 230 of file PosixSubsystem.h.
|
virtual |
Default destructor
Definition at line 400 of file PosixSubsystem.cc.
References acquire(), Spinlock::acquire(), MemoryMapManager::acquireLock(), Tree< K, E >::begin(), Tree< K, E >::clear(), Tree< K, E >::end(), freeMultipleFds(), Process::getAddressSpace(), Process::getNumThreads(), ProcessorBase::information(), MemoryMapManager::instance(), m_FreeCount, m_SyncObjects, PosixSubsystem::PosixThread::m_ThreadData, m_Threads, m_ThreadWaiters, m_TraceContext, release(), Spinlock::release(), MemoryMapManager::releaseLock(), Process::releaseVforkAddressSpace(), ProcessorBase::switchAddressSpace(), and MemoryMapManager::unmapAllUnlocked().
|
virtual |
Acquire full mutual exclusion for all Subsystem resources.
It is sometimes necessary to perform an operation that would require the entire Subsystem to be owned by a specific thread. For example, Subsystem termination often requires all other threads to exit the Subsystem's critical sections before it can complete.
This call allows that thread to acquire that mutual exclusion.
Reimplemented from Subsystem.
Definition at line 540 of file PosixSubsystem.cc.
References UnlikelyLock::acquire(), Spinlock::acquire(), ProcessorBase::information(), m_bAcquired, m_Lock, m_pAcquiredThread, m_SignalHandlersLock, and Spinlock::release().
Referenced by ~PosixSubsystem().
Here is the caller graph for this function:
|
private |
Definition at line 534 of file PosixSubsystem.cc.
| bool PosixSubsystem::acquireFileDescriptor | ( | size_t | fd, |
| DescriptorLease & | descriptor | ||
| ) |
Pins the descriptor currently published at fd.
Callers cannot obtain a borrowed table pointer: a successful lookup retains the descriptor until the returned handle leaves scope, even if another thread closes or replaces the descriptor in the meantime.
Definition at line 1752 of file PosixSubsystem.cc.
| bool PosixSubsystem::acquireNextFileDescriptor | ( | size_t | minimum, |
| size_t & | fd, | ||
| DescriptorLease & | descriptor | ||
| ) |
Retain the lowest published descriptor at or after minimum.
Definition at line 1833 of file PosixSubsystem.cc.
References Tree< K, E >::begin(), Tree< K, E >::end(), m_FdLock, m_FdMap, and Semaphore::release().
| void PosixSubsystem::addFileDescriptor | ( | size_t | fd, |
| FileDescriptor * | pFd | ||
| ) |
Inserts a file descriptor
Definition at line 1909 of file PosixSubsystem.cc.
References SharedPointer< T >::get(), Tree< K, E >::insert(), m_FdBitmap, m_FdLock, m_FdMap, m_NextFd, Semaphore::release(), SharedPointer< T >::reset(), ExtensibleBitmap::set(), and Tree< K, E >::take().
| bool PosixSubsystem::admitLegacyUserSignals | ( | ) |
Definition at line 1190 of file PosixSubsystem.cc.
|
inline |
Definition at line 481 of file PosixSubsystem.h.
|
inline |
Definition at line 433 of file PosixSubsystem.h.
| void PosixSubsystem::allocateFd | ( | size_t | fdNum | ) |
Sets the given file descriptor as "in use".
Definition at line 1588 of file PosixSubsystem.cc.
References m_FdBitmap, m_FdLock, m_NextFd, Semaphore::release(), and ExtensibleBitmap::set().
| bool PosixSubsystem::checkAccess | ( | const DescriptorLease & | pFileDescriptor, |
| bool | bRead, | ||
| bool | bWrite, | ||
| bool | bExecute | ||
| ) | const |
Definition at line 2129 of file PosixSubsystem.cc.
|
static |
Check whether a given region of memory is safe for the given operations.
This is important to do as we can get pointers from anywhere in the POSIX subsystem, and making sure they are sane and safe is crucial.
Definition at line 574 of file PosixSubsystem.cc.
References VirtualAddressSpace::CopyOnWrite, Dec, VirtualAddressSpace::Execute, VirtualAddressSpace::getMapping(), PhysicalMemoryManager::getPageSize(), Hex, ProcessorBase::information(), MemoryMapManager::instance(), VirtualAddressSpace::isMapped(), VirtualAddressSpace::KernelMode, VirtualAddressSpace::NoAccess, VirtualAddressSpace::Write, and VirtualAddressSpace::WriteProtected.
Referenced by checkUserBuffer().
Here is the caller graph for this function:
|
static |
Calculate the byte extent of a userspace array without wrapping.
Zero-sized arrays have a zero byte extent. This makes them safe to pass through the copy helpers without special-casing a null userspace pointer.
Definition at line 686 of file PosixSubsystem.cc.
Referenced by checkUserAddressRange(), checkUserBuffer(), copyFromUser(), and copyToUser().
Here is the caller graph for this function:
|
static |
Validate only the arithmetic and architectural userspace bounds of an array. Mapping residency and permissions are deliberately left to the eventual user copy.
Definition at line 700 of file PosixSubsystem.cc.
References checkedUserBufferSize().
|
static |
Validate a userspace array after checking its size calculation.
Definition at line 721 of file PosixSubsystem.cc.
References checkAddress(), and checkedUserBufferSize().
|
private |
Definition at line 2088 of file PosixSubsystem.cc.
| bool PosixSubsystem::closeFileDescriptor | ( | size_t | fd, |
| const DescriptorLease & | descriptor | ||
| ) |
Unpublishes fd only if it still names the generation in descriptor.
This is the close counterpart to acquireFileDescriptor: a concurrent close and reuse of the numeric fd must not allow an older close path to remove the replacement descriptor.
Definition at line 1871 of file PosixSubsystem.cc.
References ExtensibleBitmap::clear(), SharedPointer< T >::get(), Tree< K, E >::lookup(), m_FdBitmap, m_FdLock, m_FdMap, m_LastFd, Semaphore::release(), SharedPointer< T >::reset(), and Tree< K, E >::take().
Definition at line 361 of file PosixSubsystem.cc.
| bool PosixSubsystem::copyDescriptors | ( | PosixSubsystem * | pSubsystem | ) |
Copies file descriptors from another subsystem
Definition at line 1630 of file PosixSubsystem.cc.
References Tree< K, E >::begin(), Vector< T >::clear(), Tree< K, E >::end(), freeMultipleFds(), Tree< K, E >::insert(), m_FdBitmap, m_FdLock, m_FdMap, m_NextFd, Vector< T >::pushBack(), Semaphore::release(), ExtensibleBitmap::set(), and Tree< K, E >::take().
|
static |
Snapshot a userspace array into kernel-owned memory.
Mapping teardown is excluded for the duration of validation and copying, so callers can safely release all userspace references before blocking.
Definition at line 738 of file PosixSubsystem.cc.
References checkedUserBufferSize(), and MemoryMapManager::instance().
Referenced by FramebufferFile::command(), and RandomFile::command().
Here is the caller graph for this function:
|
static |
Copy a kernel-owned array to userspace under the mapping lifecycle gate.
Definition at line 760 of file PosixSubsystem.cc.
References checkedUserBufferSize(), and MemoryMapManager::instance().
Referenced by FramebufferFile::command(), and EvdevFile::command().
Here is the caller graph for this function:
|
static |
Copy a NUL-terminated user string without reading past a mapped range.
Definition at line 796 of file PosixSubsystem.cc.
References PhysicalMemoryManager::getPageSize(), and MemoryMapManager::instance().
| bool PosixSubsystem::descriptorMatchesOpenDescription | ( | size_t | fd, |
| const FileDescriptor::OpenFileDescriptionLease & | expected | ||
| ) |
Compare publication identity without taking an OFD lock or retaining references.
Definition at line 1856 of file PosixSubsystem.cc.
References SharedPointer< T >::get(), Tree< K, E >::lookupRef(), m_FdLock, m_FdMap, and Semaphore::release().
| PosixSubsystem::DescriptorDuplicationResult PosixSubsystem::duplicateFileDescriptor | ( | size_t | source, |
| size_t | target, | ||
| bool | closeOnExec | ||
| ) |
Atomically replaces target with a duplicate of source.
The source lookup, anonymous-target owner publication, and table swap share one descriptor-table critical section. A concurrent final close therefore cannot close socket/eventfd admission between lookup and duplication, and target is never observable as an unallocated descriptor.
Definition at line 1937 of file PosixSubsystem.cc.
References SharedPointer< T >::get(), Tree< K, E >::insert(), Tree< K, E >::lookup(), m_FdBitmap, m_FdLock, m_FdMap, m_NextFd, Semaphore::release(), SharedPointer< T >::reset(), ExtensibleBitmap::set(), Tree< K, E >::take(), and ExtensibleBitmap::test().
| bool PosixSubsystem::executablePath | ( | FilesystemPathRef & | result | ) | const |
Definition at line 355 of file PosixSubsystem.cc.
| bool PosixSubsystem::executablePath | ( | String & | result | ) | const |
Definition at line 344 of file PosixSubsystem.cc.
|
virtual |
Need to exit this process.
Implements Subsystem.
Definition at line 859 of file PosixSubsystem.cc.
References Process::beginTermination(), Thread::Continue, Dec, Process::finishTermination(), freeMultipleFds(), Process::getAddressSpace(), Process::getId(), ProcessorBase::getInterrupts(), Thread::getParent(), ProcessorBase::inDeviceHardIrq(), ProcessorBase::information(), MemoryMapManager::instance(), m_TraceContext, Thread::notifySubsystemExit(), Process::quiesceTermination(), Process::releaseVforkAddressSpace(), Process::setExitStatus(), Thread::setUnwindState(), Thread::unexpectedExit(), and MemoryMapManager::unmapAll().
|
overridevirtual |
Reimplemented from Subsystem.
Definition at line 138 of file landlock.cc.
|
overridevirtual |
Reimplemented from Subsystem.
Definition at line 134 of file landlock.cc.
|
overridevirtual |
Reimplemented from Subsystem.
Definition at line 156 of file landlock.cc.
| File * PosixSubsystem::findFileRetained | ( | const String & | path, |
| ResolvedPath & | result, | ||
| const FilesystemPathRef & | workingDir = FilesystemPathRef(), |
||
| bool | followFinal = false |
||
| ) |
Definition at line 2376 of file PosixSubsystem.cc.
| File * PosixSubsystem::followFile | ( | ResolvedPath & | selected | ) |
Definition at line 2394 of file PosixSubsystem.cc.
| void PosixSubsystem::freeFd | ( | size_t | fdNum | ) |
Sets the given file descriptor as "available" and deletes the FileDescriptor linked to it.
Definition at line 1601 of file PosixSubsystem.cc.
References ExtensibleBitmap::clear(), SharedPointer< T >::get(), m_FdBitmap, m_FdLock, m_FdMap, m_LastFd, Semaphore::release(), SharedPointer< T >::reset(), and Tree< K, E >::take().
| void PosixSubsystem::freeMultipleFds | ( | bool | bOnlyCloExec = false, |
| size_t | iFirst = 0, |
||
| size_t | iLast = -1 |
||
| ) |
Frees a range of descriptors (or only those marked FD_CLOEXEC)
Definition at line 1684 of file PosixSubsystem.cc.
References List< T, nodePoolSize >::begin(), Tree< K, E >::begin(), Vector< T >::clear(), ExtensibleBitmap::clear(), Vector< T >::count(), List< T, nodePoolSize >::end(), Tree< K, E >::end(), m_FdBitmap, m_FdLock, m_FdMap, m_LastFd, List< T, nodePoolSize >::pushBack(), Vector< T >::pushBack(), Semaphore::release(), and Tree< K, E >::take().
Referenced by copyDescriptors(), exit(), invoke(), and ~PosixSubsystem().
Here is the caller graph for this function:
|
inline |
Retrieves the currently-active ABI for the subsystem.
Definition at line 755 of file PosixSubsystem.h.
Referenced by threadException().
Here is the caller graph for this function:| size_t PosixSubsystem::getFd | ( | size_t | minimum = 0 | ) |
Returns the first available file descriptor at or above minimum.
Note: POSIX requires open()/accept()/etc to be safe during a signal handler, which requires us to not allow signals during these file descriptor calls. They cannot re-enter as they take process-specific locks.
Definition at line 1557 of file PosixSubsystem.cc.
References m_FdBitmap, m_FdLock, m_LastFd, m_NextFd, Semaphore::release(), ExtensibleBitmap::set(), and ExtensibleBitmap::test().
| bool PosixSubsystem::getSignalDisposition | ( | size_t | sig, |
| SignalDisposition & | disposition, | ||
| bool | beginDelivery = false |
||
| ) |
Copies a disposition and, at delivery, atomically consumes SA_RESETHAND.
Definition at line 1298 of file PosixSubsystem.cc.
References UnlikelyLock::acquire(), UnlikelyLock::enter(), PosixSubsystem::SignalHandler::flags, Event::getHandlerAddress(), UnlikelyLock::leave(), m_SignalHandlersLock, PosixSubsystem::SignalHandler::pEvent, UnlikelyLock::release(), PosixSubsystem::SignalHandler::restorer, Event::retire(), PosixSubsystem::SignalHandler::sigMask, and PosixSubsystem::SignalHandler::type.
Referenced by threadException().
Here is the caller graph for this function:
|
inline |
Gets a signal handler
Definition at line 490 of file PosixSubsystem.h.
|
inline |
Gets a synchronisation object given a descriptor
Definition at line 584 of file PosixSubsystem.h.
|
inline |
Gets a thread given a descriptor
Definition at line 681 of file PosixSubsystem.h.
|
inline |
Gets a thread waiter object given a descriptor
Definition at line 700 of file PosixSubsystem.h.
|
inline |
Inserts a synchronisation object given a descriptor
Definition at line 589 of file PosixSubsystem.h.
|
inline |
Inserts a thread given a descriptor and a Thread
Definition at line 686 of file PosixSubsystem.h.
|
inline |
Inserts a thread waiter object, returns a descriptor
Definition at line 705 of file PosixSubsystem.h.
| size_t PosixSubsystem::installFileDescriptor | ( | FileDescriptor * | descriptor, |
| DescriptorLease & | lease, | ||
| size_t | minimum = 0 |
||
| ) |
Allocates and publishes a descriptor while returning a pin for that exact table generation. This lets multi-descriptor operations roll back safely if a later userspace copyout fails.
Definition at line 1993 of file PosixSubsystem.cc.
References FileDescriptor::fd, Tree< K, E >::insert(), m_FdBitmap, m_FdLock, m_FdMap, m_LastFd, m_NextFd, Semaphore::release(), ExtensibleBitmap::set(), and ExtensibleBitmap::test().
| void PosixSubsystem::invalidateUserImage | ( | ) |
Definition at line 383 of file PosixSubsystem.cc.
|
virtual |
Invokes the given command (SyscallState mechanism).
Implements Subsystem.
Definition at line 2431 of file PosixSubsystem.cc.
References invoke().
|
private |
Definition at line 2523 of file PosixSubsystem.cc.
| bool PosixSubsystem::invoke | ( | const FilesystemPathRef & | originalPath, |
| const String & | originalName, | ||
| Vector< String > & | argv, | ||
| Vector< String > & | env, | ||
| SyscallState & | state, | ||
| bool | descriptorPathInaccessible = false |
||
| ) |
Definition at line 2556 of file PosixSubsystem.cc.
|
virtual |
Invokes the given file (thread mechanism).
Implements Subsystem.
Definition at line 2540 of file PosixSubsystem.cc.
References invoke().
|
virtual |
Invokes the given file (SyscallState mechanism).
Implements Subsystem.
Definition at line 2545 of file PosixSubsystem.cc.
References invoke().
| bool PosixSubsystem::invoke | ( | File * | originalFile, |
| const String & | originalName, | ||
| Vector< String > & | argv, | ||
| Vector< String > & | env, | ||
| SyscallState & | state, | ||
| bool | descriptorPathInaccessible | ||
| ) |
Definition at line 2550 of file PosixSubsystem.cc.
|
private |
Invokes the given command - actual implementation.
Definition at line 2563 of file PosixSubsystem.cc.
References Thread::adoptInitialUserStackForExec(), VFS::checkAccess(), Vector< T >::count(), Thread::deferSignalExit(), Process::description(), Thread::discardUserStackMetadataForExec(), VirtualAddressSpace::Execute, freeMultipleFds(), Process::getAddressSpace(), Process::getId(), File::getName(), PhysicalMemoryManager::getPageSize(), Thread::getParent(), Thread::getUnwindState(), Process::getUserId(), Process::getUserspaceId(), ProcessorBase::information(), MemoryMapManager::instance(), SyscallManager::instance(), loadElf(), m_TraceContext, MemoryMapManager::mapAnon(), parseShebang(), Vector< T >::popFront(), prepareExecutable(), Vector< T >::pushFront(), File::read(), Process::releaseVforkAddressSpace(), Thread::resetTlsBase(), VirtualAddressSpace::revertToKernelAddressSpace(), Thread::setClearChildTid(), ProcessorBase::setInterrupts(), Thread::startDetached(), Thread::state(), Thread::TerminateThread, and MemoryMapManager::unmapAll().
|
virtual |
A thread needs to be killed!
Implements Subsystem.
Definition at line 951 of file PosixSubsystem.cc.
References Process::getId(), Thread::getParent(), ProcessorBase::information(), Scheduler::instance(), queueSignalDelivery(), ProcessorBase::setInterrupts(), and Scheduler::yield().
|
private |
Load a validated ELF's PT_LOAD sections into the address space.
Definition at line 2241 of file PosixSubsystem.cc.
References File::getName(), PhysicalMemoryManager::getPageSize(), Process::getParent(), Hex, ProcessorBase::information(), MemoryMapManager::instance(), and Elf::validateExecutableProgramHeaders().
Referenced by invoke().
Here is the caller graph for this function:| bool PosixSubsystem::matchesUserImage | ( | const UserImageToken & | token | ) | const |
Definition at line 377 of file PosixSubsystem.cc.
|
inline |
Definition at line 485 of file PosixSubsystem.h.
|
inline |
Definition at line 253 of file PosixSubsystem.h.
|
private |
Parse a bounded shebang line, if present.
Definition at line 2436 of file PosixSubsystem.cc.
References File::getFullPath(), and File::read().
Referenced by invoke().
Here is the caller graph for this function:
|
inline |
Definition at line 475 of file PosixSubsystem.h.
|
inline |
Definition at line 469 of file PosixSubsystem.h.
|
inline |
Definition at line 472 of file PosixSubsystem.h.
|
private |
Validate and retain the bounded metadata needed to load an executable.
Definition at line 2134 of file PosixSubsystem.cc.
References File::acquireMappingUse(), VirtualAddressSpace::getUserReservedStart(), VirtualAddressSpace::getUserStart(), ProcessorBase::information(), File::read(), Elf::validateExecutableHeader(), Elf::validateExecutableInterpreter(), and Elf::validateExecutableProgramHeaders().
Referenced by invoke().
Here is the caller graph for this function:
|
privatevirtual |
Preserves process state after exec admission closes and before peers exit.
Reimplemented from Subsystem.
Definition at line 2027 of file PosixSubsystem.cc.
References Process::acquireThread(), Process::getNumThreads(), m_SignalHandlersLock, and Thread::transferProcessSignalsTo().
| TraceStatus PosixSubsystem::prepareTraceSignal | ( | Thread & | thread, |
| int | signal, | ||
| int32_t | pid, | ||
| uint32_t | uid, | ||
| bool | inheritReservation, | ||
| UniquePointer< SignalEvent > & | result | ||
| ) |
Definition at line 45 of file trace-signals.cc.
|
privatevirtual |
Preserves process-owned pending work before an exiting thread drains it.
Reimplemented from Subsystem.
Definition at line 2041 of file PosixSubsystem.cc.
References Process::acquireProcessSignalThread(), m_SignalHandlersLock, and Thread::transferProcessSignalsTo().
|
private |
Definition at line 1797 of file PosixSubsystem.cc.
|
private |
Definition at line 1765 of file PosixSubsystem.cc.
| bool PosixSubsystem::publishTraceSignal | ( | Thread & | thread, |
| UniquePointer< SignalEvent > & | prepared, | ||
| SignalEvent * | source | ||
| ) |
Definition at line 76 of file trace-signals.cc.
| bool PosixSubsystem::publishUserImage | ( | VirtualAddressSpace & | space | ) |
Definition at line 389 of file PosixSubsystem.cc.
| PosixSubsystem::SignalDeliveryResult PosixSubsystem::queueSignalDelivery | ( | Thread * | target, |
| size_t | sig, | ||
| uint32_t * | flags = nullptr, |
||
| int32_t | signalCode = 0, |
||
| bool | processDirected = false, |
||
| uint64_t | signalValue = 0, |
||
| const SharedPointer< SignalEventState > & | state = SharedPointer<SignalEventState>() |
||
| ) |
Resolves and queues a signal atomically with disposition replacement.
Definition at line 1344 of file PosixSubsystem.cc.
References UnlikelyLock::acquire(), Process::acquireProcessSignalThread(), Process::acquireThread(), SignalEvent::cloneForDelivery(), Thread::Continue, Thread::cullSignalEvent(), PosixSubsystem::SignalHandler::flags, SharedPointer< T >::get(), Process::getExitStatus(), Process::getNumThreads(), Process::getParent(), Thread::getParent(), Thread::getSignalMask(), Thread::getUnwindState(), Process::getUserId(), Process::getUserspaceId(), Process::getUserTime(), Thread::hasSignalEvent(), ProcessorBase::information(), LinuxPrivateSignalFirst, m_SignalHandlersLock, m_TraceContext, PosixSubsystem::SignalHandler::pEvent, UnlikelyLock::release(), Process::resume(), Thread::sendEvent(), SignalEvent::setSignalOrigin(), and PosixSubsystem::SignalHandler::type.
Referenced by kill(), and sendSignal().
Here is the caller graph for this function:
|
static |
Copies a resident file prefix directly into an anonymous user buffer. Zero requests the ordinary read/copy fallback, including for file mappings which might alias the source. No backend read runs under the mapping gate.
Definition at line 782 of file PosixSubsystem.cc.
References MemoryMapManager::instance(), File::readCached(), File::supportsRegularFileOperations(), and MemoryMapManager::writableAnonymousRange().
|
inline |
Definition at line 436 of file PosixSubsystem.h.
|
virtual |
Release mutual exclusion acquired via acquire().
Reimplemented from Subsystem.
Definition at line 562 of file PosixSubsystem.cc.
References Spinlock::acquire(), m_bAcquired, m_FdLock, m_Lock, m_pAcquiredThread, m_SignalHandlersLock, Spinlock::release(), UnlikelyLock::release(), and Semaphore::release().
Referenced by ~PosixSubsystem().
Here is the caller graph for this function:
|
inline |
Removes a semaphore given a descriptor
Definition at line 600 of file PosixSubsystem.h.
|
inline |
Removes a thread given a descriptor
Definition at line 695 of file PosixSubsystem.h.
|
inline |
Removes a thread waiter object given a descriptor
Definition at line 715 of file PosixSubsystem.h.
| void PosixSubsystem::resetSignalHandlersForExec | ( | Thread * | thread, |
| SignalHandler *const | handlers[SignalDispositionCount] | ||
| ) |
Installs a complete exec-time disposition table and rebinds pending deliveries to it. Takes ownership of every entry in handlers.
Definition at line 1257 of file PosixSubsystem.cc.
References UnlikelyLock::acquire(), Process::getNumThreads(), Thread::getParent(), m_SignalHandlersLock, PosixSubsystem::SignalHandler::pEvent, UnlikelyLock::release(), and PosixSubsystem::SignalHandler::sig.
|
overridevirtual |
Retry a userspace page fault after raw interrupt scopes have retired.
Reimplemented from Subsystem.
Definition at line 987 of file PosixSubsystem.cc.
References Process::getAddressSpace(), ProcessorBase::getInterrupts(), Thread::getParent(), ProcessorBase::information(), MemoryMapManager::instance(), and threadException().
| void PosixSubsystem::retireDescriptor | ( | FileDescriptor * | descriptor | ) |
Definition at line 2054 of file PosixSubsystem.cc.
|
virtual |
Send a POSIX signal to a thread or its process.
Definition at line 1156 of file PosixSubsystem.cc.
References PerProcessorScheduler::checkEventState(), Dec, Process::getId(), Thread::getId(), Thread::getParent(), Thread::getScheduler(), ProcessorBase::information(), Scheduler::instance(), queueSignalDelivery(), and Scheduler::yield().
Referenced by IntervalTimer::signal(), and threadException().
Here is the caller graph for this function:
|
inline |
Switch the ABI of the subsystem to the specified choice.
Definition at line 760 of file PosixSubsystem.h.
|
overridevirtual |
Sets the process that this subsystem is linked to.
Reimplemented from Subsystem.
Definition at line 329 of file PosixSubsystem.cc.
References Process::getAddressSpace(), MemoryMapManager::instance(), m_TraceContext, and Subsystem::setProcess().
| void PosixSubsystem::setSignalHandler | ( | size_t | sig, |
| SignalHandler * | handler | ||
| ) |
Sets a signal handler
Definition at line 1202 of file PosixSubsystem.cc.
References UnlikelyLock::acquire(), Process::acquireThread(), Thread::cullSignalEvent(), Dec, Process::getNumThreads(), m_SignalHandlersLock, PosixSubsystem::SignalHandler::pEvent, UnlikelyLock::release(), PosixSubsystem::SignalHandler::sig, and PosixSubsystem::SignalHandler::type.
| bool PosixSubsystem::snapshotUserImage | ( | UserImageToken & | token | ) | const |
Definition at line 367 of file PosixSubsystem.cc.
|
virtual |
A thread has thrown an exception!
Reimplemented from Subsystem.
Definition at line 1011 of file PosixSubsystem.cc.
References Dec, Thread::deferSignalExit(), EMIT_IF, getAbi(), Process::getId(), Thread::getId(), Thread::getParent(), getSignalDisposition(), Thread::getTlsBase(), Hex, ProcessorBase::id(), and sendSignal().
Referenced by resolveUserPageFault().
Here is the caller graph for this function:
|
privatevirtual |
Notifies the subsystem immediately before a thread announces exit.
Reimplemented from Subsystem.
Definition at line 2069 of file PosixSubsystem.cc.
References Thread::getParent(), Process::getUserspaceId(), and m_TraceContext.
|
privatevirtual |
Notifies the subsystem that the given thread has been removed.
Reimplemented from Subsystem.
Definition at line 2114 of file PosixSubsystem.cc.
References Completion::complete(), and m_Threads.
|
inline |
Definition at line 261 of file PosixSubsystem.h.
| bool PosixSubsystem::traceException | ( | Thread & | thread, |
| int & | signal, | ||
| InterruptState & | state, | ||
| ExceptionType | exception, | ||
| uintptr_t | address, | ||
| uintptr_t | errorCode | ||
| ) |
Definition at line 180 of file trace-signals.cc.
|
inline |
Definition at line 264 of file PosixSubsystem.h.
|
overridevirtual |
Reimplemented from Subsystem.
Definition at line 156 of file trace-signals.cc.
|
overridevirtual |
Reimplemented from Subsystem.
Definition at line 103 of file trace-signals.cc.
|
staticconstexprprivate |
Definition at line 767 of file PosixSubsystem.h.
|
staticconstexpr |
Bundled musl reserves these signals for its timer, cancellation, and synchronous-call machinery. Public realtime signals occupy 35..64.
Definition at line 192 of file PosixSubsystem.h.
Referenced by queueSignalDelivery().
|
private |
ABI for the subsystem This affects syscall parameters and the behaviors of some syscalls.
Definition at line 859 of file PosixSubsystem.h.
|
private |
Definition at line 805 of file PosixSubsystem.h.
|
private |
Are we acquired?
Definition at line 864 of file PosixSubsystem.h.
|
private |
Definition at line 803 of file PosixSubsystem.h.
Definition at line 853 of file PosixSubsystem.h.
|
private |
Definition at line 852 of file PosixSubsystem.h.
|
private |
File descriptors used by this process
Definition at line 831 of file PosixSubsystem.h.
Referenced by addFileDescriptor(), allocateFd(), closeFileDescriptor(), copyDescriptors(), duplicateFileDescriptor(), freeFd(), freeMultipleFds(), getFd(), and installFileDescriptor().
|
private |
Definition at line 818 of file PosixSubsystem.h.
|
private |
Serializes descriptor mutation, enumeration, and allocation metadata. Ordinary lookup retains a lease through m_FdEntries under RCU.
Definition at line 827 of file PosixSubsystem.h.
Referenced by acquireNextFileDescriptor(), addFileDescriptor(), allocateFd(), closeFileDescriptor(), copyDescriptors(), descriptorMatchesOpenDescription(), duplicateFileDescriptor(), freeFd(), freeMultipleFds(), getFd(), installFileDescriptor(), and release().
|
private |
The file descriptor map. Maps number to pointers, the type of which is decided by the subsystem.
Definition at line 817 of file PosixSubsystem.h.
Referenced by acquireNextFileDescriptor(), addFileDescriptor(), closeFileDescriptor(), copyDescriptors(), descriptorMatchesOpenDescription(), duplicateFileDescriptor(), freeFd(), freeMultipleFds(), and installFileDescriptor().
|
private |
Number of times freed
Definition at line 839 of file PosixSubsystem.h.
Referenced by ~PosixSubsystem().
|
mutableprivate |
Definition at line 851 of file PosixSubsystem.h.
|
private |
Last known unallocated descriptor
Definition at line 835 of file PosixSubsystem.h.
Referenced by closeFileDescriptor(), freeFd(), freeMultipleFds(), getFd(), and installFileDescriptor().
|
private |
Safety spinlock for mutual exclusion in acquire().
Definition at line 874 of file PosixSubsystem.h.
|
private |
Definition at line 806 of file PosixSubsystem.h.
|
private |
Definition at line 807 of file PosixSubsystem.h.
|
private |
The next available file descriptor.
Definition at line 822 of file PosixSubsystem.h.
Referenced by addFileDescriptor(), allocateFd(), copyDescriptors(), duplicateFileDescriptor(), getFd(), and installFileDescriptor().
|
private |
Definition at line 850 of file PosixSubsystem.h.
|
private |
Which thread acquired?
Definition at line 869 of file PosixSubsystem.h.
|
private |
Definition at line 804 of file PosixSubsystem.h.
|
private |
Definition at line 798 of file PosixSubsystem.h.
|
private |
A lock for access to the signal handlers tree
Definition at line 801 of file PosixSubsystem.h.
Referenced by acquire(), getSignalDisposition(), PosixSubsystem(), prepareThreadsForExec(), preserveProcessSignalsForThreadExit(), queueSignalDelivery(), release(), resetSignalHandlersForExec(), and setSignalHandler().
|
private |
Links some file descriptors to PosixSyncObjects.
Definition at line 841 of file PosixSubsystem.h.
Referenced by ~PosixSubsystem().
|
private |
Links some thread handles to Threads.
Definition at line 845 of file PosixSubsystem.h.
Referenced by threadRemoved(), and ~PosixSubsystem().
Links waiter objects to Semaphores.
Definition at line 849 of file PosixSubsystem.h.
Referenced by PosixSubsystem(), and ~PosixSubsystem().
|
private |
Signal handlers
Definition at line 797 of file PosixSubsystem.h.
Referenced by exit(), invoke(), queueSignalDelivery(), setProcess(), threadExiting(), and ~PosixSubsystem().
|
private |
Definition at line 811 of file PosixSubsystem.h.
|
private |
Definition at line 810 of file PosixSubsystem.h.
|
private |
Definition at line 809 of file PosixSubsystem.h.
|
staticconstexpr |
Definition at line 307 of file PosixSubsystem.h.
|
staticconstexpr |
Definition at line 193 of file PosixSubsystem.h.
|
static |
Definition at line 186 of file PosixSubsystem.h.
|
static |
Definition at line 184 of file PosixSubsystem.h.
|
static |
Sanitise flags.
Definition at line 183 of file PosixSubsystem.h.
|
static |
Definition at line 185 of file PosixSubsystem.h.
|
staticconstexpr |
Definition at line 194 of file PosixSubsystem.h.