VirtualBox

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

Last change on this file since 32287 was 32190, checked in by vboxsync, 14 years ago

PDMDevHlpVMSuspendSaveAndPowerOff: More code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.5 KB
Line 
1/** @file
2 * VM - The Virtual Machine, API. (VMM)
3 */
4
5/*
6 * Copyright (C) 2006-2007 Oracle Corporation
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
36RT_C_DECLS_BEGIN
37
38/** @defgroup grp_vmm_apis VM All Contexts API
39 * @ingroup grp_vm
40 * @{ */
41
42/** @def VM_RC_ADDR
43 * Converts a current context address of data within the VM structure to the equivalent
44 * raw-mode address.
45 *
46 * @returns raw-mode 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_RC_ADDR(pVM, pvInVM) ( (RTRCPTR)((RTRCUINTPTR)pVM->pVMRC + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMR3)) )
52#elif defined(IN_RING0)
53# define VM_RC_ADDR(pVM, pvInVM) ( (RTRCPTR)((RTRCUINTPTR)pVM->pVMRC + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMR0)) )
54#else
55# define VM_RC_ADDR(pVM, pvInVM) ( (RTRCPTR)(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_RC
67# define VM_R3_ADDR(pVM, pvInVM) ( (RTR3PTR)((RTR3UINTPTR)pVM->pVMR3 + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMRC)) )
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_RC
84# define VM_R0_ADDR(pVM, pvInVM) ( (RTR0PTR)((RTR0UINTPTR)pVM->pVMR0 + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMRC)) )
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
92
93/**
94 * VM error callback function.
95 *
96 * @param pVM The VM handle. Can be NULL if an error occurred before
97 * successfully creating a VM.
98 * @param pvUser The user argument.
99 * @param rc VBox status code.
100 * @param RT_SRC_POS_DECL The source position arguments. See RT_SRC_POS and RT_SRC_POS_ARGS.
101 * @param pszFormat Error message format string.
102 * @param args Error message arguments.
103 */
104typedef DECLCALLBACK(void) FNVMATERROR(PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszError, va_list args);
105/** Pointer to a VM error callback. */
106typedef FNVMATERROR *PFNVMATERROR;
107
108VMMDECL(int) VMSetError(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...);
109VMMDECL(int) VMSetErrorV(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list args);
110
111/** @def VM_SET_ERROR
112 * Macro for setting a simple VM error message.
113 * Don't use '%' in the message!
114 *
115 * @returns rc. Meaning you can do:
116 * @code
117 * return VM_SET_ERROR(pVM, VERR_OF_YOUR_CHOICE, "descriptive message");
118 * @endcode
119 * @param pVM VM handle.
120 * @param rc VBox status code.
121 * @param pszMessage Error message string.
122 * @thread Any
123 */
124#define VM_SET_ERROR(pVM, rc, pszMessage) (VMSetError(pVM, rc, RT_SRC_POS, pszMessage))
125
126
127/**
128 * VM runtime error callback function.
129 *
130 * See VMSetRuntimeError for the detailed description of parameters.
131 *
132 * @param pVM The VM handle.
133 * @param pvUser The user argument.
134 * @param fFlags The error flags.
135 * @param pszErrorId Error ID string.
136 * @param pszFormat Error message format string.
137 * @param va Error message arguments.
138 */
139typedef DECLCALLBACK(void) FNVMATRUNTIMEERROR(PVM pVM, void *pvUser, uint32_t fFlags, const char *pszErrorId,
140 const char *pszFormat, va_list va);
141/** Pointer to a VM runtime error callback. */
142typedef FNVMATRUNTIMEERROR *PFNVMATRUNTIMEERROR;
143
144VMMDECL(int) VMSetRuntimeError(PVM pVM, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...);
145VMMDECL(int) VMSetRuntimeErrorV(PVM pVM, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list args);
146
147/** @name VMSetRuntimeError fFlags
148 * When no flags are given the VM will continue running and it's up to the front
149 * end to take action on the error condition.
150 *
151 * @{ */
152/** The error is fatal.
153 * The VM is not in a state where it can be saved and will enter a state
154 * where it can no longer execute code. The caller <b>must</b> propagate status
155 * codes. */
156#define VMSETRTERR_FLAGS_FATAL RT_BIT_32(0)
157/** Suspend the VM after, or if possible before, raising the error on EMT. The
158 * caller <b>must</b> propagate status codes. */
159#define VMSETRTERR_FLAGS_SUSPEND RT_BIT_32(1)
160/** Don't wait for the EMT to handle the request.
161 * Only valid when on a worker thread and there is a high risk of a dead
162 * lock. Be careful not to flood the user with errors. */
163#define VMSETRTERR_FLAGS_NO_WAIT RT_BIT_32(2)
164/** @} */
165
166/**
167 * VM state callback function.
168 *
169 * You are not allowed to call any function which changes the VM state from a
170 * state callback, except VMR3Destroy().
171 *
172 * @param pVM The VM handle.
173 * @param enmState The new state.
174 * @param enmOldState The old state.
175 * @param pvUser The user argument.
176 */
177typedef DECLCALLBACK(void) FNVMATSTATE(PVM pVM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
178/** Pointer to a VM state callback. */
179typedef FNVMATSTATE *PFNVMATSTATE;
180
181VMMDECL(const char *) VMGetStateName(VMSTATE enmState);
182
183
184/**
185 * Request type.
186 */
187typedef enum VMREQTYPE
188{
189 /** Invalid request. */
190 VMREQTYPE_INVALID = 0,
191 /** VM: Internal. */
192 VMREQTYPE_INTERNAL,
193 /** Maximum request type (exclusive). Used for validation. */
194 VMREQTYPE_MAX
195} VMREQTYPE;
196
197/**
198 * Request state.
199 */
200typedef enum VMREQSTATE
201{
202 /** The state is invalid. */
203 VMREQSTATE_INVALID = 0,
204 /** The request have been allocated and is in the process of being filed. */
205 VMREQSTATE_ALLOCATED,
206 /** The request is queued by the requester. */
207 VMREQSTATE_QUEUED,
208 /** The request is begin processed. */
209 VMREQSTATE_PROCESSING,
210 /** The request is completed, the requester is begin notified. */
211 VMREQSTATE_COMPLETED,
212 /** The request packet is in the free chain. (The requester */
213 VMREQSTATE_FREE
214} VMREQSTATE;
215
216/**
217 * Request flags.
218 */
219typedef enum VMREQFLAGS
220{
221 /** The request returns a VBox status code. */
222 VMREQFLAGS_VBOX_STATUS = 0,
223 /** The request is a void request and have no status code. */
224 VMREQFLAGS_VOID = 1,
225 /** Return type mask. */
226 VMREQFLAGS_RETURN_MASK = 1,
227 /** Caller does not wait on the packet, EMT will free it. */
228 VMREQFLAGS_NO_WAIT = 2,
229 /** Poke the destination EMT(s) if executing guest code. Use with care. */
230 VMREQFLAGS_POKE = 4
231} VMREQFLAGS;
232
233
234/**
235 * VM Request packet.
236 *
237 * This is used to request an action in the EMT. Usually the requester is
238 * another thread, but EMT can also end up being the requester in which case
239 * it's carried out synchronously.
240 */
241typedef struct VMREQ
242{
243 /** Pointer to the next request in the chain. */
244 struct VMREQ * volatile pNext;
245 /** Pointer to ring-3 VM structure which this request belongs to. */
246 PUVM pUVM;
247 /** Request state. */
248 volatile VMREQSTATE enmState;
249 /** VBox status code for the completed request. */
250 volatile int iStatus;
251 /** Requester event sem.
252 * The request can use this event semaphore to wait/poll for completion
253 * of the request.
254 */
255 RTSEMEVENT EventSem;
256 /** Set if the event semaphore is clear. */
257 volatile bool fEventSemClear;
258 /** Flags, VMR3REQ_FLAGS_*. */
259 unsigned fFlags;
260 /** Request type. */
261 VMREQTYPE enmType;
262 /** Request destination. */
263 VMCPUID idDstCpu;
264 /** Request specific data. */
265 union VMREQ_U
266 {
267 /** VMREQTYPE_INTERNAL. */
268 struct
269 {
270 /** Pointer to the function to be called. */
271 PFNRT pfn;
272 /** Number of arguments. */
273 unsigned cArgs;
274 /** Array of arguments. */
275 uintptr_t aArgs[64];
276 } Internal;
277 } u;
278} VMREQ;
279/** Pointer to a VM request packet. */
280typedef VMREQ *PVMREQ;
281
282/** @} */
283
284
285#ifndef IN_RC
286/** @defgroup grp_vmm_apis_hc VM Host Context API
287 * @ingroup grp_vm
288 * @{ */
289
290/** @} */
291#endif
292
293
294#ifdef IN_RING3
295/** @defgroup grp_vmm_apis_r3 VM Host Context Ring 3 API
296 * This interface is a _draft_!
297 * @ingroup grp_vm
298 * @{ */
299
300/**
301 * Completion notification codes.
302 */
303typedef enum VMINITCOMPLETED
304{
305 /** The Ring3 init is completed. */
306 VMINITCOMPLETED_RING3 = 1,
307 /** The Ring0 init is completed. */
308 VMINITCOMPLETED_RING0,
309 /** The GC init is completed. */
310 VMINITCOMPLETED_GC
311} VMINITCOMPLETED;
312
313
314VMMR3DECL(int) VMR3Create(uint32_t cCpus, PCVMM2USERMETHODS pVm2UserCbs,
315 PFNVMATERROR pfnVMAtError, void *pvUserVM,
316 PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM,
317 PVM *ppVM);
318VMMR3DECL(int) VMR3PowerOn(PVM pVM);
319VMMR3DECL(int) VMR3Suspend(PVM pVM);
320VMMR3DECL(int) VMR3Resume(PVM pVM);
321VMMR3DECL(int) VMR3Reset(PVM pVM);
322
323/**
324 * Progress callback.
325 * This will report the completion percentage of an operation.
326 *
327 * @returns VINF_SUCCESS.
328 * @returns Error code to cancel the operation with.
329 * @param pVM The VM handle.
330 * @param uPercent Completetion precentage (0-100).
331 * @param pvUser User specified argument.
332 */
333typedef DECLCALLBACK(int) FNVMPROGRESS(PVM pVM, unsigned uPercent, void *pvUser);
334/** Pointer to a FNVMPROGRESS function. */
335typedef FNVMPROGRESS *PFNVMPROGRESS;
336
337VMMR3DECL(int) VMR3Save(PVM pVM, const char *pszFilename, bool fContinueAfterwards, PFNVMPROGRESS pfnProgress, void *pvUser, bool *pfSuspended);
338VMMR3DECL(int) VMR3Teleport(PVM pVM, uint32_t cMsDowntime, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser, PFNVMPROGRESS pfnProgress, void *pvProgressUser, bool *pfSuspended);
339VMMR3DECL(int) VMR3LoadFromFile(PVM pVM, const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser);
340VMMR3DECL(int) VMR3LoadFromStream(PVM pVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
341 PFNVMPROGRESS pfnProgress, void *pvProgressUser);
342VMMR3DECL(int) VMR3PowerOff(PVM pVM);
343VMMR3DECL(int) VMR3Destroy(PVM pVM);
344VMMR3DECL(void) VMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
345VMMR3DECL(PVM) VMR3EnumVMs(PVM pVMPrev);
346
347/**
348 * VM destruction callback.
349 * @param pVM The VM which is about to be destroyed.
350 * @param pvUser The user parameter specified at registration.
351 */
352typedef DECLCALLBACK(void) FNVMATDTOR(PVM pVM, void *pvUser);
353/** Pointer to a VM destruction callback. */
354typedef FNVMATDTOR *PFNVMATDTOR;
355
356VMMR3DECL(int) VMR3AtDtorRegister(PFNVMATDTOR pfnAtDtor, void *pvUser);
357VMMR3DECL(int) VMR3AtDtorDeregister(PFNVMATDTOR pfnAtDtor);
358VMMR3DECL(int) VMR3AtStateRegister(PVM pVM, PFNVMATSTATE pfnAtState, void *pvUser);
359VMMR3DECL(int) VMR3AtStateDeregister(PVM pVM, PFNVMATSTATE pfnAtState, void *pvUser);
360VMMR3DECL(VMSTATE) VMR3GetState(PVM pVM);
361VMMR3DECL(const char *) VMR3GetStateName(VMSTATE enmState);
362VMMR3DECL(bool) VMR3TeleportedAndNotFullyResumedYet(PVM pVM);
363VMMR3DECL(int) VMR3AtErrorRegister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
364VMMR3DECL(int) VMR3AtErrorRegisterU(PUVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
365VMMR3DECL(int) VMR3AtErrorDeregister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
366VMMR3DECL(void) VMR3SetErrorWorker(PVM pVM);
367VMMR3DECL(uint32_t) VMR3GetErrorCount(PVM pVM);
368VMMR3DECL(int) VMR3AtRuntimeErrorRegister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser);
369VMMR3DECL(int) VMR3AtRuntimeErrorDeregister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser);
370VMMR3DECL(int) VMR3SetRuntimeErrorWorker(PVM pVM);
371VMMR3DECL(uint32_t) VMR3GetRuntimeErrorCount(PVM pVM);
372VMMR3DECL(int) VMR3ReqCall(PVM pVM, VMCPUID idDstCpu, PVMREQ *ppReq, RTMSINTERVAL cMillies, uint32_t fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
373VMMR3DECL(int) VMR3ReqCallU(PUVM pUVM, VMCPUID idDstCpu, PVMREQ *ppReq, RTMSINTERVAL cMillies, uint32_t fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
374VMMR3DECL(int) VMR3ReqCallVU(PUVM pUVM, VMCPUID idDstCpu, PVMREQ *ppReq, RTMSINTERVAL cMillies, uint32_t fFlags, PFNRT pfnFunction, unsigned cArgs, va_list Args);
375VMMR3DECL(int) VMR3ReqCallWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
376VMMR3DECL(int) VMR3ReqCallWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
377VMMR3DECL(int) VMR3ReqCallNoWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
378VMMR3DECL(int) VMR3ReqCallNoWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
379VMMR3DECL(int) VMR3ReqCallVoidWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
380VMMR3DECL(int) VMR3ReqCallVoidWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
381VMMR3DECL(int) VMR3ReqCallVoidNoWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
382VMMR3DECL(int) VMR3ReqCallVoidNoWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
383VMMR3DECL(int) VMR3ReqAlloc(PVM pVM, PVMREQ *ppReq, VMREQTYPE enmType, VMCPUID idDstCpu);
384VMMR3DECL(int) VMR3ReqAllocU(PUVM pUVM, PVMREQ *ppReq, VMREQTYPE enmType, VMCPUID idDstCpu);
385VMMR3DECL(int) VMR3ReqFree(PVMREQ pReq);
386VMMR3DECL(int) VMR3ReqQueue(PVMREQ pReq, RTMSINTERVAL cMillies);
387VMMR3DECL(int) VMR3ReqWait(PVMREQ pReq, RTMSINTERVAL cMillies);
388VMMR3DECL(int) VMR3ReqProcessU(PUVM pUVM, VMCPUID idDstCpu);
389VMMR3DECL(void) VMR3NotifyGlobalFFU(PUVM pUVM, uint32_t fFlags);
390VMMR3DECL(void) VMR3NotifyCpuFFU(PUVMCPU pUVMCpu, uint32_t fFlags);
391/** @name Flags for VMR3NotifyCpuFFU and VMR3NotifyGlobalFFU.
392 * @{ */
393/** Whether we've done REM or not. */
394#define VMNOTIFYFF_FLAGS_DONE_REM RT_BIT_32(0)
395/** Whether we should poke the CPU if it's executing guest code. */
396#define VMNOTIFYFF_FLAGS_POKE RT_BIT_32(1)
397/** @} */
398
399VMMR3DECL(int) VMR3WaitHalted(PVM pVM, PVMCPU pVCpu, bool fIgnoreInterrupts);
400VMMR3DECL(int) VMR3WaitU(PUVMCPU pUVMCpu);
401VMMR3_INT_DECL(int) VMR3AsyncPdmNotificationWaitU(PUVMCPU pUVCpu);
402VMMR3_INT_DECL(void) VMR3AsyncPdmNotificationWakeupU(PUVM pUVM);
403VMMR3DECL(RTCPUID) VMR3GetVMCPUId(PVM pVM);
404VMMR3DECL(RTTHREAD) VMR3GetVMCPUThread(PVM pVM);
405VMMR3DECL(RTTHREAD) VMR3GetVMCPUThreadU(PUVM pUVM);
406VMMR3DECL(RTNATIVETHREAD) VMR3GetVMCPUNativeThread(PVM pVM);
407VMMR3DECL(RTNATIVETHREAD) VMR3GetVMCPUNativeThreadU(PUVM pUVM);
408VMMR3DECL(int) VMR3GetCpuCoreAndPackageIdFromCpuId(PVM pVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage);
409VMMR3DECL(int) VMR3HotUnplugCpu(PVM pVM, VMCPUID idCpu);
410VMMR3DECL(int) VMR3HotPlugCpu(PVM pVM, VMCPUID idCpu);
411VMMR3DECL(int) VMR3SetCpuPriority(PVM pVM, unsigned ulCpuPriority);
412/** @} */
413#endif /* IN_RING3 */
414
415
416#ifdef IN_RC
417/** @defgroup grp_vmm_apis_gc VM Guest Context APIs
418 * @ingroup grp_vm
419 * @{ */
420
421/** @} */
422#endif
423
424RT_C_DECLS_END
425
426/** @} */
427
428#endif
429
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