MCPcopy Create free account
hub / github.com/MJx0/KittyMemoryEx / getAllMaps

Function getAllMaps

KittyMemoryEx/KittyMemoryEx.cpp:168–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166 }
167
168 std::vector<ProcMap> getAllMaps(pid_t pid)
169 {
170 std::vector<ProcMap> retMaps;
171 if (pid <= 0)
172 return retMaps;
173
174 char filePath[256] = {0};
175 snprintf(filePath, sizeof(filePath), "/proc/%d/maps", pid);
176
177 errno = 0;
178 FILE *fp = fopen(filePath, "r");
179 if (!fp)
180 {
181 KITTY_LOGD("Couldn't open maps file %s, error=%s", filePath, strerror(errno));
182 return retMaps;
183 }
184
185 char line[512] = {0};
186 while (fgets(line, sizeof(line), fp))
187 {
188 ProcMap map;
189 map.pid = pid;
190
191 char perms[5] = {0}, dev[11] = {0}, pathname[256] = {0};
192 // parse a line in maps file
193 // (format) startAddress-endAddress perms offset dev inode pathname
194 sscanf(line,
195 "%" SCNxPTR "-%" SCNxPTR " %4s %" SCNxPTR " %s %lu %s",
196 &map.startAddress,
197 &map.endAddress,
198 perms,
199 &map.offset,
200 dev,
201 &map.inode,
202 pathname);
203
204 map.length = map.endAddress - map.startAddress;
205 map.dev = dev;
206 map.pathname = pathname;
207
208 if (perms[0] == 'r')
209 {
210 map.protection |= PROT_READ;
211 map.readable = true;
212 }
213 if (perms[1] == 'w')
214 {
215 map.protection |= PROT_WRITE;
216 map.writeable = true;
217 }
218 if (perms[2] == 'x')
219 {
220 map.protection |= PROT_EXEC;
221 map.executable = true;
222 }
223
224 map.is_private = (perms[3] == 'p');
225 map.is_shared = (perms[3] == 's');

Callers 10

ElfScannerMethod · 0.85
somainInfoMethod · 0.85
sonextInfoMethod · 0.85
soheadInfoMethod · 0.85
getMapsFunction · 0.85
getAddressMapFunction · 0.85
KittyScanner.cppFile · 0.85
getAllELFsMethod · 0.85
initMethod · 0.85
allSoInfoMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected