149 static const int None = 0x0;
150 static const int Read = 0x1;
151 static const int Write = 0x2;
152 static const int Exec = 0x4;
161 m_MaximumPermissions(maximumPerms),
163 m_OwnerProcess(nullptr),
164 m_OwnsMappings(true),
165 m_LockMode(MemoryLockMode::None) {}
190 uintptr_t destination,
size_t destinationLength) = 0;
191 void setMappingOwnership(
bool ownsMappings) {
192 m_OwnsMappings = ownsMappings;
194 virtual void releaseDetachedPage(uintptr_t oldAddress,
197 virtual File* backingFile()
const {
200 virtual bool backingRangeValid(uintptr_t source,
size_t length)
const {
224 virtual bool preparePermissions(uintptr_t base,
size_t length,
Permissions perms) {
231 virtual bool sync(uintptr_t at,
bool async) {
241 virtual bool sharedBacking(uintptr_t at, uintptr_t&
identity,
size_t& offset)
const {
245 virtual bool usesBacking(uintptr_t
identity)
const {
248 virtual bool beyondBackingEnd(uintptr_t at)
const {
269 PopulationStatus* population =
nullptr) = 0;
271 return PopulationStatus::Success;
274 MemoryLockMode lockMode()
const {
287 return SwapStatus::Unsupported;
293 return SwapStatus::Success;
295 virtual bool compact() {
326 return m_MaximumPermissions;
371 MemoryLockMode m_LockMode;
387#if HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS
388 static void setCloneFailureForTest(ssize_t after);
393 MemoryMappedObject* stageSlice(uintptr_t source,
size_t sourceLength, uintptr_t destination,
394 size_t destinationLength)
override;
395 void releaseDetachedPage(uintptr_t oldAddress,
398 virtual bool remove(
size_t length)
override;
402 virtual void unmap()
override;
405 PopulationStatus* population =
nullptr)
override;
407 SwapStatus pageOutAt(
VirtualAddressSpace& space, uintptr_t address,
bool& released)
override;
409 return pageOut(space);
412 return restoreAll(space);
414 PopulationStatus prepareResidentAccess(
VirtualAddressSpace& space, uintptr_t address)
override;
419 uintptr_t address = 0;
421 bool pagingBlocked =
false;
426 static physical_uintptr_t m_Zero;
427 static bool initialisePhysicalPage(physical_uintptr_t physical);
429 void unmapUnlocked();
448 uintptr_t
address,
size_t length,
size_t offset,
File* backing,
bool bCopyOnWrite,
458 size_t destinationLength)
override;
459 void releaseDetachedPage(uintptr_t oldAddress,
462 File* backingFile()
const override {
465 bool backingRangeValid(uintptr_t source,
size_t length)
const override;
467 void* credentials)
override;
472 virtual bool sync(uintptr_t at,
bool async)
override;
474 virtual void invalidate(uintptr_t at)
override;
475 virtual bool sharedBacking(uintptr_t at, uintptr_t&
identity,
size_t& offset)
const override;
476 virtual bool usesBacking(uintptr_t
identity)
const override;
477 virtual bool beyondBackingEnd(uintptr_t at)
const override;
479 virtual bool preparePermissions(uintptr_t base,
size_t length,
Permissions perms)
override;
481 virtual void unmap()
override;
484 PopulationStatus* population =
nullptr)
override;
501 virtual bool compact()
override;
504 void unmapUnlocked();
506 physical_uintptr_t getBackingPage(
size_t fileOffset,
size_t mappingBytes);
508 void releaseDetachedPageUnlocked(uintptr_t oldAddress,
532 size_t m_ReadAheadEnd = ~size_t{0};
533 size_t m_ReadAheadPages = 4;
549 bool m_ExecutableUse;
550 bool m_SharedWriteUse;
552 bool m_MountAdmitted;
564 enum class Placement {
570 enum class MapStatus {
579 enum class VmStatus { Success, InvalidRange, Unmapped, Unsupported, NoMemory, LockLimit };
580 enum class FileRemapStatus {
589 FileRemapStatus remapFilePages(uintptr_t base,
size_t length,
size_t byteOffset,
bool nonblock);
591 uintptr_t source, destination;
592 size_t oldLength, newLength;
595 VmStatus remap(
const RemapRequest& request, uintptr_t& result);
596 VmStatus residency(uintptr_t base,
size_t length,
unsigned char* kernelVector,
597 FileResidencyAccess access,
void* credentials);
598 VmStatus discard(uintptr_t base,
size_t length);
600 enum class UserPageCopyStatus { Success, Inaccessible, NoMemory, IoError, Unsupported };
602 void* kernelBuffer,
size_t bytes,
bool write);
604 PopulationStatus populateMemory(
VirtualAddressSpace& space, uintptr_t base,
size_t length);
607 MemoryLockMode mode,
bool privileged);
609 MemoryLockMode currentMode, MemoryLockMode futureMode,
618#if HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS
620 void acquireLifecycleGateForHostedTest();
621 void releaseLifecycleGateForHostedTest();
622 bool trapForHostedTest(uintptr_t address,
bool bIsWrite,
bool bWasPresent);
623 const void* lifecycleGateAddressForHostedTest()
const {
624 return static_cast<const Semaphore*
>(&m_LifecycleLock);
633 bool bCopyOnWrite =
true);
636 bool hasSharedWriteCapability(
File* backing);
640 size_t offset,
bool bCopyOnWrite, Placement placement, MapStatus* status,
642 MemoryMappedObject::Write |
643 MemoryMappedObject::Exec,
645 MemoryLockMode requestedLock = MemoryLockMode::None,
const FileMappingOrigin& origin = {});
656 MemoryLockMode requestedLock = MemoryLockMode::None);
664 SwapStatus pageOutRange(uintptr_t base,
size_t length);
665 SwapStatus activateSwap(uint32_t endpoint);
666 SwapStatus deactivateSwap(uint32_t endpoint);
668 bool operationOwnedByCurrentExecution();
679 size_t remove(uintptr_t base,
size_t length);
688 size_t removeAndRelease(uintptr_t base,
size_t length, VmStatus* status =
nullptr);
713 ProtectStatus* status =
nullptr);
719 bool contains(uintptr_t base,
size_t length);
727 bool sharedBacking(
Process* process, uintptr_t address, uintptr_t&
identity,
size_t& offset);
729 bool faultIn(uintptr_t address,
bool write);
731 bool faultInRange(uintptr_t address,
size_t length,
bool write);
735 bool writableAnonymousRange(uintptr_t address,
size_t length);
737 enum class FaultResolution { Unhandled, Resolved, BackingFault };
738 FaultResolution resolveUserFault(uintptr_t address,
bool write,
bool wasPresent,
bool execute);
740 enum class ResizeStatus { Ready, NoMemory, Unsupported, Invalid };
745 size_t loanCount()
const;
746 size_t totalLoans()
const;
759 ResizeStatus prepareFileResize(
File* file,
size_t oldSize,
size_t newSize,
766 bool sync(uintptr_t base,
size_t length,
bool async,
int* error =
nullptr);
769 void invalidate(uintptr_t base,
size_t length);
784 virtual bool trap(InterruptState& state, uintptr_t address,
bool bIsWrite,
bool bWasPresent);
791 virtual bool compact();
794 return "Unmap safe pages from memory mapped files.";
803 void unmapAllUnlocked();
832 explicit operator bool()
const {
850 MemoryLockStatus prepareManagedLocks(
VirtualAddressSpace& space, uintptr_t base,
size_t length,
851 MemoryLockMode mode,
bool all,
855 bool copyOnWrite, Placement placement, MapStatus* status,
858 MemoryLockMode requestedLock,
862 void enterOperation();
863 bool tryEnterOperation();
864 void leaveOperation();
866 size_t removeInternal(uintptr_t base,
size_t length,
bool releaseReservations,
867 VmStatus* status =
nullptr);
871 bool residentAnonymousOnly =
false);
872 bool accessRange(uintptr_t address,
size_t length,
bool write,
bool residentAnonymousOnly);
873 bool handleTrapUnlocked(uintptr_t address,
bool bIsWrite,
bool bWasPresent,
bool execute,
875 bool handleTrap(uintptr_t address,
bool bIsWrite,
bool bWasPresent,
bool execute =
false,
883 bool op(Ops what, uintptr_t base,
size_t length,
bool async);
905 void* m_pLifecycleOwner;
906 size_t m_LifecycleDepth;