Created
August 25, 2017 15:06
-
-
Save tklengyel/a0615c69aa6e377efc28a7f63c34a47a to your computer and use it in GitHub Desktop.
Xen foreign memory mapping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* gcc -o xen_memmap -lxenctrl xen_memmap.c | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/mman.h> | |
#define XC_WANT_COMPAT_MAP_FOREIGN_API 1 | |
#include <xenctrl.h> | |
int main(int argc, char **argv) { | |
xc_interface *xc = xc_interface_open(0, 0, 0); | |
if (!xc) { | |
fprintf(stderr, "xc_interface_open() failed!\n"); | |
return 0; | |
} | |
unsigned long pfn = strtoul(argv[1], NULL, 0); | |
domid_t domainid = 1; | |
void *memory = xc_map_foreign_range(xc, domainid, XC_PAGE_SIZE, PROT_READ, (unsigned long) pfn); | |
if ( memory ) { | |
/* Page is now mapped */ | |
munmap(memory, XC_PAGE_SIZE); | |
} | |
xc_interface_close(xc); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment