| 344 | } |
| 345 | |
| 346 | ProcMap getAddressMap(pid_t pid, uintptr_t address, const std::vector<ProcMap> &maps) |
| 347 | { |
| 348 | if (!address) |
| 349 | return {}; |
| 350 | |
| 351 | address = KittyUtils::untagHeepPtr(address); |
| 352 | |
| 353 | if (!maps.empty()) |
| 354 | { |
| 355 | auto it = std::lower_bound(maps.begin(), maps.end(), address, [](const ProcMap &m, uintptr_t val) { |
| 356 | return m.endAddress <= val; |
| 357 | }); |
| 358 | |
| 359 | if (it != maps.end() && address >= it->startAddress && address < it->endAddress) |
| 360 | { |
| 361 | return *it; |
| 362 | } |
| 363 | } |
| 364 | else |
| 365 | { |
| 366 | auto pmaps = getAllMaps(pid); |
| 367 | auto it = std::lower_bound(pmaps.begin(), pmaps.end(), address, [](const ProcMap &m, uintptr_t val) { |
| 368 | return m.endAddress <= val; |
| 369 | }); |
| 370 | |
| 371 | if (it != pmaps.end() && address >= it->startAddress && address < it->endAddress) |
| 372 | { |
| 373 | return *it; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | return {}; |
| 378 | } |
| 379 | |
| 380 | #ifdef __ANDROID__ |
| 381 | std::string getAppDirectory(const std::string &pkg) |
no test coverage detected