VirtualBox

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

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

vmapi: Removed unused & deprecated macro VM_HOST_ADDR.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use