ErrorCode Process::getMemoryRegionInfo(Address const &address, MemoryRegionInfo &info) { if (!address.valid()) return kErrorInvalidArgument; info.clear(); return kErrorNotFound; }
ErrorCode Process::getMemoryRegionInfo(Address const &address, MemoryRegionInfo &info) { if (!address.valid()) return kErrorInvalidArgument; info.clear(); FILE *fp = ProcFS::OpenFILE(_pid, "maps"); if (fp == nullptr) { return Platform::TranslateError(); } uint64_t last = 0; bool found = false; while (!found) { // Each line can contain one path and some additional addresses and // such, so PATH_MAX * 2 should be enough. char buf[PATH_MAX * 2]; uint64_t start, end; char r, w, x, p; uint64_t offset; unsigned int devMinor, devMajor; uint64_t inode; int nread; if (std::fgets(buf, sizeof(buf), fp) == nullptr) break; if (std::sscanf(buf, "%" PRIx64 "-%" PRIx64 " %c%c%c%c %" PRIx64 " %x:%x %" PRIu64 " %n", &start, &end, &r, &w, &x, &p, &offset, &devMinor, &devMajor, &inode, &nread) != 10) { continue; } if (address >= last && address <= start) { // // A hole. // info.start = last; info.length = start - last; found = true; } else if (address >= start && address < end) { // // A defined region. // info.start = start; info.length = end - start; info.protection = 0; if (r == 'r') info.protection |= ds2::kProtectionRead; if (w == 'w') info.protection |= ds2::kProtectionWrite; if (x == 'x') info.protection |= ds2::kProtectionExecute; while (buf[nread] != '\0' && std::isspace(buf[nread])) ++nread; info.backingFile = buf + nread; info.backingFileOffset = offset; info.backingFileInode = inode; found = true; } else { last = end; } } std::fclose(fp); if (!found) { info.start = last; // // We need to obtain the end of the address space, first // we need to know if it's 64-bit. // ErrorCode error = updateInfo(); if (error != kSuccess && error != kErrorAlreadyExist) return error; if (CPUTypeIs64Bit(_info.cpuType)) { info.length = std::numeric_limits<uint64_t>::max() - info.start; } else { info.length = std::numeric_limits<uint32_t>::max() - info.start; } } return kSuccess; }