Internal implementation helper for LookUpMapping(address). Takes as input an `address` and a known vector `mappings`, assumed to be sorted by increasing addresses, as /proc/self/maps seems to be. Returns a pointer to the MappingInfo describing the mapping that this address belongs to, or nullptr if the address isn't in `mappings`.
| 207 | // Returns a pointer to the MappingInfo describing the mapping that this |
| 208 | // address belongs to, or nullptr if the address isn't in `mappings`. |
| 209 | static MappingInfo* LookUpMapping(std::vector<MappingInfo>& mappings, uintptr_t address) |
| 210 | { |
| 211 | // Comparison function for std::lower_bound. Returns true if all addresses in `m1` |
| 212 | // are lower than `addr`. |
| 213 | auto Compare = []( const MappingInfo& m1, uintptr_t addr ) { |
| 214 | // '<=' because the address ranges are half-open intervals, [start, end). |
| 215 | return m1.end_address <= addr; |
| 216 | }; |
| 217 | auto iter = std::lower_bound( mappings.begin(), mappings.end(), address, Compare ); |
| 218 | if( iter == mappings.end() || iter->start_address > address) { |
| 219 | return nullptr; |
| 220 | } |
| 221 | return &*iter; |
| 222 | } |
| 223 | |
| 224 | // Internal implementation helper for EnsureReadable(address). |
| 225 | // |
no test coverage detected