VirtualBox

source: vbox/trunk/include/iprt/nt/vid.h@ 91651

Last change on this file since 91651 was 91651, checked in by vboxsync, 3 years ago

iprt/nt/hyperv.h,vid.h: Some updates for build 22000. bugref:10118

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
Line 
1/** @file
2 * Virtualization Infrastructure Driver (VID) API.
3 */
4
5/*
6 * Copyright (C) 2018-2020 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 */
38typedef 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. */
48typedef 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. */
58typedef 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;
67AssertCompileSize(VID_MESSAGE_TYPE, 4);
68/** @} */
69
70/**
71 * Header of the message mapping returned by VidMessageSlotMap.
72 */
73typedef 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;
82AssertCompileSize(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 */
90typedef enum
91{
92 VidProcessorStatusStopped = 0,
93 VidProcessorStatusRunning,
94 VidProcessorStatusSuspended,
95 VidProcessorStatusUndefined = 0xffff
96} VID_PROCESSOR_STATUS;
97AssertCompileSize(VID_PROCESSOR_STATUS, 4);
98
99
100/** I/O control input for VidMessageSlotHandleAndGetNext. */
101typedef 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. */
108typedef 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. */
110typedef 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
127#ifdef IN_RING3
128RT_C_DECLS_BEGIN
129
130/** Calling convention. */
131#ifndef WINAPI
132# define VIDAPI __stdcall
133#else
134# define VIDAPI WINAPI
135#endif
136
137/** Partition handle. */
138#ifndef WINAPI
139typedef void *VID_PARTITION_HANDLE;
140#else
141typedef HANDLE VID_PARTITION_HANDLE;
142#endif
143
144/**
145 * Gets the partition ID.
146 *
147 * The partition ID is the numeric identifier used when making hypercalls to the
148 * hypervisor.
149 *
150 * @note Starting with Windows 11 (or possibly earlier), this does not work on
151 * Exo partition as created by WHvCreatePartition. It returns a
152 * STATUS_NOT_IMPLEMENTED as the I/O control code is not allowed through.
153 * All partitions has an ID though, so just pure annoying blockheadedness
154 * sprung upon us w/o any chance of doing a memory managment rewrite in
155 * time.
156 */
157DECLIMPORT(BOOL) VIDAPI VidGetHvPartitionId(VID_PARTITION_HANDLE hPartition, HV_PARTITION_ID *pidPartition);
158
159/**
160 * Get a partition property.
161 *
162 * @returns Success indicator (details in LastErrorValue).
163 * @param hPartition The partition handle.
164 * @param enmProperty The property to get.
165 * @param puValue Where to return the property value.
166 */
167DECLIMPORT(BOOL) VIDAPI VidGetPartitionProperty(VID_PARTITION_HANDLE hPartition, HV_PARTITION_PROPERTY_CODE enmProperty,
168 PHV_PARTITION_PROPERTY puValue);
169
170/**
171 * @copydoc VidGetPartitionProperty
172 * @note Currently (Windows 11 GA) identical to VidGetPartitionProperty.
173 */
174DECLIMPORT(BOOL) VIDAPI VidGetExoPartitionProperty(VID_PARTITION_HANDLE hPartition, HV_PARTITION_PROPERTY_CODE enmProperty,
175 PHV_PARTITION_PROPERTY puValue);
176
177/**
178 * Starts asynchronous execution of a virtual CPU.
179 */
180DECLIMPORT(BOOL) VIDAPI VidStartVirtualProcessor(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu);
181
182/**
183 * Stops the asynchronous execution of a virtual CPU.
184 *
185 * @retval ERROR_VID_STOP_PENDING if busy with intercept, check messages.
186 */
187DECLIMPORT(BOOL) VIDAPI VidStopVirtualProcessor(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu);
188
189/**
190 * WHvCreateVirtualProcessor boils down to a call to VidMessageSlotMap and
191 * some internal WinHvPlatform state fiddling.
192 *
193 * Looks like it maps memory and returns the pointer to it.
194 * VidMessageSlotHandleAndGetNext is later used to wait for the next message and
195 * put (??) it into that memory mapping.
196 *
197 * @returns Success indicator (details in LastErrorValue).
198 *
199 * @param hPartition The partition handle.
200 * @param pOutput Where to return the pointer to the message memory
201 * mapping. The CPU index is also returned here.
202 * @param iCpu The CPU to wait-and-get messages for.
203 */
204DECLIMPORT(BOOL) VIDAPI VidMessageSlotMap(VID_PARTITION_HANDLE hPartition, PVID_MAPPED_MESSAGE_SLOT pOutput, HV_VP_INDEX iCpu);
205
206/**
207 * This is used by WHvRunVirtualProcessor to wait for the next exit msg.
208 *
209 * The message appears in the memory mapping returned by VidMessageSlotMap.
210 *
211 * @returns Success indicator (details only in LastErrorValue - LastStatusValue
212 * is not set).
213 * @retval STATUS_TIMEOUT for STATUS_TIMEOUT as well as STATUS_USER_APC and
214 * STATUS_ALERTED.
215 *
216 * @param hPartition The partition handle.
217 * @param iCpu The CPU to wait-and-get messages for.
218 * @param fFlags Flags, VID_MSHAGN_F_XXX.
219 *
220 * When starting or resuming execution, at least one of
221 * VID_MSHAGN_F_GET_NEXT_MESSAGE (bit 0) and
222 * VID_MSHAGN_F_HANDLE_MESSAGE (bit 1) must be set.
223 *
224 * When cancelling execution only VID_MSHAGN_F_CANCEL (big 2)
225 * must be set.
226 *
227 * @param cMillies The timeout, presumably in milliseconds. This parameter
228 * was dropped about build 17758.
229 *
230 * @todo Would be awfully nice if someone at Microsoft could hit at the
231 * flags here.
232 */
233DECLIMPORT(BOOL) VIDAPI VidMessageSlotHandleAndGetNext(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
234 uint32_t fFlags, uint32_t cMillies);
235/**
236 * Gets the processor running status.
237 *
238 * This is probably only available in special builds, as one of the early I/O
239 * control dispatching routines will not let it thru. Lower down routines does
240 * implement it, so it's possible to patch it into working. This works for
241 * build 17101: eb vid+12180 0f 84 98 00 00 00
242 *
243 * @retval ERROR_NOT_IMPLEMENTED
244 *
245 * @remarks VidExoFastIoControlPartition probably disapproves of this too. It
246 * could be very handy for debugging upon occation.
247 */
248DECLIMPORT(BOOL) VIDAPI VidGetVirtualProcessorRunningStatus(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
249 VID_PROCESSOR_STATUS *penmStatus);
250
251/**
252 * For query virtual processor registers and other state information.
253 *
254 * @returns Success indicator (details in LastErrorValue).
255 */
256DECLIMPORT(BOOL) VIDAPI VidGetVirtualProcessorState(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
257 HV_REGISTER_NAME const *paRegNames, uint32_t cRegisters,
258 HV_REGISTER_VALUE *paRegValues);
259
260/**
261 * For setting virtual processor registers and other state information.
262 *
263 * @returns Success indicator (details in LastErrorValue).
264 */
265DECLIMPORT(BOOL) VIDAPI VidSetVirtualProcessorState(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
266 HV_REGISTER_NAME const *paRegNames, uint32_t cRegisters,
267 HV_REGISTER_VALUE const *paRegValues);
268
269/**
270 * Wrapper around the HvCallGetMemoryBalance hypercall.
271 *
272 * When VID.SYS processes the request, it will also query
273 * HvPartitionPropertyVirtualTlbPageCount, so we're passing a 3rd return
274 * parameter in case the API is ever extended to match the I/O control.
275 *
276 * @returns Success indicator (details in LastErrorValue).
277 * @retval ERROR_NOT_IMPLEMENTED for exo partitions.
278 *
279 * @param hPartition The partition handle.
280 * @param pcPagesAvailable Where to return the number of unused pages
281 * still available to the partition.
282 * @param pcPagesInUse Where to return the number of pages currently
283 * in use by the partition.
284 * @param pReserved Pointer to dummy value, just in case they
285 * modify the API to include the nested TLB size.
286 *
287 * @note Not available for exo partitions, unfortunately. The
288 * VidExoFastIoControlPartition function deflects it, failing it with
289 * STATUS_NOT_IMPLEMENTED / ERROR_NOT_IMPLEMENTED.
290 */
291DECLIMPORT(BOOL) VIDAPI VidGetHvMemoryBalance(VID_PARTITION_HANDLE hPartition, uint64_t *pcPagesAvailable,
292 uint64_t *pcPagesInUse, uint64_t *pReserved);
293
294RT_C_DECLS_END
295#endif /* IN_RING3 */
296
297#endif /* !IPRT_INCLUDED_nt_vid_h */
298
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette