VirtualBox

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

Last change on this file since 7133 was 7133, checked in by vboxsync, 17 years ago

Eliminate cpum.h dependency (shuts up a bunch of .c warnings). Fixed the header tests.

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