Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
virt2phys.c File Reference
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "virt2phys.h"
+ Include dependency graph for virt2phys.c:

Go to the source code of this file.


#define BIT(i)   ((unsigned long long) 1 << i)
#define FILENAME_SIZE   30
#define PAGE_SHIFT   12
#define PAGE_SIZE   (1<<PAGE_SHIFT)
#define PAGE_MASK   (((unsigned long long)1<< PAGE_SHIFT) -1)
#define PAGE_PRESENT   BIT(63)
#define PAGE_SWAPPED   BIT(62)
#define PAGE_PFN_MASK   (((unsigned long long)1<< 55) -1)


static int open_pagemap (pid_t pid)
static int virt2phys (int fd, unsigned long vaddr, unsigned long *paddr)
int check_contiguity (unsigned long vaddr, pid_t pid, struct physmem *pmem, size_t size)

Detailed Description

Mapping of virtual to physical memory

Source : See the linux kernel documentation at ->

The file /proc/pid/pagemap contains 8 bytes for each virtual PFN describing the page status. First we check the bits indicating if page is present and not swapped. Then we can get the physical PFN.

Contiguity check consist to verify of contiguous virtual memory correspond to present, not swapped and contiguous physical pages.

Definition in file virt2phys.c.

Macro Definition Documentation



Definition at line 37 of file virt2phys.c.


#define BIT (   i)    ((unsigned long long) 1 << i)

Definition at line 44 of file virt2phys.c.


#define FILENAME_SIZE   30

Definition at line 45 of file virt2phys.c.


#define PAGE_MASK   (((unsigned long long)1<< PAGE_SHIFT) -1)

Definition at line 48 of file virt2phys.c.


#define PAGE_PFN_MASK   (((unsigned long long)1<< 55) -1)

Definition at line 52 of file virt2phys.c.


#define PAGE_PRESENT   BIT(63)

Definition at line 50 of file virt2phys.c.


#define PAGE_SHIFT   12

Definition at line 46 of file virt2phys.c.


#define PAGE_SIZE   (1<<PAGE_SHIFT)

Definition at line 47 of file virt2phys.c.


#define PAGE_SWAPPED   BIT(62)

Definition at line 51 of file virt2phys.c.

Function Documentation

◆ check_contiguity()

int check_contiguity ( unsigned long  vaddr,
pid_t  pid,
struct physmem pmem,
size_t  size 

Definition at line 111 of file virt2phys.c.

References fd, open_pagemap(), physmem::paddr, PAGE_MASK, PAGE_SIZE, physmem::size, and virt2phys().

Referenced by v4l2_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ open_pagemap()

static int open_pagemap ( pid_t  pid)

Definition at line 59 of file virt2phys.c.


Referenced by check_contiguity().

+ Here is the caller graph for this function:

◆ virt2phys()

static int virt2phys ( int  fd,
unsigned long  vaddr,
unsigned long *  paddr 

Definition at line 78 of file virt2phys.c.


Referenced by check_contiguity().

+ Here is the caller graph for this function: