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