MCPcopy Create free account
hub / github.com/bloomberg/pystack / readChunkThroughMemFile

Method readChunkThroughMemFile

src/pystack/_pystack/mem.cpp:271–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269}
270
271ssize_t
272ProcessMemoryManager::readChunkThroughMemFile(remote_addr_t addr, size_t len, char* dst) const
273{
274 if (!d_memfile) {
275 std::string filepath = "/proc/" + std::to_string(d_pid) + "/mem";
276 d_memfile = file_unique_ptr(fopen(filepath.c_str(), "r"), fclose);
277 if (!d_memfile) {
278 if (errno == EPERM || errno == EACCES) {
279 LOG(ERROR) << "Permission denied opening file " << filepath;
280 throw std::runtime_error(PERM_MESSAGE);
281 }
282 LOG(ERROR) << "Failed to open file " << filepath << ": " << std::strerror(errno);
283 throw std::runtime_error("Failed to open " + filepath);
284 }
285 }
286 fseeko(d_memfile.get(), addr, SEEK_SET);
287 if (static_cast<off_t>(addr) != ftello(d_memfile.get())
288 || len != fread(dst, 1, len, d_memfile.get()))
289 {
290 throw InvalidRemoteAddress();
291 }
292 return static_cast<ssize_t>(len);
293}
294
295ssize_t
296ProcessMemoryManager::copyMemoryFromProcess(remote_addr_t addr, size_t len, void* dst) const

Callers

nothing calls this directly

Calls 2

LOGClass · 0.85

Tested by

no test coverage detected