Check for KVM_CAP_USER_MEMORY

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
This commit is contained in:
Pekka Enberg
2015-06-01 16:39:38 +01:00
committed by Will Deacon
parent 9b1fb1c3dc
commit 2da26a59d3
+15
View File
@@ -1,6 +1,7 @@
#include "kvm/cpu.h"
#include <linux/kvm.h>
#include <stdbool.h>
#include <stdlib.h>
#include <fcntl.h>
@@ -9,6 +10,17 @@ struct kvm {
int vmfd;
};
static inline bool kvm__supports_extension(struct kvm *self, unsigned int extension)
{
int ret;
ret = ioctl(self->fd, KVM_CHECK_EXTENSION, extension);
if (ret < 0)
return false;
return ret;
}
static void die(const char *s)
{
perror(s);
@@ -44,6 +56,9 @@ int main(int argc, char *argv[])
if (kvm.vmfd < 0)
die("open");
if (!kvm__supports_extension(&kvm, KVM_CAP_USER_MEMORY))
die("KVM_CAP_USER_MEMORY");
cpu = cpu__new();
cpu__reset(cpu);