]> git.itanic.dy.fi Git - scan-pagemap/blob - pagemap.h
parser: Remove unaccessible pids from the pidlist
[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
30         int refcount;
31 };
32
33 #define tree_to_pageframe(tree_struct)                          \
34         container_of((tree_struct), struct pageframe, tree)
35
36 static inline void clear_pageframe(struct pageframe *pf)
37 {
38         memset(pf, 0, sizeof(*pf));
39         INIT_LIST_HEAD(&pf->ml);
40 }
41
42 static inline int page_present(struct pageframe *p)
43 {
44         return !!(BITRANGE(63, 63) & p->pf);
45 }
46
47 static inline int page_swapped(struct pageframe *p)
48 {
49         return !!(BITRANGE(62, 62) & p->pf);
50 }
51
52 static inline int page_shift(struct pageframe *p)
53 {
54         return (BITRANGE(55, 60) & p->pf) >> 55;
55 }
56
57 static inline long int pfn(struct pageframe *p)
58 {
59         return (BITRANGE(0, 54) & p->pf);
60 }
61
62 static inline int swap_type(struct pageframe *p)
63 {
64         return (BITRANGE(0, 4) & p->pf);
65 }
66
67 static inline int swap_offset(struct pageframe *p)
68 {
69         return (BITRANGE(5, 54) & p->pf) >> 5;
70 }
71
72 struct maps {
73         struct list_head list;
74
75         /* Memory segment of a mapping */
76         unsigned long start;
77         unsigned long end;
78         unsigned long size;
79
80         long int pages_present;
81         long int pages_swapped;
82
83         /* Name of the mapping, such as library name or something else */
84         char name[128];
85         int pid; /* Process which address space the mapping belongs to */
86         int tid; /* thread id */
87 };
88
89 #define list_to_maps(list_head)                         \
90         container_of((list_head), struct maps, list)
91
92 struct process {
93         struct maps *maps;
94         struct list_head list;
95         int pid;
96         int tid;
97         char name[256];
98
99         long int pages_present;
100         long int pages_swapped;
101
102         int is_initial_pid;
103 };
104
105 #define PARSE_PID               0x1
106 #define PARSE_MAP_NAME          0x2
107 #define PARSE_DUMP              0x8
108 #define PARSE_NOADD_TREE        0x10
109 #define PARSE_SHARED_MAPPING    0x20
110
111 struct pidlist {
112         struct list_head list;
113
114         int pid;
115 };
116
117 struct parse_opts {
118         struct list_head pidlist;
119
120         int parse_mask;
121         char *name;
122         int with_threads;
123 };
124
125 static inline void init_parse_opts(struct parse_opts *p)
126 {
127         memset(p, 0, sizeof(*p));
128         INIT_LIST_HEAD(&p->pidlist);
129 }
130
131 static inline struct pidlist *alloc_pidlist(void)
132 {
133         struct pidlist *p = malloc(sizeof(*p));
134
135         if (p == NULL)
136                 return p;
137
138         memset(p, 0, sizeof(*p));
139         INIT_LIST_HEAD(&p->list);
140
141         return p;
142 }
143
144 #define is_parse_option(parse_opts, flag) \
145         (!!((parse_opts)->parse_mask & (flag)))
146
147 #endif