]> git.itanic.dy.fi Git - scan-pagemap/blob - pagemap.h
c2f712d6bd5167ae4030a07d10d959b126b752a9
[scan-pagemap] / pagemap.h
1 #ifndef _PAGEMAP_H
2 #define _PAGEMAP_H
3
4 #include "utils.h"
5 #include "list.h"
6 #include "bintree.h"
7
8 #define PAGE_SHIFT      12
9 #define PAGE_SIZE       (1 << PAGE_SHIFT)
10
11 struct maps;
12
13 struct maps_list {
14         struct maps *map;
15         struct list_head list;
16 };
17 #define list_to_maps_list(list_head)                            \
18         container_of((list_head), struct maps_list, list)
19
20 #define BITRANGE(first, last) (((2ll << (last - first)) - 1) << first)
21
22 struct pageframe {
23         struct bintree tree;
24         struct list_head ml;    /* List of mappings which refer to this pfn */
25
26         unsigned long long pf;  /* page frame entry from /proc/pid/pagemap */
27
28         int refcount;
29 };
30
31 #define tree_to_pageframe(tree_struct)                          \
32         container_of((tree_struct), struct pageframe, tree)
33
34 static inline int page_present(struct pageframe *p)
35 {
36         return !!(BITRANGE(63, 63) & p->pf);
37 }
38
39 static inline int page_swapped(struct pageframe *p)
40 {
41         return !!(BITRANGE(62, 62) & p->pf);
42 }
43
44 static inline int page_shift(struct pageframe *p)
45 {
46         return (BITRANGE(55, 60) & p->pf) >> 55;
47 }
48
49 static inline long int pfn(struct pageframe *p)
50 {
51         return (BITRANGE(0, 54) & p->pf);
52 }
53
54 static inline int swap_type(struct pageframe *p)
55 {
56         return (BITRANGE(0, 4) & p->pf);
57 }
58
59 static inline int swap_offset(struct pageframe *p)
60 {
61         return (BITRANGE(5, 54) & p->pf) >> 5;
62 }
63
64 struct maps {
65         struct list_head list;
66
67         /* Memory segment of a mapping */
68         unsigned long start;
69         unsigned long end;
70         unsigned long size;
71
72         long int pages_present;
73         long int pages_swapped;
74
75         /* Name of the mapping, such as library name or something else */
76         char name[128];
77         int pid; /* Process which address space the mapping belongs to */
78         int tid; /* thread id */
79 };
80
81 #define list_to_maps(list_head)                         \
82         container_of((list_head), struct maps, list)
83
84 struct process {
85         struct maps *maps;
86         struct list_head list;
87         int pid;
88         int tid;
89         char name[256];
90
91         long int pages_present;
92         long int pages_swapped;
93
94         int is_initial_pid;
95 };
96
97 #define PARSE_PID               0x1
98 #define PARSE_MAP_NAME          0x2
99 #define PARSE_PROCESS_NAME      0x4
100 #define PARSE_DUMP              0x8
101 #define PARSE_NOADD_TREE        0x10
102
103 struct pidlist {
104         struct list_head list;
105
106         int pid;
107 };
108
109 struct parse_opts {
110         struct list_head pidlist;
111
112         int parse_mask;
113         char *name;
114         int with_threads;
115 };
116
117 static inline void init_parse_opts(struct parse_opts *p)
118 {
119         memset(p, 0, sizeof(*p));
120         INIT_LIST_HEAD(&p->pidlist);
121 }
122
123 static inline struct pidlist *alloc_pidlist(void)
124 {
125         struct pidlist *p = malloc(sizeof(*p));
126
127         if (p == NULL)
128                 return p;
129
130         memset(p, 0, sizeof(*p));
131         INIT_LIST_HEAD(&p->list);
132
133         return p;
134 }
135
136 #define is_parse_option(parse_opts, flag) \
137         (!!((parse_opts)->parse_mask & (flag)))
138
139 #endif