37 #define _LARGEFILE64_SOURCE
44 #define BIT(i) ((unsigned long long) 1 << i)
45 #define FILENAME_SIZE 30
47 #define PAGE_SIZE (1<<PAGE_SHIFT)
48 #define PAGE_MASK (((unsigned long long)1<< PAGE_SHIFT) -1)
50 #define PAGE_PRESENT BIT(63)
51 #define PAGE_SWAPPED BIT(62)
52 #define PAGE_PFN_MASK (((unsigned long long)1<< 55) -1)
63 if (snprintf(filename,
FILENAME_SIZE,
"/proc/%d/pagemap", pid) < 0) {
64 fprintf(stderr,
"Cant create file name\n");
68 return open(filename, O_RDONLY);
78 static int virt2phys(
int fd,
unsigned long vaddr,
unsigned long *paddr)
80 unsigned long long pm_info, index;
82 index = (vaddr >>
PAGE_SHIFT) *
sizeof(
unsigned long long);
84 if ((off64_t)index != lseek64(fd, index, SEEK_SET)) {
89 if (
sizeof(
unsigned long long) != read(fd, &pm_info,
sizeof(
unsigned long long))) {
114 unsigned long vcurrent, pcurrent = 0, pnext;
137 if (size && (pmem->
size >= size)) {
142 if (
virt2phys(fd, vcurrent, &pcurrent)) {
147 if (pcurrent == pnext) {
int check_contiguity(unsigned long vaddr, pid_t pid, struct physmem *pmem, size_t size)
static int virt2phys(int fd, unsigned long vaddr, unsigned long *paddr)
static int open_pagemap(pid_t pid)