VirtualBox

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

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

The Big Sun Rebranding Header Change

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