physmem: add helpers, cleanup logic.

This commit is contained in:
Michael Scire
2019-07-07 12:55:30 -07:00
parent b901cd584e
commit ce64a9fab9
2 changed files with 169 additions and 170 deletions

View File

@ -303,6 +303,15 @@ struct VirtualMemoryArea {
PAddr paddr = 0;
Common::MemoryHookPointer mmio_handler = nullptr;
/// If the address lies within this VMA, returns the size left before the
/// end of this VMA. If the given address doesn't lie within the VMA, then
/// an empty optional value is returned.
///
/// For example, given a VMA 100 bytes long. If '10' was given as the
/// start address, then this would return 90.
///
std::optional<u64> SizeRemainingFromAddress(VAddr address) const;
/// Tests if this area can be merged to the right with `next`.
bool CanBeMergedWith(const VirtualMemoryArea& next) const;
};
@ -735,6 +744,13 @@ private:
MemoryAttribute attribute_mask, MemoryAttribute attribute,
MemoryAttribute ignore_mask) const;
/// Gets the amount of memory currently mapped (state != Unmapped) in a range.
ResultVal<std::size_t> SizeOfAllocatedVMAsInRange(VAddr address, std::size_t size) const;
/// Gets the amount of memory unmappable by UnmapPhysicalMemory in a range.
ResultVal<std::size_t> SizeOfUnmappablePhysicalMemoryInRange(VAddr address,
std::size_t size) const;
/**
* A map covering the entirety of the managed address space, keyed by the `base` field of each
* VMA. It must always be modified by splitting or merging VMAs, so that the invariant