148 static const int None = 0x0;
149 static const int Read = 0x1;
150 static const int Write = 0x2;
151 static const int Exec = 0x4;
160 m_MaximumPermissions(maximumPerms),
162 m_OwnerProcess(nullptr),
163 m_OwnsMappings(true),
164 m_LockMode(MemoryLockMode::None) {}
189 uintptr_t destination,
size_t destinationLength) = 0;
190 void setMappingOwnership(
bool ownsMappings) {
191 m_OwnsMappings = ownsMappings;
193 virtual void releaseDetachedPage(uintptr_t oldAddress,
196 virtual File* backingFile()
const {
199 virtual bool backingRangeValid(uintptr_t source,
size_t length)
const {
223 virtual bool preparePermissions(uintptr_t base,
size_t length,
Permissions perms) {
230 virtual bool sync(uintptr_t at,
bool async) {
240 virtual bool sharedBacking(uintptr_t at, uintptr_t&
identity,
size_t& offset)
const {
244 virtual bool usesBacking(uintptr_t
identity)
const {
247 virtual bool beyondBackingEnd(uintptr_t at)
const {
268 PopulationStatus* population =
nullptr) = 0;
270 return PopulationStatus::Success;
273 MemoryLockMode lockMode()
const {
286 return SwapStatus::Unsupported;
292 return SwapStatus::Success;
294 virtual bool compact() {
325 return m_MaximumPermissions;
370 MemoryLockMode m_LockMode;
386#if HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS
387 static void setCloneFailureForTest(ssize_t after);
392 MemoryMappedObject* stageSlice(uintptr_t source,
size_t sourceLength, uintptr_t destination,
393 size_t destinationLength)
override;
394 void releaseDetachedPage(uintptr_t oldAddress,
397 virtual bool remove(
size_t length)
override;
401 virtual void unmap()
override;
404 PopulationStatus* population =
nullptr)
override;
406 SwapStatus pageOutAt(
VirtualAddressSpace& space, uintptr_t address,
bool& released)
override;
408 return pageOut(space);
411 return restoreAll(space);
413 PopulationStatus prepareResidentAccess(
VirtualAddressSpace& space, uintptr_t address)
override;
418 uintptr_t address = 0;
420 bool pagingBlocked =
false;
425 static physical_uintptr_t m_Zero;
426 static bool initialisePhysicalPage(physical_uintptr_t physical);
428 void unmapUnlocked();
447 uintptr_t
address,
size_t length,
size_t offset,
File* backing,
bool bCopyOnWrite,
457 size_t destinationLength)
override;
458 void releaseDetachedPage(uintptr_t oldAddress,
461 File* backingFile()
const override {
464 bool backingRangeValid(uintptr_t source,
size_t length)
const override;
466 void* credentials)
override;
471 virtual bool sync(uintptr_t at,
bool async)
override;
473 virtual void invalidate(uintptr_t at)
override;
474 virtual bool sharedBacking(uintptr_t at, uintptr_t&
identity,
size_t& offset)
const override;
475 virtual bool usesBacking(uintptr_t
identity)
const override;
476 virtual bool beyondBackingEnd(uintptr_t at)
const override;
478 virtual bool preparePermissions(uintptr_t base,
size_t length,
Permissions perms)
override;
480 virtual void unmap()
override;
483 PopulationStatus* population =
nullptr)
override;
500 virtual bool compact()
override;
503 void unmapUnlocked();
505 physical_uintptr_t getBackingPage(
size_t fileOffset,
size_t mappingBytes);
507 void releaseDetachedPageUnlocked(uintptr_t oldAddress,
531 size_t m_ReadAheadEnd = ~size_t{0};
532 size_t m_ReadAheadPages = 4;
548 bool m_ExecutableUse;
549 bool m_SharedWriteUse;
562 enum class Placement {
568 enum class MapStatus {
577 enum class VmStatus { Success, InvalidRange, Unmapped, Unsupported, NoMemory, LockLimit };
578 enum class FileRemapStatus {
587 FileRemapStatus remapFilePages(uintptr_t base,
size_t length,
size_t byteOffset,
bool nonblock);
589 uintptr_t source, destination;
590 size_t oldLength, newLength;
593 VmStatus remap(
const RemapRequest& request, uintptr_t& result);
594 VmStatus residency(uintptr_t base,
size_t length,
unsigned char* kernelVector,
595 FileResidencyAccess access,
void* credentials);
596 VmStatus discard(uintptr_t base,
size_t length);
598 enum class UserPageCopyStatus { Success, Inaccessible, NoMemory, IoError, Unsupported };
600 void* kernelBuffer,
size_t bytes,
bool write);
602 PopulationStatus populateMemory(
VirtualAddressSpace& space, uintptr_t base,
size_t length);
605 MemoryLockMode mode,
bool privileged);
607 MemoryLockMode currentMode, MemoryLockMode futureMode,
616#if HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS
618 void acquireLifecycleGateForHostedTest();
619 void releaseLifecycleGateForHostedTest();
620 bool trapForHostedTest(uintptr_t address,
bool bIsWrite,
bool bWasPresent);
621 const void* lifecycleGateAddressForHostedTest()
const {
622 return static_cast<const Semaphore*
>(&m_LifecycleLock);
631 bool bCopyOnWrite =
true);
634 bool hasSharedWriteCapability(
File* backing);
638 size_t offset,
bool bCopyOnWrite, Placement placement, MapStatus* status,
640 MemoryMappedObject::Write |
641 MemoryMappedObject::Exec,
643 MemoryLockMode requestedLock = MemoryLockMode::None,
const FileMappingOrigin& origin = {});
654 MemoryLockMode requestedLock = MemoryLockMode::None);
662 SwapStatus pageOutRange(uintptr_t base,
size_t length);
663 SwapStatus activateSwap(uint32_t endpoint);
664 SwapStatus deactivateSwap(uint32_t endpoint);
666 bool operationOwnedByCurrentExecution();
677 size_t remove(uintptr_t base,
size_t length);
686 size_t removeAndRelease(uintptr_t base,
size_t length, VmStatus* status =
nullptr);
711 ProtectStatus* status =
nullptr);
717 bool contains(uintptr_t base,
size_t length);
725 bool sharedBacking(
Process* process, uintptr_t address, uintptr_t&
identity,
size_t& offset);
727 bool faultIn(uintptr_t address,
bool write);
729 bool faultInRange(uintptr_t address,
size_t length,
bool write);
733 bool writableAnonymousRange(uintptr_t address,
size_t length);
735 enum class FaultResolution { Unhandled, Resolved, BackingFault };
736 FaultResolution resolveUserFault(uintptr_t address,
bool write,
bool wasPresent,
bool execute);
738 enum class ResizeStatus { Ready, NoMemory, Unsupported, Invalid };
743 size_t loanCount()
const;
744 size_t totalLoans()
const;
757 ResizeStatus prepareFileResize(
File* file,
size_t oldSize,
size_t newSize,
764 bool sync(uintptr_t base,
size_t length,
bool async,
int* error =
nullptr);
767 void invalidate(uintptr_t base,
size_t length);
782 virtual bool trap(InterruptState& state, uintptr_t address,
bool bIsWrite,
bool bWasPresent);
789 virtual bool compact();
792 return "Unmap safe pages from memory mapped files.";
801 void unmapAllUnlocked();
830 explicit operator bool()
const {
848 MemoryLockStatus prepareManagedLocks(
VirtualAddressSpace& space, uintptr_t base,
size_t length,
849 MemoryLockMode mode,
bool all,
853 bool copyOnWrite, Placement placement, MapStatus* status,
856 MemoryLockMode requestedLock,
860 void enterOperation();
861 bool tryEnterOperation();
862 void leaveOperation();
864 size_t removeInternal(uintptr_t base,
size_t length,
bool releaseReservations,
865 VmStatus* status =
nullptr);
869 bool residentAnonymousOnly =
false);
870 bool accessRange(uintptr_t address,
size_t length,
bool write,
bool residentAnonymousOnly);
871 bool handleTrapUnlocked(uintptr_t address,
bool bIsWrite,
bool bWasPresent,
bool execute,
873 bool handleTrap(uintptr_t address,
bool bIsWrite,
bool bWasPresent,
bool execute =
false,
881 bool op(Ops what, uintptr_t base,
size_t length,
bool async);
903 void* m_pLifecycleOwner;
904 size_t m_LifecycleDepth;