-
Notifications
You must be signed in to change notification settings - Fork 6
Home
Lilian VERLHAC edited this page Apr 19, 2020
·
5 revisions
hr_procmaps **contruct_procmaps(int pid);Parse /proc/<PID>/maps to create an object hr_procmaps containing information on the maps of the process PID.
The pid argument is the PID of the process to get the maps of. If it is set to 0 or a negative value, the function will parse /proc/self/maps instead, fetching information about itself.
Return value: malloc()'d hr_procmaps ** on success, NULL on error and errno is set.
void destroy_procmaps(hr_procmaps **procmaps);Destroy the hr_procmaps object freeing the allocated memory.
Example:
#include <stdio.h>
#include <procmaps.h>
int main(void)
{
hr_procmaps **procmaps = construct_procmaps(0);
printf("0x%0llx", procmaps[0]->addr_begin);
destroy_procmaps(procmaps);
return 0;
}procmaps_row_t:
typedef struct dev_major_minor_s dev_major_minor_t;
struct dev_major_minor_s {
int major;
int minor;
};
typedef struct procmaps_row_s procmaps_row_t;
struct procmaps_row_s {
unsigned long long addr_begin;
unsigned long long addr_end;
unsigned char perms;
unsigned long long offset;
dev_major_minor_t dev;
int inode;
char *pathname;
};
typedef procmaps_row_t hr_procmaps;Represents map information.
$> head -n 1 /proc/PID/maps
00400000-00452000 r-xp 00000000 08:02 173521 /usr/bin/dbus-daemon
| /proc/PID/maps | struct member | |
|---|---|---|
| Address beginning | 00400000 | addr_begin |
| Address end | 00452000 | addr_end |
| Permissions | r-xp | perms |
| Offset | 00000000 | offset |
| Dev | 08:02 | dev |
| Inode | 173521 | inode |
| Path / Name | /usr/bin/dbus-daemon | pathname |
MAPS_PERMS:
enum MAPS_PERMS {
PERMS_READ = 1 << 0,
PERMS_WRITE = 1 << 1,
PERMS_EXECUTE = 1 << 2,
PERMS_PRIVATE = 1 << 3,
PERMS_SHARED = 1 << 4
};The perms member of procmaps_row_t is a bitset composed of the MAPS_PERMS enum values.
Exemple:
| Permissions | perms |
|---|---|
| r-xp | 00001101 |