1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
use libc::*;
pub type hv_return_t = u32;
pub const HV_SUCCESS: hv_return_t = 0;
pub const HV_ERROR: hv_return_t = 0xfae94001;
pub const HV_BUSY: hv_return_t = 0xfae94002;
pub const HV_BAD_ARGUMENT: hv_return_t = 0xfae94003;
pub const HV_NO_RESOURCES: hv_return_t = 0xfae94005;
pub const HV_NO_DEVICE: hv_return_t = 0xfae94006;
pub const HV_UNSUPPORTED: hv_return_t = 0xfae9400f;
pub type hv_vm_options_t = u64;
pub const HV_VM_DEFAULT: hv_vm_options_t = 0 << 0;
extern "C" {
pub fn hv_vm_create(flags: hv_vm_options_t) -> hv_return_t;
pub fn hv_vm_destroy() -> hv_return_t;
}
pub type hv_vcpuid_t = c_uint;
pub const HV_VCPU_DEFAULT: u64 = 0;
extern "C" {
pub fn hv_vcpu_create(vcpu: *mut hv_vcpuid_t, flags: hv_vm_options_t) -> hv_return_t;
pub fn hv_vcpu_run(vcpu: hv_vcpuid_t) -> hv_return_t;
pub fn hv_vcpu_interrupt(vcpu: *const hv_vcpuid_t, vcpu_count: c_uint) -> hv_return_t;
pub fn hv_vcpu_get_exec_time(vcpu: hv_vcpuid_t, time: *mut u64) -> hv_return_t;
pub fn hv_vcpu_flush(vcpu: hv_vcpuid_t) -> hv_return_t;
pub fn hv_vcpu_invalidate_tlb(vcpu: hv_vcpuid_t) -> hv_return_t;
pub fn hv_vcpu_destroy(vcpu: hv_vcpuid_t) -> hv_return_t;
}
extern "C" {
pub fn hv_vcpu_read_register(
vcpu: hv_vcpuid_t,
reg: super::Register,
value: *mut u64,
) -> hv_return_t;
pub fn hv_vcpu_write_register(
vcpu: hv_vcpuid_t,
reg: super::Register,
value: u64,
) -> hv_return_t;
}
extern "C" {
pub fn hv_vcpu_read_fpstate(
vcpu: hv_vcpuid_t,
buffer: *mut c_void,
size: size_t,
) -> hv_return_t;
pub fn hv_vcpu_write_fpstate(
vcpu: hv_vcpuid_t,
buffer: *const c_void,
size: size_t,
) -> hv_return_t;
}
extern "C" {
pub fn hv_vcpu_enable_native_msr(vcpu: hv_vcpuid_t, msr: u32, enable: bool) -> hv_return_t;
pub fn hv_vcpu_read_msr(vcpu: hv_vcpuid_t, msr: u32, value: *mut u64) -> hv_return_t;
pub fn hv_vcpu_write_msr(vcpu: hv_vcpuid_t, msr: u32, value: *const u64) -> hv_return_t;
}
extern "C" {
pub fn hv_vm_sync_tsc(tsc: u64) -> hv_return_t;
}
pub type hv_uvaddr_t = *const c_void;
pub type hv_memory_flags_t = u64;
pub type hv_gpaddr_t = u64;
pub const HV_MEMORY_READ: hv_memory_flags_t = 1 << 0;
pub const HV_MEMORY_WRITE: hv_memory_flags_t = 1 << 1;
pub const HV_MEMORY_EXEC: hv_memory_flags_t = 1 << 2;
extern "C" {
pub fn hv_vm_map(
uva: hv_uvaddr_t,
gpa: hv_gpaddr_t,
size: size_t,
flags: hv_memory_flags_t,
) -> hv_return_t;
pub fn hv_vm_unmap(gpa: hv_gpaddr_t, size: size_t) -> hv_return_t;
pub fn hv_vm_protect(gpa: hv_gpaddr_t, size: size_t, flags: hv_memory_flags_t) -> hv_return_t;
}
extern "C" {
pub fn hv_vmx_vcpu_read_vmcs(vcpu: hv_vcpuid_t, field: u32, value: *mut u64) -> hv_return_t;
pub fn hv_vmx_vcpu_write_vmcs(vcpu: hv_vcpuid_t, field: u32, value: u64) -> hv_return_t;
pub fn hv_vmx_read_capability(field: super::VMXCap, value: *mut u64) -> hv_return_t;
pub fn hv_vmx_vcpu_set_apic_address(vcpu: hv_vcpuid_t, gpa: hv_gpaddr_t) -> hv_return_t;
}