VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

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