pagemap: was missing one bit in lkmc_pagemap_get_entry for pfn

Credits to Phidelux:
https://stackoverflow.com/questions/6284810/proc-pid-pagemaps-and-proc-pid-maps-linux/45500208?noredirect=1#comment109030479_45500208
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2020-05-09 01:00:00 +00:00
parent 12ed05f893
commit 6275f70ed8
2 changed files with 8 additions and 5 deletions

View File

@@ -12,7 +12,7 @@
* https://github.com/torvalds/linux/blob/v4.9/Documentation/vm/pagemap.txt
*/
typedef struct {
uint64_t pfn : 54;
uint64_t pfn : 55;
unsigned int soft_dirty : 1;
unsigned int file_page : 1;
unsigned int swapped : 1;
@@ -46,8 +46,8 @@ int lkmc_pagemap_get_entry(LkmcPagemapEntry *entry, int pagemap_fd, uintptr_t va
return 1;
}
}
entry->pfn = data & (((uint64_t)1 << 54) - 1);
entry->soft_dirty = (data >> 54) & 1;
entry->pfn = data & (((uint64_t)1 << 55) - 1);
entry->soft_dirty = (data >> 55) & 1;
entry->file_page = (data >> 61) & 1;
entry->swapped = (data >> 62) & 1;
entry->present = (data >> 63) & 1;

View File

@@ -1,6 +1,7 @@
/* https://cirosantilli.com/linux-kernel-module-cheat#pagemap-dump-out */
#define _XOPEN_SOURCE 700
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
@@ -91,8 +92,10 @@ int main(int argc, char **argv) {
{
LkmcPagemapEntry entry;
for (uintptr_t vaddr = low; vaddr < high; vaddr += sysconf(_SC_PAGE_SIZE)) {
/* TODO always fails for the last page (vsyscall), why? pread returns 0. */
if (!lkmc_pagemap_get_entry(&entry, pagemap_fd, vaddr)) {
if (lkmc_pagemap_get_entry(&entry, pagemap_fd, vaddr)) {
/* TODO always fails for the last page (vsyscall), why? pread returns 0. */
/*assert(0);*/
} else {
printf(
"%jx %jx %u %u %u %u %s\n",
(uintmax_t)vaddr,