| 67 | } |
| 68 | |
| 69 | void KittyPtrValidator::refreshRegionCache() |
| 70 | { |
| 71 | cachedRegions_.clear(); |
| 72 | vm_address_t address = 0; |
| 73 | |
| 74 | while (true) |
| 75 | { |
| 76 | vm_size_t size = 0; |
| 77 | natural_t nesting_depth = 0; |
| 78 | vm_region_submap_short_info_data_64_t info{}; |
| 79 | mach_msg_type_number_t info_count = VM_REGION_SUBMAP_SHORT_INFO_COUNT_64; |
| 80 | kern_return_t kret = vm_region_recurse_64(task_, |
| 81 | &address, |
| 82 | &size, |
| 83 | &nesting_depth, |
| 84 | (vm_region_recurse_info_t)&info, |
| 85 | &info_count); |
| 86 | if (kret != KERN_SUCCESS) |
| 87 | break; |
| 88 | |
| 89 | bool readable = (info.protection & VM_PROT_READ) != 0; |
| 90 | bool writable = (info.protection & VM_PROT_WRITE) != 0; |
| 91 | bool executable = (info.protection & VM_PROT_EXECUTE) != 0; |
| 92 | RegionInfo new_region(address, address + size, readable, writable, executable); |
| 93 | |
| 94 | if (!cachedRegions_.empty() && cachedRegions_.back().canMergeWith(new_region)) |
| 95 | { |
| 96 | cachedRegions_.back().end = new_region.end; |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | cachedRegions_.emplace_back(new_region); |
| 101 | } |
| 102 | |
| 103 | address += size; |
| 104 | } |
| 105 | |
| 106 | if (!cachedRegions_.empty()) |
| 107 | { |
| 108 | std::sort(cachedRegions_.begin(), cachedRegions_.end(), [](const RegionInfo &a, const RegionInfo &b) { |
| 109 | return a.start < b.start; |
| 110 | }); |
| 111 | } |
| 112 | |
| 113 | last_region_index_ = 0; |
| 114 | } |
| 115 | |
| 116 | #else |
| 117 |
nothing calls this directly
no test coverage detected