|
The Pedigree Project 0.1
|
#include <PosixSubsystem.h>
Inheritance diagram for PosixSubsystem:
Collaboration diagram for PosixSubsystem:Classes | |
| struct | ExecutableImage |
| 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 |
| 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 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 () |
| 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) |
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 181 of file PosixSubsystem.h.
| enum PosixSubsystem::Abi |
ABI mode.
Definition at line 200 of file PosixSubsystem.h.
|
strongprivate |
Definition at line 789 of file PosixSubsystem.h.
|
strong |
Definition at line 183 of file PosixSubsystem.h.
|
strong |
Definition at line 421 of file PosixSubsystem.h.
| enum PosixSubsystem::UserStringResult |
Definition at line 335 of file PosixSubsystem.h.
|
inline |
Default constructor
Definition at line 206 of file PosixSubsystem.h.
| PosixSubsystem::PosixSubsystem | ( | PosixSubsystem & | s, |
| bool | clearSignalHandlers = false |
||
| ) |
Copy constructor
Definition at line 230 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 232 of file PosixSubsystem.h.
|
virtual |
Default destructor
Definition at line 373 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 513 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 507 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 1687 of file PosixSubsystem.cc.
References Tree< K, E >::lookup(), m_FdLock, m_FdMap, and Semaphore::release().
| bool PosixSubsystem::acquireNextFileDescriptor | ( | size_t | minimum, |
| size_t & | fd, | ||
| DescriptorLease & | descriptor | ||
| ) |
Retain the lowest published descriptor at or after minimum.
Definition at line 1699 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 1774 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 1149 of file PosixSubsystem.cc.
|
inline |
Definition at line 477 of file PosixSubsystem.h.
|
inline |
Definition at line 429 of file PosixSubsystem.h.
| void PosixSubsystem::allocateFd | ( | size_t | fdNum | ) |
Sets the given file descriptor as "in use".
Definition at line 1531 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 1991 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 547 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 659 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 673 of file PosixSubsystem.cc.
References checkedUserBufferSize().
|
static |
Validate a userspace array after checking its size calculation.
Definition at line 694 of file PosixSubsystem.cc.
References checkAddress(), and checkedUserBufferSize().
|
private |
Definition at line 1950 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 1737 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 334 of file PosixSubsystem.cc.
| bool PosixSubsystem::copyDescriptors | ( | PosixSubsystem * | pSubsystem | ) |
Copies file descriptors from another subsystem
Definition at line 1571 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 711 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 733 of file PosixSubsystem.cc.
References checkedUserBufferSize(), and MemoryMapManager::instance().
Referenced by FramebufferFile::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 755 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 1722 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 1801 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 328 of file PosixSubsystem.cc.
| bool PosixSubsystem::executablePath | ( | String & | result | ) | const |
Definition at line 317 of file PosixSubsystem.cc.
|
virtual |
Need to exit this process.
Implements Subsystem.
Definition at line 818 of file PosixSubsystem.cc.
References Process::beginTermination(), Thread::Continue, Dec, Process::finishTermination(), freeMultipleFds(), Process::getAddressSpace(), Process::getId(), ProcessorBase::getInterrupts(), Thread::getParent(), Process::getUserspaceId(), ProcessorBase::inDeviceHardIrq(), ProcessorBase::information(), MemoryMapManager::instance(), m_TraceContext, Thread::notifySubsystemExit(), Process::quiesceTermination(), Process::releaseVforkAddressSpace(), Process::setExitStatus(), Thread::setUnwindState(), Thread::unexpectedExit(), and MemoryMapManager::unmapAll().
| File * PosixSubsystem::findFileRetained | ( | const String & | path, |
| ResolvedPath & | result, | ||
| const FilesystemPathRef & | workingDir = FilesystemPathRef(), |
||
| bool | followFinal = false |
||
| ) |
Definition at line 2238 of file PosixSubsystem.cc.
| File * PosixSubsystem::followFile | ( | ResolvedPath & | selected | ) |
Definition at line 2256 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 1544 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 1623 of file PosixSubsystem.cc.
References List< T, nodePoolSize >::begin(), Tree< K, E >::begin(), Vector< T >::clear(), ExtensibleBitmap::clear(), 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 746 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 1500 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 1257 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 486 of file PosixSubsystem.h.
|
inline |
Gets a synchronisation object given a descriptor
Definition at line 580 of file PosixSubsystem.h.
|
inline |
Gets a thread given a descriptor
Definition at line 677 of file PosixSubsystem.h.
|
inline |
Gets a thread waiter object given a descriptor
Definition at line 696 of file PosixSubsystem.h.
|
inline |
Inserts a synchronisation object given a descriptor
Definition at line 585 of file PosixSubsystem.h.
|
inline |
Inserts a thread given a descriptor and a Thread
Definition at line 682 of file PosixSubsystem.h.
|
inline |
Inserts a thread waiter object, returns a descriptor
Definition at line 701 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 1856 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 356 of file PosixSubsystem.cc.
|
virtual |
Invokes the given command (SyscallState mechanism).
Implements Subsystem.
Definition at line 2293 of file PosixSubsystem.cc.
References invoke().
|
private |
Definition at line 2385 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 2418 of file PosixSubsystem.cc.
|
virtual |
Invokes the given file (thread mechanism).
Implements Subsystem.
Definition at line 2402 of file PosixSubsystem.cc.
References invoke().
|
virtual |
Invokes the given file (SyscallState mechanism).
Implements Subsystem.
Definition at line 2407 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 2412 of file PosixSubsystem.cc.
|
private |
Invokes the given command - actual implementation.
Definition at line 2425 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::getTaskId(), 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 910 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 2103 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 350 of file PosixSubsystem.cc.
|
inline |
Definition at line 481 of file PosixSubsystem.h.
|
inline |
Definition at line 254 of file PosixSubsystem.h.
|
private |
Parse a bounded shebang line, if present.
Definition at line 2298 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 471 of file PosixSubsystem.h.
|
inline |
Definition at line 465 of file PosixSubsystem.h.
|
inline |
Definition at line 468 of file PosixSubsystem.h.
|
private |
Validate and retain the bounded metadata needed to load an executable.
Definition at line 1996 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 1889 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 1903 of file PosixSubsystem.cc.
References Process::acquireProcessSignalThread(), m_SignalHandlersLock, and Thread::transferProcessSignalsTo().
| 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 362 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 1303 of file PosixSubsystem.cc.
References UnlikelyLock::acquire(), Process::acquireProcessSignalThread(), Process::acquireThread(), SignalEvent::cloneForDelivery(), Thread::Continue, Thread::cullSignalEvent(), PosixSubsystem::SignalHandler::flags, 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:
|
inline |
Definition at line 432 of file PosixSubsystem.h.
|
virtual |
Release mutual exclusion acquired via acquire().
Reimplemented from Subsystem.
Definition at line 535 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 596 of file PosixSubsystem.h.
|
inline |
Removes a thread given a descriptor
Definition at line 691 of file PosixSubsystem.h.
|
inline |
Removes a thread waiter object given a descriptor
Definition at line 711 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 1216 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 946 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 1916 of file PosixSubsystem.cc.
|
virtual |
Send a POSIX signal to a thread or its process.
Definition at line 1115 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 751 of file PosixSubsystem.h.
|
overridevirtual |
Sets the process that this subsystem is linked to.
Reimplemented from Subsystem.
Definition at line 302 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 1161 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 340 of file PosixSubsystem.cc.
|
virtual |
A thread has thrown an exception!
Reimplemented from Subsystem.
Definition at line 973 of file PosixSubsystem.cc.
References Dec, Thread::deferSignalExit(), 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 1931 of file PosixSubsystem.cc.
References Thread::getParent(), Thread::getTaskId(), Process::getUserspaceId(), and m_TraceContext.
|
privatevirtual |
Notifies the subsystem that the given thread has been removed.
Reimplemented from Subsystem.
Definition at line 1976 of file PosixSubsystem.cc.
References Completion::complete(), and m_Threads.
|
inline |
Definition at line 262 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 265 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.
|
staticconstexpr |
Bundled musl reserves these signals for its timer, cancellation, and synchronous-call machinery. Public realtime signals occupy 35..64.
Definition at line 195 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 844 of file PosixSubsystem.h.
|
private |
Definition at line 792 of file PosixSubsystem.h.
|
private |
Are we acquired?
Definition at line 849 of file PosixSubsystem.h.
|
private |
Definition at line 790 of file PosixSubsystem.h.
Definition at line 838 of file PosixSubsystem.h.
|
private |
Definition at line 837 of file PosixSubsystem.h.
|
private |
File descriptors used by this process
Definition at line 816 of file PosixSubsystem.h.
Referenced by addFileDescriptor(), allocateFd(), closeFileDescriptor(), copyDescriptors(), duplicateFileDescriptor(), freeFd(), freeMultipleFds(), getFd(), and installFileDescriptor().
|
private |
Serializes descriptor lookup, publication, and allocation metadata.
Definition at line 812 of file PosixSubsystem.h.
Referenced by acquireFileDescriptor(), 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 804 of file PosixSubsystem.h.
Referenced by acquireFileDescriptor(), acquireNextFileDescriptor(), addFileDescriptor(), closeFileDescriptor(), copyDescriptors(), descriptorMatchesOpenDescription(), duplicateFileDescriptor(), freeFd(), freeMultipleFds(), and installFileDescriptor().
|
private |
Number of times freed
Definition at line 824 of file PosixSubsystem.h.
Referenced by ~PosixSubsystem().
|
mutableprivate |
Definition at line 836 of file PosixSubsystem.h.
|
private |
Last known unallocated descriptor
Definition at line 820 of file PosixSubsystem.h.
Referenced by closeFileDescriptor(), freeFd(), freeMultipleFds(), getFd(), and installFileDescriptor().
|
private |
Safety spinlock for mutual exclusion in acquire().
Definition at line 859 of file PosixSubsystem.h.
|
private |
Definition at line 793 of file PosixSubsystem.h.
|
private |
Definition at line 794 of file PosixSubsystem.h.
|
private |
The next available file descriptor.
Definition at line 808 of file PosixSubsystem.h.
Referenced by addFileDescriptor(), allocateFd(), copyDescriptors(), duplicateFileDescriptor(), getFd(), and installFileDescriptor().
|
private |
Definition at line 835 of file PosixSubsystem.h.
|
private |
Which thread acquired?
Definition at line 854 of file PosixSubsystem.h.
|
private |
Definition at line 791 of file PosixSubsystem.h.
|
private |
Definition at line 785 of file PosixSubsystem.h.
|
private |
A lock for access to the signal handlers tree
Definition at line 788 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 826 of file PosixSubsystem.h.
Referenced by ~PosixSubsystem().
|
private |
Links some thread handles to Threads.
Definition at line 830 of file PosixSubsystem.h.
Referenced by threadRemoved(), and ~PosixSubsystem().
Links waiter objects to Semaphores.
Definition at line 834 of file PosixSubsystem.h.
Referenced by PosixSubsystem(), and ~PosixSubsystem().
|
private |
Signal handlers
Definition at line 784 of file PosixSubsystem.h.
Referenced by exit(), invoke(), queueSignalDelivery(), setProcess(), threadExiting(), and ~PosixSubsystem().
|
private |
Definition at line 798 of file PosixSubsystem.h.
|
private |
Definition at line 797 of file PosixSubsystem.h.
|
private |
Definition at line 796 of file PosixSubsystem.h.
|
staticconstexpr |
Definition at line 308 of file PosixSubsystem.h.
|
staticconstexpr |
Definition at line 196 of file PosixSubsystem.h.
|
static |
Definition at line 189 of file PosixSubsystem.h.
|
static |
Definition at line 187 of file PosixSubsystem.h.
|
static |
Sanitise flags.
Definition at line 186 of file PosixSubsystem.h.
|
static |
Definition at line 188 of file PosixSubsystem.h.
|
staticconstexpr |
Definition at line 197 of file PosixSubsystem.h.