0

I need to read a /proc/{pid}/pagemaps file and get the page frame number and if is present in RAM.

The docs say that bits 0-54 are the page frame number and bit 63 is set if is present in RAM.

54-0
If the page is present in RAM (bit 63), then these bits provide the page frame number, which can be used to index /proc/kpageflags and /proc/kpagecount. If the page is present in swap (bit 62), then bits 4–0 give the swap type, and bits 54–5 encode the swap offset.

I tried a basic shift-left operation:

with open(pagemap_file, "rb") as pmf:
    offset = (address / page_size) * 8
    pmf.seek(int(offset), 0)
    try:
        content = pmf.read(8)
        pfn = (content >> 6) & 3
    except Exception as e:
        print(e)
        pfn = None

And I got: unsupported operand type(s) for >>: 'bytes' and 'int'

Also:

pfn = (pmf.read(8) >> (6).to_bytes(1, byteorder='big')) & (3).to_bytes(1, byteorder='big')

But I got the same error.

How can I do this?

pmf.read(8)b'\x00\x00\x00\x00\x00\x00\x80\xa1'

martineau
  • 119,623
  • 25
  • 170
  • 301
Daniela Morais
  • 2,125
  • 7
  • 28
  • 49

0 Answers0