Skip to content

Instantly share code, notes, and snippets.

@corruptmem
Created February 8, 2011 22:38
Show Gist options
  • Save corruptmem/817434 to your computer and use it in GitHub Desktop.
Save corruptmem/817434 to your computer and use it in GitHub Desktop.
kvm
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/kvm.h>
#include <errno.h>
#include <string.h>
int main(int argc, char* argv[])
{
int kvm = open("/dev/kvm", O_RDWR);
int vm = ioctl(kvm, KVM_CREATE_VM, 0);
perror("CREATE_VM");
struct kvm_userspace_memory_region mem;
mem.slot = 0;
mem.guest_phys_addr = 0x0;
mem.memory_size = 1024;
mem.userspace_addr = (long) malloc(1024);
ioctl(vm, KVM_SET_USER_MEMORY_REGION, mem);
perror("SET_USER_MEMORY_REGION");
ioctl(vm, KVM_CREATE_VCPU, 0);
perror("CREATE_VCPU");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment