Created
October 5, 2022 22:54
-
-
Save jarkkojs/5f333b08a22b59ff52c8b28b27053dd6 to your computer and use it in GitHub Desktop.
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
#define _GNU_SOURCE | |
#include <fcntl.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <linux/kvm.h> | |
#include <sys/ioctl.h> | |
#define KVM_CAP_UNMAPPED_PRIVATE_MEM 240 | |
int main(void) | |
{ | |
int exit_code = 1; | |
int ret; | |
int kvm; | |
int vm; | |
kvm = open("/dev/kvm", O_RDWR | O_CLOEXEC); | |
if (kvm == -1) { | |
perror("open"); | |
goto err; | |
} | |
ret = ioctl(kvm, KVM_GET_API_VERSION, NULL); | |
if (ret == -1) { | |
perror("ioctl"); | |
goto err_kvm; | |
} | |
if (ret != 12) { | |
fprintf(stderr, "Expected KVM API 12 != %d", ret); | |
goto err_kvm; | |
} | |
vm = ioctl(kvm, KVM_CREATE_VM, 0UL); | |
if (vm == -1) { | |
perror("ioctl"); | |
goto err_kvm; | |
} | |
ret = ioctl(vm, KVM_CHECK_EXTENSION, KVM_CAP_UNMAPPED_PRIVATE_MEM); | |
if (ret == -1) { | |
perror("ioctl"); | |
goto err_vm; | |
} | |
printf("%d\n", ret); | |
exit_code = 0; | |
err_vm: | |
close(vm); | |
err_kvm: | |
close(kvm); | |
err: | |
exit(exit_code); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment