| 198 | } |
| 199 | |
| 200 | OSAllocator_64Bit::LiveVMARegion* OSAllocator_64Bit::FindLiveRegionForAddress(uintptr_t Addr, uintptr_t AddrEnd) { |
| 201 | LiveVMARegion* LiveRegion {}; |
| 202 | |
| 203 | // Check active slabs to see if we can fit this |
| 204 | for (auto it = LiveRegions->begin(); it != LiveRegions->end(); ++it) { |
| 205 | uintptr_t RegionBegin = (*it)->SlabInfo->Base; |
| 206 | uintptr_t RegionEnd = RegionBegin + (*it)->SlabInfo->RegionSize; |
| 207 | |
| 208 | if (Addr >= RegionBegin && Addr < RegionEnd) { |
| 209 | LiveRegion = *it; |
| 210 | // Leave our loop |
| 211 | break; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | // Couldn't find an active region that fit |
| 216 | // Check reserved regions |
| 217 | if (!LiveRegion) { |
| 218 | // Didn't have a slab that fit this range |
| 219 | // Check our reserved regions to see if we have one that fits |
| 220 | for (auto it = ReservedRegions->begin(); it != ReservedRegions->end(); ++it) { |
| 221 | ReservedVMARegion* ReservedRegion = *it; |
| 222 | uintptr_t RegionEnd = ReservedRegion->Base + ReservedRegion->RegionSize; |
| 223 | if (Addr >= ReservedRegion->Base && AddrEnd < RegionEnd) { |
| 224 | // Found one, let's make it active |
| 225 | LiveRegion = MakeRegionActive(it, 0); |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | return LiveRegion; |
| 232 | } |
| 233 | |
| 234 | void* OSAllocator_64Bit::Mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) { |
| 235 | if (addr != 0 && addr < reinterpret_cast<void*>(LOWER_BOUND)) { |