VirtualBox

source: vbox/trunk/include/VBox/vmapi.h@ 6835

Last change on this file since 6835 was 6835, checked in by vboxsync, 16 years ago

Added VMGetStateName.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.9 KB
Line 
1/** @file
2 * VM - The Virtual Machine, API.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
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 ___VBox_vmapi_h
27#define ___VBox_vmapi_h
28
29#include <VBox/cdefs.h>
30#include <VBox/types.h>
31#include <VBox/cpum.h>
32#include <VBox/stam.h>
33#include <VBox/cfgm.h>
34
35#include <iprt/stdarg.h>
36
37__BEGIN_DECLS
38
39/** @defgroup grp_vmm_apis VM All Contexts API
40 * @ingroup grp_vm
41 * @{ */
42
43/** @def VM_GUEST_ADDR
44 * Converts a current context address of data within the VM structure to the equivalent
45 * guest address.
46 *
47 * @returns guest virtual address.
48 * @param pVM Pointer to the VM.
49 * @param pvInVM CC Pointer within the VM.
50 */
51#ifdef IN_RING3
52# define VM_GUEST_ADDR(pVM, pvInVM) ( (RTGCPTR)((RTGCUINTPTR)pVM->pVMGC + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMR3)) )
53#elif defined(IN_RING0)
54# define VM_GUEST_ADDR(pVM, pvInVM) ( (RTGCPTR)((RTGCUINTPTR)pVM->pVMGC + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMR0)) )
55#else
56# define VM_GUEST_ADDR(pVM, pvInVM) ( (RTGCPTR)(pvInVM) )
57#endif
58
59/** @def VM_R3_ADDR
60 * Converts a current context address of data within the VM structure to the equivalent
61 * ring-3 host address.
62 *
63 * @returns host virtual address.
64 * @param pVM Pointer to the VM.
65 * @param pvInVM CC pointer within the VM.
66 */
67#ifdef IN_GC
68# define VM_R3_ADDR(pVM, pvInVM) ( (RTR3PTR)((RTR3UINTPTR)pVM->pVMR3 + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMGC)) )
69#elif defined(IN_RING0)
70# define VM_R3_ADDR(pVM, pvInVM) ( (RTR3PTR)((RTR3UINTPTR)pVM->pVMR3 + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMR0)) )
71#else
72# define VM_R3_ADDR(pVM, pvInVM) ( (RTR3PTR)(pvInVM) )
73#endif
74
75
76/** @def VM_R0_ADDR
77 * Converts a current context address of data within the VM structure to the equivalent
78 * ring-0 host address.
79 *
80 * @returns host virtual address.
81 * @param pVM Pointer to the VM.
82 * @param pvInVM CC pointer within the VM.
83 */
84#ifdef IN_GC
85# define VM_R0_ADDR(pVM, pvInVM) ( (RTR0PTR)((RTR0UINTPTR)pVM->pVMR0 + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMGC)) )
86#elif defined(IN_RING3)
87# define VM_R0_ADDR(pVM, pvInVM) ( (RTR0PTR)((RTR0UINTPTR)pVM->pVMR0 + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMR3)) )
88#else
89# define VM_R0_ADDR(pVM, pvInVM) ( (RTR0PTR)(pvInVM) )
90#endif
91
92/** @def VM_HOST_ADDR
93 * Converts guest address of data within the VM structure to the equivalent
94 * host address.
95 *
96 * @returns host virtual address.
97 * @param pVM Pointer to the VM.
98 * @param pvInVM GC Pointer within the VM.
99 * @deprecated
100 */
101#define VM_HOST_ADDR(pVM, pvInVM) ( (RTHCPTR)((RTHCUINTPTR)pVM->pVMHC + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMGC)) )
102
103
104
105/**
106 * VM error callback function.
107 *
108 * @param pVM The VM handle. Can be NULL if an error occurred before
109 * successfully creating a VM.
110 * @param pvUser The user argument.
111 * @param rc VBox status code.
112 * @param RT_SRC_POS_DECL The source position arguments. See RT_SRC_POS and RT_SRC_POS_ARGS.
113 * @param pszFormat Error message format string.
114 * @param args Error message arguments.
115 */
116typedef DECLCALLBACK(void) FNVMATERROR(PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszError, va_list args);
117/** Pointer to a VM error callback. */
118typedef FNVMATERROR *PFNVMATERROR;
119
120VMDECL(int) VMSetError(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...);
121VMDECL(int) VMSetErrorV(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list args);
122
123/** @def VM_SET_ERROR
124 * Macro for setting a simple VM error message.
125 * Don't use '%' in the message!
126 *
127 * @returns rc. Meaning you can do:
128 * @code
129 * return VM_SET_ERROR(pVM, VERR_OF_YOUR_CHOICE, "descriptive message");
130 * @endcode
131 * @param pVM VM handle.
132 * @param rc VBox status code.
133 * @param pszMessage Error message string.
134 * @thread Any
135 */
136#define VM_SET_ERROR(pVM, rc, pszMessage) (VMSetError(pVM, rc, RT_SRC_POS, pszMessage))
137
138
139/**
140 * VM runtime error callback function.
141 * See VMSetRuntimeError for the detailed description of parameters.
142 *
143 * @param pVM The VM handle.
144 * @param pvUser The user argument.
145 * @param fFatal Whether it is a fatal error or not.
146 * @param pszErrorID Error ID string.
147 * @param pszFormat Error message format string.
148 * @param args Error message arguments.
149 */
150typedef DECLCALLBACK(void) FNVMATRUNTIMEERROR(PVM pVM, void *pvUser, bool fFatal,
151 const char *pszErrorID,
152 const char *pszFormat, va_list args);
153/** Pointer to a VM runtime error callback. */
154typedef FNVMATRUNTIMEERROR *PFNVMATRUNTIMEERROR;
155
156VMDECL(int) VMSetRuntimeError(PVM pVM, bool fFatal, const char *pszErrorID, const char *pszFormat, ...);
157VMDECL(int) VMSetRuntimeErrorV(PVM pVM, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list args);
158
159
160/**
161 * VM reset callback.
162 *
163 * @returns VBox status code.
164 * @param pDevInst Device instance of the device which registered the callback.
165 * @param pvUser User argument.
166 */
167typedef DECLCALLBACK(int) FNVMATRESET(PPDMDEVINS pDevInst, void *pvUser);
168/** VM reset callback. */
169typedef FNVMATRESET *PFNVMATRESET;
170
171/**
172 * VM reset internal callback.
173 *
174 * @returns VBox status code.
175 * @param pVM The VM which is begin reset.
176 * @param pvUser User argument.
177 */
178typedef DECLCALLBACK(int) FNVMATRESETINT(PVM pVM, void *pvUser);
179/** VM reset internal callback. */
180typedef FNVMATRESETINT *PFNVMATRESETINT;
181
182/**
183 * VM reset external callback.
184 *
185 * @param pvUser User argument.
186 */
187typedef DECLCALLBACK(void) FNVMATRESETEXT(void *pvUser);
188/** VM reset external callback. */
189typedef FNVMATRESETEXT *PFNVMATRESETEXT;
190
191
192/**
193 * VM state callback function.
194 *
195 * You are not allowed to call any function which changes the VM state from a
196 * state callback, except VMR3Destroy().
197 *
198 * @param pVM The VM handle.
199 * @param enmState The new state.
200 * @param enmOldState The old state.
201 * @param pvUser The user argument.
202 */
203typedef DECLCALLBACK(void) FNVMATSTATE(PVM pVM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
204/** Pointer to a VM state callback. */
205typedef FNVMATSTATE *PFNVMATSTATE;
206
207VMDECL(const char *) VMGetStateName(VMSTATE enmState);
208
209
210/**
211 * Request type.
212 */
213typedef enum VMREQTYPE
214{
215 /** Invalid request. */
216 VMREQTYPE_INVALID = 0,
217 /** VM: Internal. */
218 VMREQTYPE_INTERNAL,
219 /** Maximum request type (exclusive). Used for validation. */
220 VMREQTYPE_MAX
221} VMREQTYPE;
222
223/**
224 * Request state.
225 */
226typedef enum VMREQSTATE
227{
228 /** The state is invalid. */
229 VMREQSTATE_INVALID = 0,
230 /** The request have been allocated and is in the process of being filed. */
231 VMREQSTATE_ALLOCATED,
232 /** The request is queued by the requester. */
233 VMREQSTATE_QUEUED,
234 /** The request is begin processed. */
235 VMREQSTATE_PROCESSING,
236 /** The request is completed, the requester is begin notified. */
237 VMREQSTATE_COMPLETED,
238 /** The request packet is in the free chain. (The requester */
239 VMREQSTATE_FREE
240} VMREQSTATE;
241
242/**
243 * Request flags.
244 */
245typedef enum VMREQFLAGS
246{
247 /** The request returns a VBox status code. */
248 VMREQFLAGS_VBOX_STATUS = 0,
249 /** The request is a void request and have no status code. */
250 VMREQFLAGS_VOID = 1,
251 /** Return type mask. */
252 VMREQFLAGS_RETURN_MASK = 1,
253 /** Caller does not wait on the packet, EMT will free it. */
254 VMREQFLAGS_NO_WAIT = 2
255} VMREQFLAGS;
256
257/**
258 * VM Request packet.
259 *
260 * This is used to request an action in the EMT. Usually the requester is
261 * another thread, but EMT can also end up being the requester in which case
262 * it's carried out synchronously.
263 */
264typedef struct VMREQ
265{
266 /** Pointer to the next request in the chain. */
267 struct VMREQ * volatile pNext;
268 /** Pointer to ring-3 VM structure which this request belongs to. */
269 PUVM pUVM;
270 /** Request state. */
271 volatile VMREQSTATE enmState;
272 /** VBox status code for the completed request. */
273 volatile int iStatus;
274 /** Requester event sem.
275 * The request can use this event semaphore to wait/poll for completion
276 * of the request.
277 */
278 RTSEMEVENT EventSem;
279 /** Set if the event semaphore is clear. */
280 volatile bool fEventSemClear;
281 /** Flags, VMR3REQ_FLAGS_*. */
282 unsigned fFlags;
283 /** Request type. */
284 VMREQTYPE enmType;
285 /** Request specific data. */
286 union VMREQ_U
287 {
288 /** VMREQTYPE_INTERNAL. */
289 struct
290 {
291 /** Pointer to the function to be called. */
292 PFNRT pfn;
293 /** Number of arguments. */
294 unsigned cArgs;
295 /** Array of arguments. */
296 uintptr_t aArgs[64];
297 } Internal;
298 } u;
299} VMREQ;
300/** Pointer to a VM request packet. */
301typedef VMREQ *PVMREQ;
302
303/** @} */
304
305
306#ifndef IN_GC
307/** @defgroup grp_vmm_apis_hc VM Host Context API
308 * @ingroup grp_vm
309 * @{ */
310
311/** @} */
312#endif
313
314
315#ifdef IN_RING3
316/** @defgroup grp_vmm_apis_r3 VM Host Context Ring 3 API
317 * This interface is a _draft_!
318 * @ingroup grp_vm
319 * @{ */
320
321/**
322 * Completion notification codes.
323 */
324typedef enum VMINITCOMPLETED
325{
326 /** The Ring3 init is completed. */
327 VMINITCOMPLETED_RING3 = 1,
328 /** The Ring0 init is completed. */
329 VMINITCOMPLETED_RING0,
330 /** The GC init is completed. */
331 VMINITCOMPLETED_GC
332} VMINITCOMPLETED;
333
334
335VMR3DECL(int) VMR3Create(PFNVMATERROR pfnVMAtError, void *pvUserVM, PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM, PVM *ppVM);
336VMR3DECL(int) VMR3PowerOn(PVM pVM);
337VMR3DECL(int) VMR3Suspend(PVM pVM);
338VMR3DECL(int) VMR3SuspendNoSave(PVM pVM);
339VMR3DECL(int) VMR3Resume(PVM pVM);
340VMR3DECL(int) VMR3Reset(PVM pVM);
341
342/**
343 * Progress callback.
344 * This will report the completion percentage of an operation.
345 *
346 * @returns VINF_SUCCESS.
347 * @returns Error code to cancel the operation with.
348 * @param pVM The VM handle.
349 * @param uPercent Completetion precentage (0-100).
350 * @param pvUser User specified argument.
351 */
352typedef DECLCALLBACK(int) FNVMPROGRESS(PVM pVM, unsigned uPercent, void *pvUser);
353/** Pointer to a FNVMPROGRESS function. */
354typedef FNVMPROGRESS *PFNVMPROGRESS;
355
356VMR3DECL(int) VMR3Save(PVM pVM, const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser);
357VMR3DECL(int) VMR3Load(PVM pVM, const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser);
358VMR3DECL(int) VMR3PowerOff(PVM pVM);
359VMR3DECL(int) VMR3Destroy(PVM pVM);
360VMR3DECL(void) VMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
361VMR3DECL(PVM) VMR3EnumVMs(PVM pVMPrev);
362VMR3DECL(int) VMR3WaitForResume(PVM pVM);
363
364/**
365 * VM destruction callback.
366 * @param pVM The VM which is about to be destroyed.
367 * @param pvUser The user parameter specified at registration.
368 */
369typedef DECLCALLBACK(void) FNVMATDTOR(PVM pVM, void *pvUser);
370/** Pointer to a VM destruction callback. */
371typedef FNVMATDTOR *PFNVMATDTOR;
372
373VMR3DECL(int) VMR3AtDtorRegister(PFNVMATDTOR pfnAtDtor, void *pvUser);
374VMR3DECL(int) VMR3AtDtorDeregister(PFNVMATDTOR pfnAtDtor);
375VMR3DECL(int) VMR3AtResetRegister(PVM pVM, PPDMDEVINS pDevInst, PFNVMATRESET pfnCallback, void *pvUser, const char *pszDesc);
376VMR3DECL(int) VMR3AtResetRegisterInternal(PVM pVM, PFNVMATRESETINT pfnCallback, void *pvUser, const char *pszDesc);
377VMR3DECL(int) VMR3AtResetRegisterExternal(PVM pVM, PFNVMATRESETEXT pfnCallback, void *pvUser, const char *pszDesc);
378VMR3DECL(int) VMR3AtResetDeregister(PVM pVM, PPDMDEVINS pDevInst, PFNVMATRESET pfnCallback);
379VMR3DECL(int) VMR3AtResetDeregisterInternal(PVM pVM, PFNVMATRESETINT pfnCallback);
380VMR3DECL(int) VMR3AtResetDeregisterExternal(PVM pVM, PFNVMATRESETEXT pfnCallback);
381VMR3DECL(int) VMR3AtStateRegister(PVM pVM, PFNVMATSTATE pfnAtState, void *pvUser);
382VMR3DECL(int) VMR3AtStateDeregister(PVM pVM, PFNVMATSTATE pfnAtState, void *pvUser);
383VMR3DECL(VMSTATE) VMR3GetState(PVM pVM);
384VMR3DECL(const char *) VMR3GetStateName(VMSTATE enmState);
385VMR3DECL(int) VMR3AtErrorRegister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
386VMR3DECL(int) VMR3AtErrorRegisterU(PUVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
387VMR3DECL(int) VMR3AtErrorDeregister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
388VMR3DECL(void) VMR3SetErrorWorker(PVM pVM);
389VMR3DECL(int) VMR3AtRuntimeErrorRegister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser);
390VMR3DECL(int) VMR3AtRuntimeErrorDeregister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser);
391VMR3DECL(void) VMR3SetRuntimeErrorWorker(PVM pVM);
392VMR3DECL(int) VMR3ReqCall(PVM pVM, PVMREQ *ppReq, unsigned cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
393VMR3DECL(int) VMR3ReqCallVoidU(PUVM pUVM, PVMREQ *ppReq, unsigned cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
394VMR3DECL(int) VMR3ReqCallVoid(PVM pVM, PVMREQ *ppReq, unsigned cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
395VMR3DECL(int) VMR3ReqCallEx(PVM pVM, PVMREQ *ppReq, unsigned cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
396VMR3DECL(int) VMR3ReqCallU(PUVM pUVM, PVMREQ *ppReq, unsigned cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
397VMR3DECL(int) VMR3ReqCallVU(PUVM pUVM, PVMREQ *ppReq, unsigned cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, va_list Args);
398VMR3DECL(int) VMR3ReqAlloc(PVM pVM, PVMREQ *ppReq, VMREQTYPE enmType);
399VMR3DECL(int) VMR3ReqAllocU(PUVM pUVM, PVMREQ *ppReq, VMREQTYPE enmType);
400VMR3DECL(int) VMR3ReqFree(PVMREQ pReq);
401VMR3DECL(int) VMR3ReqQueue(PVMREQ pReq, unsigned cMillies);
402VMR3DECL(int) VMR3ReqWait(PVMREQ pReq, unsigned cMillies);
403VMR3DECL(int) VMR3ReqProcessU(PUVM pUVM);
404VMR3DECL(void) VMR3NotifyFF(PVM pVM, bool fNotifiedREM);
405VMR3DECL(void) VMR3NotifyFFU(PUVM pUVM, bool fNotifiedREM);
406VMR3DECL(int) VMR3WaitHalted(PVM pVM, bool fIgnoreInterrupts);
407VMR3DECL(int) VMR3WaitU(PUVM pUVM);
408
409/** @} */
410#endif /* IN_RING3 */
411
412
413#ifdef IN_GC
414/** @defgroup grp_vmm_apis_gc VM Guest Context APIs
415 * @ingroup grp_vm
416 * @{ */
417
418/** @} */
419#endif
420
421__END_DECLS
422
423/** @} */
424
425#endif
426
427
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use