1 | /** @file
|
---|
2 | * Virtualization Infrastructure Driver (VID) API.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2018-2022 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef IPRT_INCLUDED_nt_vid_h
|
---|
27 | #define IPRT_INCLUDED_nt_vid_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include "hyperv.h"
|
---|
33 |
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Output from VidMessageSlotMap.
|
---|
37 | */
|
---|
38 | typedef struct VID_MAPPED_MESSAGE_SLOT
|
---|
39 | {
|
---|
40 | /** The message block mapping. */
|
---|
41 | struct _HV_MESSAGE *pMsgBlock;
|
---|
42 | /** Copy of input iCpu. */
|
---|
43 | uint32_t iCpu;
|
---|
44 | /** Explicit padding. */
|
---|
45 | uint32_t uParentAdvisory;
|
---|
46 | } VID_MAPPED_MESSAGE_SLOT;
|
---|
47 | /** Pointer to VidMessageSlotMap output structure. */
|
---|
48 | typedef VID_MAPPED_MESSAGE_SLOT *PVID_MAPPED_MESSAGE_SLOT;
|
---|
49 |
|
---|
50 |
|
---|
51 | /** @name VID_MESSAGE_MAPPING_HEADER::enmVidMsgType values (wild guess).
|
---|
52 | * @{ */
|
---|
53 | /** Type mask, strips flags. */
|
---|
54 | #define VID_MESSAGE_TYPE_MASK UINT32_C(0x00ffffff)
|
---|
55 | /** No return message necessary. */
|
---|
56 | #define VID_MESSAGE_TYPE_FLAG_NO_RETURN UINT32_C(0x01000000)
|
---|
57 | /** Observed message values. */
|
---|
58 | typedef enum
|
---|
59 | {
|
---|
60 | /** Invalid zero value. */
|
---|
61 | VidMessageInvalid = 0,
|
---|
62 | /** Guessing this means a message from the hypervisor. */
|
---|
63 | VidMessageHypervisorMessage = 0x00000c | VID_MESSAGE_TYPE_FLAG_NO_RETURN,
|
---|
64 | /** Guessing this means stop request completed. Message length is 1 byte. */
|
---|
65 | VidMessageStopRequestComplete = 0x00000d | VID_MESSAGE_TYPE_FLAG_NO_RETURN,
|
---|
66 | } VID_MESSAGE_TYPE;
|
---|
67 | AssertCompileSize(VID_MESSAGE_TYPE, 4);
|
---|
68 | /** @} */
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Header of the message mapping returned by VidMessageSlotMap.
|
---|
72 | */
|
---|
73 | typedef struct VID_MESSAGE_MAPPING_HEADER
|
---|
74 | {
|
---|
75 | /** Current guess is that this is VID_MESSAGE_TYPE. */
|
---|
76 | VID_MESSAGE_TYPE enmVidMsgType;
|
---|
77 | /** The message size or so it seems (0x100). */
|
---|
78 | uint32_t cbMessage;
|
---|
79 | /** So far these have been zero. */
|
---|
80 | uint32_t aZeroPPadding[2+4];
|
---|
81 | } VID_MESSAGE_MAPPING_HEADER;
|
---|
82 | AssertCompileSize(VID_MESSAGE_MAPPING_HEADER, 32);
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * VID processor status (VidGetVirtualProcessorRunningStatus).
|
---|
86 | *
|
---|
87 | * @note This is used internally in VID.SYS, in 17101 it's at offset 8 in their
|
---|
88 | * 'pVCpu' structure.
|
---|
89 | */
|
---|
90 | typedef enum
|
---|
91 | {
|
---|
92 | VidProcessorStatusStopped = 0,
|
---|
93 | VidProcessorStatusRunning,
|
---|
94 | VidProcessorStatusSuspended,
|
---|
95 | VidProcessorStatusUndefined = 0xffff
|
---|
96 | } VID_PROCESSOR_STATUS;
|
---|
97 | AssertCompileSize(VID_PROCESSOR_STATUS, 4);
|
---|
98 |
|
---|
99 |
|
---|
100 | /** I/O control input for VidMessageSlotHandleAndGetNext. */
|
---|
101 | typedef struct VID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT
|
---|
102 | {
|
---|
103 | HV_VP_INDEX iCpu;
|
---|
104 | uint32_t fFlags; /**< VID_MSHAGN_F_GET_XXX*/
|
---|
105 | uint32_t cMillies; /**< Not present in build 17758 as the API changed to always to infinite waits. */
|
---|
106 | } VID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT;
|
---|
107 | /** Pointer to input for VidMessageSlotHandleAndGetNext. */
|
---|
108 | typedef VID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT *PVID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT;
|
---|
109 | /** Pointer to const input for VidMessageSlotHandleAndGetNext. */
|
---|
110 | typedef VID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT const *PCVID_IOCTL_INPUT_MESSAGE_SLOT_HANDLE_AND_GET_NEXT;
|
---|
111 |
|
---|
112 | /** @name VID_MSHAGN_F_GET_XXX - Flags for VidMessageSlotHandleAndGetNext
|
---|
113 | * @{ */
|
---|
114 | /** This will try get the next message, waiting if necessary.
|
---|
115 | * It is subject to NtAlertThread processing when it starts waiting. */
|
---|
116 | #define VID_MSHAGN_F_GET_NEXT_MESSAGE RT_BIT_32(0)
|
---|
117 | /** ACK the message as handled and resume execution/whatever.
|
---|
118 | * This is executed before VID_MSHAGN_F_GET_NEXT_MESSAGE and should not be
|
---|
119 | * subject to NtAlertThread side effects. */
|
---|
120 | #define VID_MSHAGN_F_HANDLE_MESSAGE RT_BIT_32(1)
|
---|
121 | /** Cancel VP execution (no other bit set).
|
---|
122 | * @since about build 17758. */
|
---|
123 | #define VID_MSHAGN_F_CANCEL RT_BIT_32(2)
|
---|
124 | /** @} */
|
---|
125 |
|
---|
126 | /** A 64-bit version of HV_PARTITION_PROPERTY_CODE. */
|
---|
127 | typedef int64_t VID_PARTITION_PROPERTY_CODE;
|
---|
128 |
|
---|
129 |
|
---|
130 | #ifdef IN_RING3
|
---|
131 | RT_C_DECLS_BEGIN
|
---|
132 |
|
---|
133 | /** Calling convention. */
|
---|
134 | #ifndef WINAPI
|
---|
135 | # define VIDAPI __stdcall
|
---|
136 | #else
|
---|
137 | # define VIDAPI WINAPI
|
---|
138 | #endif
|
---|
139 |
|
---|
140 | /** Partition handle. */
|
---|
141 | #ifndef WINAPI
|
---|
142 | typedef void *VID_PARTITION_HANDLE;
|
---|
143 | #else
|
---|
144 | typedef HANDLE VID_PARTITION_HANDLE;
|
---|
145 | #endif
|
---|
146 |
|
---|
147 | /**
|
---|
148 | * Gets the partition ID.
|
---|
149 | *
|
---|
150 | * The partition ID is the numeric identifier used when making hypercalls to the
|
---|
151 | * hypervisor.
|
---|
152 | *
|
---|
153 | * @note Starting with Windows 11 (or possibly earlier), this does not work on
|
---|
154 | * Exo partition as created by WHvCreatePartition. It returns a
|
---|
155 | * STATUS_NOT_IMPLEMENTED as the I/O control code is not allowed through.
|
---|
156 | * All partitions has an ID though, so just pure annoying blockheadedness
|
---|
157 | * sprung upon us w/o any chance of doing a memory managment rewrite in
|
---|
158 | * time.
|
---|
159 | */
|
---|
160 | DECLIMPORT(BOOL) VIDAPI VidGetHvPartitionId(VID_PARTITION_HANDLE hPartition, HV_PARTITION_ID *pidPartition);
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Get a partition property.
|
---|
164 | *
|
---|
165 | * @returns Success indicator (details in LastErrorValue).
|
---|
166 | * @param hPartition The partition handle.
|
---|
167 | * @param enmProperty The property to get. Is a HV_PARTITION_PROPERTY_CODE
|
---|
168 | * type, but seems to be passed around as a 64-bit integer
|
---|
169 | * for some reason.
|
---|
170 | * @param puValue Where to return the property value.
|
---|
171 | */
|
---|
172 | DECLIMPORT(BOOL) VIDAPI VidGetPartitionProperty(VID_PARTITION_HANDLE hPartition, VID_PARTITION_PROPERTY_CODE enmProperty,
|
---|
173 | PHV_PARTITION_PROPERTY puValue);
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * @copydoc VidGetPartitionProperty
|
---|
177 | * @note Currently (Windows 11 GA) identical to VidGetPartitionProperty.
|
---|
178 | */
|
---|
179 | DECLIMPORT(BOOL) VIDAPI VidGetExoPartitionProperty(VID_PARTITION_HANDLE hPartition, VID_PARTITION_PROPERTY_CODE enmProperty,
|
---|
180 | PHV_PARTITION_PROPERTY puValue);
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Starts asynchronous execution of a virtual CPU.
|
---|
184 | */
|
---|
185 | DECLIMPORT(BOOL) VIDAPI VidStartVirtualProcessor(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu);
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * Stops the asynchronous execution of a virtual CPU.
|
---|
189 | *
|
---|
190 | * @retval ERROR_VID_STOP_PENDING if busy with intercept, check messages.
|
---|
191 | */
|
---|
192 | DECLIMPORT(BOOL) VIDAPI VidStopVirtualProcessor(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu);
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * WHvCreateVirtualProcessor boils down to a call to VidMessageSlotMap and
|
---|
196 | * some internal WinHvPlatform state fiddling.
|
---|
197 | *
|
---|
198 | * Looks like it maps memory and returns the pointer to it.
|
---|
199 | * VidMessageSlotHandleAndGetNext is later used to wait for the next message and
|
---|
200 | * put (??) it into that memory mapping.
|
---|
201 | *
|
---|
202 | * @returns Success indicator (details in LastErrorValue).
|
---|
203 | *
|
---|
204 | * @param hPartition The partition handle.
|
---|
205 | * @param pOutput Where to return the pointer to the message memory
|
---|
206 | * mapping. The CPU index is also returned here.
|
---|
207 | * @param iCpu The CPU to wait-and-get messages for.
|
---|
208 | */
|
---|
209 | DECLIMPORT(BOOL) VIDAPI VidMessageSlotMap(VID_PARTITION_HANDLE hPartition, PVID_MAPPED_MESSAGE_SLOT pOutput, HV_VP_INDEX iCpu);
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * This is used by WHvRunVirtualProcessor to wait for the next exit msg.
|
---|
213 | *
|
---|
214 | * The message appears in the memory mapping returned by VidMessageSlotMap.
|
---|
215 | *
|
---|
216 | * @returns Success indicator (details only in LastErrorValue - LastStatusValue
|
---|
217 | * is not set).
|
---|
218 | * @retval STATUS_TIMEOUT for STATUS_TIMEOUT as well as STATUS_USER_APC and
|
---|
219 | * STATUS_ALERTED.
|
---|
220 | *
|
---|
221 | * @param hPartition The partition handle.
|
---|
222 | * @param iCpu The CPU to wait-and-get messages for.
|
---|
223 | * @param fFlags Flags, VID_MSHAGN_F_XXX.
|
---|
224 | *
|
---|
225 | * When starting or resuming execution, at least one of
|
---|
226 | * VID_MSHAGN_F_GET_NEXT_MESSAGE (bit 0) and
|
---|
227 | * VID_MSHAGN_F_HANDLE_MESSAGE (bit 1) must be set.
|
---|
228 | *
|
---|
229 | * When cancelling execution only VID_MSHAGN_F_CANCEL (big 2)
|
---|
230 | * must be set.
|
---|
231 | *
|
---|
232 | * @param cMillies The timeout, presumably in milliseconds. This parameter
|
---|
233 | * was dropped about build 17758.
|
---|
234 | *
|
---|
235 | * @todo Would be awfully nice if someone at Microsoft could hit at the
|
---|
236 | * flags here.
|
---|
237 | */
|
---|
238 | DECLIMPORT(BOOL) VIDAPI VidMessageSlotHandleAndGetNext(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
|
---|
239 | uint32_t fFlags, uint32_t cMillies);
|
---|
240 | /**
|
---|
241 | * Gets the processor running status.
|
---|
242 | *
|
---|
243 | * This is probably only available in special builds, as one of the early I/O
|
---|
244 | * control dispatching routines will not let it thru. Lower down routines does
|
---|
245 | * implement it, so it's possible to patch it into working. This works for
|
---|
246 | * build 17101: eb vid+12180 0f 84 98 00 00 00
|
---|
247 | *
|
---|
248 | * @retval ERROR_NOT_IMPLEMENTED
|
---|
249 | *
|
---|
250 | * @remarks VidExoFastIoControlPartition probably disapproves of this too. It
|
---|
251 | * could be very handy for debugging upon occation.
|
---|
252 | */
|
---|
253 | DECLIMPORT(BOOL) VIDAPI VidGetVirtualProcessorRunningStatus(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
|
---|
254 | VID_PROCESSOR_STATUS *penmStatus);
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * For query virtual processor registers and other state information.
|
---|
258 | *
|
---|
259 | * @returns Success indicator (details in LastErrorValue).
|
---|
260 | */
|
---|
261 | DECLIMPORT(BOOL) VIDAPI VidGetVirtualProcessorState(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
|
---|
262 | HV_REGISTER_NAME const *paRegNames, uint32_t cRegisters,
|
---|
263 | HV_REGISTER_VALUE *paRegValues);
|
---|
264 |
|
---|
265 | /**
|
---|
266 | * For setting virtual processor registers and other state information.
|
---|
267 | *
|
---|
268 | * @returns Success indicator (details in LastErrorValue).
|
---|
269 | */
|
---|
270 | DECLIMPORT(BOOL) VIDAPI VidSetVirtualProcessorState(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
|
---|
271 | HV_REGISTER_NAME const *paRegNames, uint32_t cRegisters,
|
---|
272 | HV_REGISTER_VALUE const *paRegValues);
|
---|
273 |
|
---|
274 | /**
|
---|
275 | * Wrapper around the HvCallGetMemoryBalance hypercall.
|
---|
276 | *
|
---|
277 | * When VID.SYS processes the request, it will also query
|
---|
278 | * HvPartitionPropertyVirtualTlbPageCount, so we're passing a 3rd return
|
---|
279 | * parameter in case the API is ever extended to match the I/O control.
|
---|
280 | *
|
---|
281 | * @returns Success indicator (details in LastErrorValue).
|
---|
282 | * @retval ERROR_NOT_IMPLEMENTED for exo partitions.
|
---|
283 | *
|
---|
284 | * @param hPartition The partition handle.
|
---|
285 | * @param pcPagesAvailable Where to return the number of unused pages
|
---|
286 | * still available to the partition.
|
---|
287 | * @param pcPagesInUse Where to return the number of pages currently
|
---|
288 | * in use by the partition.
|
---|
289 | * @param pReserved Pointer to dummy value, just in case they
|
---|
290 | * modify the API to include the nested TLB size.
|
---|
291 | *
|
---|
292 | * @note Not available for exo partitions, unfortunately. The
|
---|
293 | * VidExoFastIoControlPartition function deflects it, failing it with
|
---|
294 | * STATUS_NOT_IMPLEMENTED / ERROR_NOT_IMPLEMENTED.
|
---|
295 | */
|
---|
296 | DECLIMPORT(BOOL) VIDAPI VidGetHvMemoryBalance(VID_PARTITION_HANDLE hPartition, uint64_t *pcPagesAvailable,
|
---|
297 | uint64_t *pcPagesInUse, uint64_t *pReserved);
|
---|
298 |
|
---|
299 | RT_C_DECLS_END
|
---|
300 | #endif /* IN_RING3 */
|
---|
301 |
|
---|
302 | #endif /* !IPRT_INCLUDED_nt_vid_h */
|
---|
303 |
|
---|