VirtualBox

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

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

Started with VM request API changes.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette