VirtualBox

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

Last change on this file since 78377 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 KB
Line 
1/** @file
2 * Virtualization Infrastructure Driver (VID) API.
3 */
4
5/*
6 * Copyright (C) 2018-2019 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 */
150DECLIMPORT(BOOL) VIDAPI VidGetHvPartitionId(VID_PARTITION_HANDLE hPartition, HV_PARTITION_ID *pidPartition);
151
152/**
153 * Starts asynchronous execution of a virtual CPU.
154 */
155DECLIMPORT(BOOL) VIDAPI VidStartVirtualProcessor(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu);
156
157/**
158 * Stops the asynchronous execution of a virtual CPU.
159 *
160 * @retval ERROR_VID_STOP_PENDING if busy with intercept, check messages.
161 */
162DECLIMPORT(BOOL) VIDAPI VidStopVirtualProcessor(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu);
163
164/**
165 * WHvCreateVirtualProcessor boils down to a call to VidMessageSlotMap and
166 * some internal WinHvPlatform state fiddling.
167 *
168 * Looks like it maps memory and returns the pointer to it.
169 * VidMessageSlotHandleAndGetNext is later used to wait for the next message and
170 * put (??) it into that memory mapping.
171 *
172 * @returns Success indicator (details in LastErrorValue).
173 *
174 * @param hPartition The partition handle.
175 * @param pOutput Where to return the pointer to the message memory
176 * mapping. The CPU index is also returned here.
177 * @param iCpu The CPU to wait-and-get messages for.
178 */
179DECLIMPORT(BOOL) VIDAPI VidMessageSlotMap(VID_PARTITION_HANDLE hPartition, PVID_MAPPED_MESSAGE_SLOT pOutput, HV_VP_INDEX iCpu);
180
181/**
182 * This is used by WHvRunVirtualProcessor to wait for the next exit msg.
183 *
184 * The message appears in the memory mapping returned by VidMessageSlotMap.
185 *
186 * @returns Success indicator (details only in LastErrorValue - LastStatusValue
187 * is not set).
188 * @retval STATUS_TIMEOUT for STATUS_TIMEOUT as well as STATUS_USER_APC and
189 * STATUS_ALERTED.
190 *
191 * @param hPartition The partition handle.
192 * @param iCpu The CPU to wait-and-get messages for.
193 * @param fFlags Flags, VID_MSHAGN_F_XXX.
194 *
195 * When starting or resuming execution, at least one of
196 * VID_MSHAGN_F_GET_NEXT_MESSAGE (bit 0) and
197 * VID_MSHAGN_F_HANDLE_MESSAGE (bit 1) must be set.
198 *
199 * When cancelling execution only VID_MSHAGN_F_CANCEL (big 2)
200 * must be set.
201 *
202 * @param cMillies The timeout, presumably in milliseconds. This parameter
203 * was dropped about build 17758.
204 *
205 * @todo Would be awfully nice if someone at Microsoft could hit at the
206 * flags here.
207 */
208DECLIMPORT(BOOL) VIDAPI VidMessageSlotHandleAndGetNext(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
209 uint32_t fFlags, uint32_t cMillies);
210/**
211 * Gets the processor running status.
212 *
213 * This is probably only available in special builds, as one of the early I/O
214 * control dispatching routines will not let it thru. Lower down routines does
215 * implement it, so it's possible to patch it into working. This works for
216 * build 17101: eb vid+12180 0f 84 98 00 00 00
217 *
218 * @retval ERROR_NOT_IMPLEMENTED
219 *
220 * @remarks VidExoFastIoControlPartition probably disapproves of this too. It
221 * could be very handy for debugging upon occation.
222 */
223DECLIMPORT(BOOL) VIDAPI VidGetVirtualProcessorRunningStatus(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
224 VID_PROCESSOR_STATUS *penmStatus);
225
226/**
227 * For query virtual processor registers and other state information.
228 *
229 * @returns Success indicator (details in LastErrorValue).
230 */
231DECLIMPORT(BOOL) VIDAPI VidGetVirtualProcessorState(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
232 HV_REGISTER_NAME const *paRegNames, uint32_t cRegisters,
233 HV_REGISTER_VALUE *paRegValues);
234
235/**
236 * For setting virtual processor registers and other state information.
237 *
238 * @returns Success indicator (details in LastErrorValue).
239 */
240DECLIMPORT(BOOL) VIDAPI VidSetVirtualProcessorState(VID_PARTITION_HANDLE hPartition, HV_VP_INDEX iCpu,
241 HV_REGISTER_NAME const *paRegNames, uint32_t cRegisters,
242 HV_REGISTER_VALUE const *paRegValues);
243
244/**
245 * Wrapper around the HvCallGetMemoryBalance hypercall.
246 *
247 * When VID.SYS processes the request, it will also query
248 * HvPartitionPropertyVirtualTlbPageCount, so we're passing a 3rd return
249 * parameter in case the API is ever extended to match the I/O control.
250 *
251 * @returns Success indicator (details in LastErrorValue).
252 * @retval ERROR_NOT_IMPLEMENTED for exo partitions.
253 *
254 * @param hPartition The partition handle.
255 * @param pcPagesAvailable Where to return the number of unused pages
256 * still available to the partition.
257 * @param pcPagesInUse Where to return the number of pages currently
258 * in use by the partition.
259 * @param pReserved Pointer to dummy value, just in case they
260 * modify the API to include the nested TLB size.
261 *
262 * @note Not available for exo partitions, unfortunately. The
263 * VidExoFastIoControlPartition function deflects it, failing it with
264 * STATUS_NOT_IMPLEMENTED / ERROR_NOT_IMPLEMENTED.
265 */
266DECLIMPORT(BOOL) VIDAPI VidGetHvMemoryBalance(VID_PARTITION_HANDLE hPartition, uint64_t *pcPagesAvailable,
267 uint64_t *pcPagesInUse, uint64_t *pReserved);
268
269RT_C_DECLS_END
270#endif /* IN_RING3 */
271
272#endif /* !IPRT_INCLUDED_nt_vid_h */
273
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