59 if (!file || newSize >= oldSize || file->getSize() != oldSize) {
60 return ResizeStatus::Invalid;
63 constexpr size_t MaximumMappings = 4096;
64 constexpr size_t MaximumTrackedPages = 65536;
66 size_t mappingCount = 0;
67 size_t trackedCount = 0;
70 for (
auto objects = spaces.value()->begin(); objects != spaces.value()->end(); ++objects) {
71 if (!(*objects)->usesBacking(
identity)) {
75 return ResizeStatus::Unsupported;
79 if (++mappingCount > MaximumMappings ||
80 object->m_Mappings.count() > MaximumTrackedPages - trackedCount) {
81 return ResizeStatus::NoMemory;
83 trackedCount +=
object->m_Mappings.count();
89 return ResizeStatus::NoMemory;
94 return ResizeStatus::NoMemory;
98 if (!data->mappings) {
99 return ResizeStatus::NoMemory;
102 data->newSize = newSize;
107 for (
auto objects = spaces.value()->begin(); objects != spaces.value()->end(); ++objects) {
108 if (!(*objects)->usesBacking(
identity)) {
112 data->mappings.get()[data->mappingCount++] = {spaces.key(),
object};
114 uintptr_t cursor =
object->m_Address;
115 uintptr_t address = 0;
116 physical_uintptr_t tracked = 0;
117 while (object->m_Mappings.lowerBound(cursor, address, tracked)) {
118 if (address == ~uintptr_t(0)) {
119 return ResizeStatus::Invalid;
121 cursor = address + 1;
122 if (tracked != ~
static_cast<physical_uintptr_t
>(0)) {
125 if (address < object->m_Address || address - object->m_Address >= object->m_Length ||
126 address - object->m_Address > ~
size_t(0) - object->m_Offset) {
127 return ResizeStatus::Invalid;
129 const uintptr_t offset = (
object->m_Offset + (address -
object->m_Address)) &
133 const size_t count = loanCounts.
lookup(offset);
134 if (!loanCounts.
tryInsert(offset, count + 1)) {
135 return ResizeStatus::NoMemory;
141 data->loanCount = loanCounts.
count();
142 if (data->loanCount) {
145 return ResizeStatus::NoMemory;
148 for (
auto loan = loanCounts.
begin(); loan != loanCounts.
end(); ++loan) {
149 data->loans.get()[i++] = {loan.key(), loan.value()};
152 result = pedigree_std::move(plan);
153 return ResizeStatus::Ready;