a lightweight library to parse Linux's /proc/[pid]/maps file, which contains the memory map of a process
A file containing the currently mapped memory regions and their access permissions.
proc_maps_parser represents a memory region with this C structure.
typedefstructprocmaps_struct
{
void*addr_start; //< start address of the areavoid*addr_end; //< end addresssize_tlength; //< size of the rangeshortis_r;
shortis_w;
shortis_x;
shortis_p;
size_toffset; //< offsetunsigned intdev_major;
unsigned intdev_minor;
unsigned long longinode; //< inode of the file that backs the areachar*pathname; //< the path of the file that backs the area ( dynamically allocated)procmaps_map_typemap_type;
charmap_anon_name[MAPPING_ANON_NAME_MAX_LEN+1]; //< name of the anonymous mappingshortfile_deleted; //< whether the file backing the mapping was deleted// chained liststructprocmaps_struct*next;
} procmaps_struct;After cloning, building this project is possible as follows:
$ cd [proc_maps_parser checkout]
$ make # to build it as a static library
$ make examples # to build both the static library and the example program
Optionally, the BUILD_DIR environment variable can be specified when running make to build the static library somewhere else. By default, this is set to a build/ directory in the root of the source tree.
from ./examples/map.c
intpid=512; // Change this to the target PIDprocmaps_iteratormaps= {0};
procmaps_error_tparser_err=PROCMAPS_SUCCESS;
parser_err=pmparser_parse(pid, &maps_iter);
if (parser_err)
{
printf("[proc_maps_parser]: failure to parse the memory map of process %d (error=%d)\n", pid, (int)parser_err);
return-1;
}
// iterate over areasprocmaps_struct*mem_region=NULL;
while ((mem_region=pmparser_next(&maps_iter)) !=NULL)
{
pmparser_print(mem_region);
}
// mandatory: should free the listpmparser_free(&maps_iter);