#ifndef _PAGEMAP_H #define _PAGEMAP_H #include "utils.h" #include "list.h" #include "bintree.h" #define PAGE_SHIFT 12 #define PAGE_SIZE (1 << PAGE_SHIFT) struct maps; struct maps_list { struct maps *map; struct list_head list; }; #define list_to_maps_list(list_head) \ container_of((list_head), struct maps_list, list) #define BITRANGE(first, last) (((2ll << (last - first)) - 1) << first) struct pageframe { struct bintree tree; struct maps_list ml; /* List to mappings which point to this pfn */ unsigned long long pf; /* page frame entry from /proc/pid/pagemap */ int refcount; }; #define tree_to_pageframe(tree_struct) \ container_of((tree_struct), struct pageframe, tree) static inline int page_present(struct pageframe *p) { return !!(BITRANGE(63, 63) & p->pf); } static inline int page_swapped(struct pageframe *p) { return !!(BITRANGE(62, 62) & p->pf); } static inline int page_shift(struct pageframe *p) { return (BITRANGE(55, 60) & p->pf) >> 55; } static inline long int pfn(struct pageframe *p) { return (BITRANGE(0, 54) & p->pf); } static inline int swap_type(struct pageframe *p) { return (BITRANGE(0, 4) & p->pf); } static inline int swap_offset(struct pageframe *p) { return (BITRANGE(5, 54) & p->pf) >> 5; } struct maps { struct list_head list; /* Memory segment of a mapping */ unsigned long start; unsigned long end; unsigned long size; long int pages_present; long int pages_swapped; /* Name of the mapping, such as library name or something else */ char name[128]; int pid; /* Process which address space the mapping belongs to */ int tid; /* thread id */ }; #define list_to_maps(list_head) \ container_of((list_head), struct maps, list) struct process { struct maps *maps; struct list_head list; int pid; int tid; char name[256]; long int pages_present; long int pages_swapped; int is_initial_pid; }; #define PARSE_PID 0x1 #define PARSE_MAP_NAME 0x2 #define PARSE_PROCESS_NAME 0x4 #define PARSE_DUMP 0x8 #define PARSE_NOADD_TREE 0x10 struct parse_opts { int parse_mask; int pid; char *name; int with_threads; }; #define is_parse_option(parse_opts, flag) \ (!!((parse_opts)->parse_mask & (flag))) #endif