Nothing Special   »   [go: up one dir, main page]

Skip to content

a lightweight library to parse Linux's /proc/[pid]/maps file, which contains the memory map of a process

License

Notifications You must be signed in to change notification settings

Straho-Chen/proc_maps_parser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

proc_maps_parser

a lightweight library to parse Linux's /proc/[pid]/maps file, which contains the memory map of a process

/proc/[pid]/maps

A file containing the currently mapped memory regions and their access permissions. See mmap(2) for some further information about memory mappings. #memory map region proc_maps_parser represents a memory region with this C structure.

struct procmaps_struct{
	void* addr_start; 	//< start address of the region
	void* addr_end; 	//< end address of the region
	unsigned long length; //<  length of the region by bytes

	char perm[5];		//< permissions rwxp 
	short is_r;			//< is readible
	short is_w;			//< is writable	
	short is_x;			//< is executable
	short is_p;			//< is private

	long offset;	//< offset
	
	char dev[12];	//< the device that backs the region, format major:minor
	int inode;	//< inode of the file that backs the area
	char pathname[600];//< the path of the file that backs the area
	
	//The next region in the list
	struct procmaps_struct* next;		//<handler of the chinaed list
}

Building

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.

Usage

from ./examples/map.c

  int pid=-1; //-1 to use the running process id, use pid>0 to list the map of another process
  procmaps_iterator* maps = pmparser_parse(pid);
	if(maps==NULL){
		printf ("[map]: cannot parse the memory map of %d\n",pid);
		return -1;
	}

	//iterate over areas
	procmaps_struct* maps_tmp=NULL;
	
	while( (maps_tmp = pmparser_next(maps)) != NULL){
		pmparser_print(maps_tmp,0);
		printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~\n"); 
	}

	//mandatory: should free the list
	pmparser_free(maps);

About

a lightweight library to parse Linux's /proc/[pid]/maps file, which contains the memory map of a process

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 95.9%
  • Makefile 4.1%