VirtualBox

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

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

Fixed init problems wrt. VM ownership by implementing the UVM structure (U = user mode) and moving problematic ring-3 stuff over there (emt+reqs, r3heap, stam, loader[VMMR0.r0]). Big change, but it works fine here... :-)

  • 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
207
208/**
209 * Request type.
210 */
211typedef enum VMREQTYPE
212{
213 /** Invalid request. */
214 VMREQTYPE_INVALID = 0,
215 /** VM: Internal. */
216 VMREQTYPE_INTERNAL,
217 /** Maximum request type (exclusive). Used for validation. */
218 VMREQTYPE_MAX
219} VMREQTYPE;
220
221/**
222 * Request state.
223 */
224typedef enum VMREQSTATE
225{
226 /** The state is invalid. */
227 VMREQSTATE_INVALID = 0,
228 /** The request have been allocated and is in the process of being filed. */
229 VMREQSTATE_ALLOCATED,
230 /** The request is queued by the requester. */
231 VMREQSTATE_QUEUED,
232 /** The request is begin processed. */
233 VMREQSTATE_PROCESSING,
234 /** The request is completed, the requester is begin notified. */
235 VMREQSTATE_COMPLETED,
236 /** The request packet is in the free chain. (The requester */
237 VMREQSTATE_FREE
238} VMREQSTATE;
239
240/**
241 * Request flags.
242 */
243typedef enum VMREQFLAGS
244{
245 /** The request returns a VBox status code. */
246 VMREQFLAGS_VBOX_STATUS = 0,
247 /** The request is a void request and have no status code. */
248 VMREQFLAGS_VOID = 1,
249 /** Return type mask. */
250 VMREQFLAGS_RETURN_MASK = 1,
251 /** Caller does not wait on the packet, EMT will free it. */
252 VMREQFLAGS_NO_WAIT = 2
253} VMREQFLAGS;
254
255/**
256 * VM Request packet.
257 *
258 * This is used to request an action in the EMT. Usually the requester is
259 * another thread, but EMT can also end up being the requester in which case
260 * it's carried out synchronously.
261 */
262typedef struct VMREQ
263{
264 /** Pointer to the next request in the chain. */
265 struct VMREQ * volatile pNext;
266 /** Pointer to ring-3 VM structure which this request belongs to. */
267 PUVM pUVM;
268 /** Request state. */
269 volatile VMREQSTATE enmState;
270 /** VBox status code for the completed request. */
271 volatile int iStatus;
272 /** Requester event sem.
273 * The request can use this event semaphore to wait/poll for completion
274 * of the request.
275 */
276 RTSEMEVENT EventSem;
277 /** Set if the event semaphore is clear. */
278 volatile bool fEventSemClear;
279 /** Flags, VMR3REQ_FLAGS_*. */
280 unsigned fFlags;
281 /** Request type. */
282 VMREQTYPE enmType;
283 /** Request specific data. */
284 union VMREQ_U
285 {
286 /** VMREQTYPE_INTERNAL. */
287 struct
288 {
289 /** Pointer to the function to be called. */
290 PFNRT pfn;
291 /** Number of arguments. */
292 unsigned cArgs;
293 /** Array of arguments. */
294 uintptr_t aArgs[64];
295 } Internal;
296 } u;
297} VMREQ;
298/** Pointer to a VM request packet. */
299typedef VMREQ *PVMREQ;
300
301/** @} */
302
303
304#ifndef IN_GC
305/** @defgroup grp_vmm_apis_hc VM Host Context API
306 * @ingroup grp_vm
307 * @{ */
308
309/** @} */
310#endif
311
312
313#ifdef IN_RING3
314/** @defgroup grp_vmm_apis_r3 VM Host Context Ring 3 API
315 * This interface is a _draft_!
316 * @ingroup grp_vm
317 * @{ */
318
319/**
320 * Completion notification codes.
321 */
322typedef enum VMINITCOMPLETED
323{
324 /** The Ring3 init is completed. */
325 VMINITCOMPLETED_RING3 = 1,
326 /** The Ring0 init is completed. */
327 VMINITCOMPLETED_RING0,
328 /** The GC init is completed. */
329 VMINITCOMPLETED_GC
330} VMINITCOMPLETED;
331
332
333VMR3DECL(int) VMR3Create(PFNVMATERROR pfnVMAtError, void *pvUserVM, PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM, PVM *ppVM);
334VMR3DECL(int) VMR3PowerOn(PVM pVM);
335VMR3DECL(int) VMR3Suspend(PVM pVM);
336VMR3DECL(int) VMR3SuspendNoSave(PVM pVM);
337VMR3DECL(int) VMR3Resume(PVM pVM);
338VMR3DECL(int) VMR3Reset(PVM pVM);
339
340/**
341 * Progress callback.
342 * This will report the completion percentage of an operation.
343 *
344 * @returns VINF_SUCCESS.
345 * @returns Error code to cancel the operation with.
346 * @param pVM The VM handle.
347 * @param uPercent Completetion precentage (0-100).
348 * @param pvUser User specified argument.
349 */
350typedef DECLCALLBACK(int) FNVMPROGRESS(PVM pVM, unsigned uPercent, void *pvUser);
351/** Pointer to a FNVMPROGRESS function. */
352typedef FNVMPROGRESS *PFNVMPROGRESS;
353
354VMR3DECL(int) VMR3Save(PVM pVM, const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser);
355VMR3DECL(int) VMR3Load(PVM pVM, const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser);
356VMR3DECL(int) VMR3PowerOff(PVM pVM);
357VMR3DECL(int) VMR3Destroy(PVM pVM);
358VMR3DECL(void) VMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
359VMR3DECL(PVM) VMR3EnumVMs(PVM pVMPrev);
360VMR3DECL(int) VMR3WaitForResume(PVM pVM);
361
362/**
363 * VM destruction callback.
364 * @param pVM The VM which is about to be destroyed.
365 * @param pvUser The user parameter specified at registration.
366 */
367typedef DECLCALLBACK(void) FNVMATDTOR(PVM pVM, void *pvUser);
368/** Pointer to a VM destruction callback. */
369typedef FNVMATDTOR *PFNVMATDTOR;
370
371VMR3DECL(int) VMR3AtDtorRegister(PFNVMATDTOR pfnAtDtor, void *pvUser);
372VMR3DECL(int) VMR3AtDtorDeregister(PFNVMATDTOR pfnAtDtor);
373VMR3DECL(int) VMR3AtResetRegister(PVM pVM, PPDMDEVINS pDevInst, PFNVMATRESET pfnCallback, void *pvUser, const char *pszDesc);
374VMR3DECL(int) VMR3AtResetRegisterInternal(PVM pVM, PFNVMATRESETINT pfnCallback, void *pvUser, const char *pszDesc);
375VMR3DECL(int) VMR3AtResetRegisterExternal(PVM pVM, PFNVMATRESETEXT pfnCallback, void *pvUser, const char *pszDesc);
376VMR3DECL(int) VMR3AtResetDeregister(PVM pVM, PPDMDEVINS pDevInst, PFNVMATRESET pfnCallback);
377VMR3DECL(int) VMR3AtResetDeregisterInternal(PVM pVM, PFNVMATRESETINT pfnCallback);
378VMR3DECL(int) VMR3AtResetDeregisterExternal(PVM pVM, PFNVMATRESETEXT pfnCallback);
379VMR3DECL(int) VMR3AtStateRegister(PVM pVM, PFNVMATSTATE pfnAtState, void *pvUser);
380VMR3DECL(int) VMR3AtStateDeregister(PVM pVM, PFNVMATSTATE pfnAtState, void *pvUser);
381VMR3DECL(VMSTATE) VMR3GetState(PVM pVM);
382VMR3DECL(const char *) VMR3GetStateName(VMSTATE enmState);
383VMR3DECL(int) VMR3AtErrorRegister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
384VMR3DECL(int) VMR3AtErrorRegisterU(PUVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
385VMR3DECL(int) VMR3AtErrorDeregister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
386VMR3DECL(void) VMR3SetErrorWorker(PVM pVM);
387VMR3DECL(int) VMR3AtRuntimeErrorRegister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser);
388VMR3DECL(int) VMR3AtRuntimeErrorDeregister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser);
389VMR3DECL(void) VMR3SetRuntimeErrorWorker(PVM pVM);
390VMR3DECL(int) VMR3ReqCall(PVM pVM, PVMREQ *ppReq, unsigned cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
391VMR3DECL(int) VMR3ReqCallVoidU(PUVM pUVM, PVMREQ *ppReq, unsigned cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
392VMR3DECL(int) VMR3ReqCallVoid(PVM pVM, PVMREQ *ppReq, unsigned cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
393VMR3DECL(int) VMR3ReqCallEx(PVM pVM, PVMREQ *ppReq, unsigned cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
394VMR3DECL(int) VMR3ReqCallU(PUVM pUVM, PVMREQ *ppReq, unsigned cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
395VMR3DECL(int) VMR3ReqCallVU(PUVM pUVM, PVMREQ *ppReq, unsigned cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, va_list Args);
396VMR3DECL(int) VMR3ReqAlloc(PVM pVM, PVMREQ *ppReq, VMREQTYPE enmType);
397VMR3DECL(int) VMR3ReqAllocU(PUVM pUVM, PVMREQ *ppReq, VMREQTYPE enmType);
398VMR3DECL(int) VMR3ReqFree(PVMREQ pReq);
399VMR3DECL(int) VMR3ReqQueue(PVMREQ pReq, unsigned cMillies);
400VMR3DECL(int) VMR3ReqWait(PVMREQ pReq, unsigned cMillies);
401VMR3DECL(int) VMR3ReqProcessU(PUVM pUVM);
402VMR3DECL(void) VMR3NotifyFF(PVM pVM, bool fNotifiedREM);
403VMR3DECL(void) VMR3NotifyFFU(PUVM pUVM, bool fNotifiedREM);
404VMR3DECL(int) VMR3WaitHalted(PVM pVM, bool fIgnoreInterrupts);
405VMR3DECL(int) VMR3WaitU(PUVM pUVM);
406
407/** @} */
408#endif /* IN_RING3 */
409
410
411#ifdef IN_GC
412/** @defgroup grp_vmm_apis_gc VM Guest Context APIs
413 * @ingroup grp_vm
414 * @{ */
415
416/** @} */
417#endif
418
419__END_DECLS
420
421/** @} */
422
423#endif
424
425
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