Last active
April 23, 2020 00:16
-
-
Save PedroHLC/25999abb03a6b4d3ea619a487657c869 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
const linux = @cImport({ | |
@cInclude("linux/kvm.h"); | |
}); | |
const sys = @cImport({ | |
@cInclude("sys/ioctl.h"); | |
@cInclude("sys/stat.h"); | |
@cInclude("fcntl.h"); | |
}); | |
const std = @import("std"); | |
const assert = std.debug.assert; | |
pub fn main() !void { | |
const stdout = std.io.getStdOut().outStream(); | |
try stdout.print("Hello\n", .{}); | |
const kvm = sys.open("/dev/kvm", sys.O_RDWR | sys.O_CLOEXEC); | |
assert(kvm != @as(c_int, -1)); | |
try stdout.print("KVM OK!\n", .{}); | |
const kvmVersion = sys.ioctl(kvm, linux.KVM_GET_API_VERSION, @as(c_int, 0)); | |
assert(kvmVersion == linux.KVM_API_VERSION); | |
try stdout.print("KVM VER OK!\n", .{}); | |
const kvmMaxVCPU = sys.ioctl(kvm, linux.KVM_CHECK_EXTENSION, @as(c_ulong, linux.KVM_CAP_NR_VCPUS)); | |
try stdout.print("Max CPUs: {}\n", .{kvmMaxVCPU}); | |
const vmType: c_int = 0; | |
const vm = sys.ioctl(kvm, linux.KVM_CREATE_VM, vmType); | |
assert(vm > 0); | |
try stdout.print("VM CREATED!\n", .{}); | |
const kvmFirstVCPU = sys.ioctl(vm, linux.KVM_CREATE_VCPU, @as(c_ulong, 0)); | |
assert(kvmFirstVCPU != @as(c_int, -1)); | |
try stdout.print("VCPU CREATED!\n", .{}); | |
try stdout.print("Bye\n", .{}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment