VirtualBox

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

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

vmapi.h: VMREQDEST_FROM_VMCPU

  • 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.
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_RC_ADDR
47 * Converts a current context address of data within the VM structure to the equivalent
48 * raw-mode address.
49 *
50 * @returns raw-mode 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_RC_ADDR(pVM, pvInVM) ( (RTRCPTR)((RTRCUINTPTR)pVM->pVMRC + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMR3)) )
56#elif defined(IN_RING0)
57# define VM_RC_ADDR(pVM, pvInVM) ( (RTRCPTR)((RTRCUINTPTR)pVM->pVMRC + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMR0)) )
58#else
59# define VM_RC_ADDR(pVM, pvInVM) ( (RTRCPTR)(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_RC
71# define VM_R3_ADDR(pVM, pvInVM) ( (RTR3PTR)((RTR3UINTPTR)pVM->pVMR3 + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMRC)) )
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_RC
88# define VM_R0_ADDR(pVM, pvInVM) ( (RTR0PTR)((RTR0UINTPTR)pVM->pVMR0 + (uint32_t)((uintptr_t)(pvInVM) - (uintptr_t)pVM->pVMRC)) )
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
112VMMDECL(int) VMSetError(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...);
113VMMDECL(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 *
134 * See VMSetRuntimeError for the detailed description of parameters.
135 *
136 * @param pVM The VM handle.
137 * @param pvUser The user argument.
138 * @param fFlags The error flags.
139 * @param pszErrorId Error ID string.
140 * @param pszFormat Error message format string.
141 * @param va Error message arguments.
142 */
143typedef DECLCALLBACK(void) FNVMATRUNTIMEERROR(PVM pVM, void *pvUser, uint32_t fFlags, const char *pszErrorId,
144 const char *pszFormat, va_list va);
145/** Pointer to a VM runtime error callback. */
146typedef FNVMATRUNTIMEERROR *PFNVMATRUNTIMEERROR;
147
148VMMDECL(int) VMSetRuntimeError(PVM pVM, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...);
149VMMDECL(int) VMSetRuntimeErrorV(PVM pVM, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list args);
150
151/** @name VMSetRuntimeError fFlags
152 * When no flags are given the VM will continue running and it's up to the front
153 * end to take action on the error condition.
154 *
155 * @{ */
156/** The error is fatal.
157 * The VM is not in a state where it can be saved and will enter a state
158 * where it can no longer execute code. The caller <b>must</b> propagate status
159 * codes. */
160#define VMSETRTERR_FLAGS_FATAL RT_BIT_32(0)
161/** Suspend the VM after, or if possible before, raising the error on EMT. The
162 * caller <b>must</b> propagate status codes. */
163#define VMSETRTERR_FLAGS_SUSPEND RT_BIT_32(1)
164/** Don't wait for the EMT to handle the request.
165 * Only valid when on a worker thread and there is a high risk of a dead
166 * lock. Be careful not to flood the user with errors. */
167#define VMSETRTERR_FLAGS_NO_WAIT RT_BIT_32(2)
168/** @} */
169
170
171/**
172 * VM reset callback.
173 *
174 * @returns VBox status code.
175 * @param pDevInst Device instance of the device which registered the callback.
176 * @param pvUser User argument.
177 */
178typedef DECLCALLBACK(int) FNVMATRESET(PPDMDEVINS pDevInst, void *pvUser);
179/** VM reset callback. */
180typedef FNVMATRESET *PFNVMATRESET;
181
182/**
183 * VM reset internal callback.
184 *
185 * @returns VBox status code.
186 * @param pVM The VM which is begin reset.
187 * @param pvUser User argument.
188 */
189typedef DECLCALLBACK(int) FNVMATRESETINT(PVM pVM, void *pvUser);
190/** VM reset internal callback. */
191typedef FNVMATRESETINT *PFNVMATRESETINT;
192
193/**
194 * VM reset external callback.
195 *
196 * @param pvUser User argument.
197 */
198typedef DECLCALLBACK(void) FNVMATRESETEXT(void *pvUser);
199/** VM reset external callback. */
200typedef FNVMATRESETEXT *PFNVMATRESETEXT;
201
202
203/**
204 * VM state callback function.
205 *
206 * You are not allowed to call any function which changes the VM state from a
207 * state callback, except VMR3Destroy().
208 *
209 * @param pVM The VM handle.
210 * @param enmState The new state.
211 * @param enmOldState The old state.
212 * @param pvUser The user argument.
213 */
214typedef DECLCALLBACK(void) FNVMATSTATE(PVM pVM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
215/** Pointer to a VM state callback. */
216typedef FNVMATSTATE *PFNVMATSTATE;
217
218VMMDECL(const char *) VMGetStateName(VMSTATE enmState);
219
220
221/**
222 * Request type.
223 */
224typedef enum VMREQTYPE
225{
226 /** Invalid request. */
227 VMREQTYPE_INVALID = 0,
228 /** VM: Internal. */
229 VMREQTYPE_INTERNAL,
230 /** Maximum request type (exclusive). Used for validation. */
231 VMREQTYPE_MAX
232} VMREQTYPE;
233
234/**
235 * Request state.
236 */
237typedef enum VMREQSTATE
238{
239 /** The state is invalid. */
240 VMREQSTATE_INVALID = 0,
241 /** The request have been allocated and is in the process of being filed. */
242 VMREQSTATE_ALLOCATED,
243 /** The request is queued by the requester. */
244 VMREQSTATE_QUEUED,
245 /** The request is begin processed. */
246 VMREQSTATE_PROCESSING,
247 /** The request is completed, the requester is begin notified. */
248 VMREQSTATE_COMPLETED,
249 /** The request packet is in the free chain. (The requester */
250 VMREQSTATE_FREE
251} VMREQSTATE;
252
253/**
254 * Request flags.
255 */
256typedef enum VMREQFLAGS
257{
258 /** The request returns a VBox status code. */
259 VMREQFLAGS_VBOX_STATUS = 0,
260 /** The request is a void request and have no status code. */
261 VMREQFLAGS_VOID = 1,
262 /** Return type mask. */
263 VMREQFLAGS_RETURN_MASK = 1,
264 /** Caller does not wait on the packet, EMT will free it. */
265 VMREQFLAGS_NO_WAIT = 2
266} VMREQFLAGS;
267
268/**
269 * Request destination
270 */
271typedef enum VMREQDEST
272{
273 /** Request packet for VCPU 0. */
274 VMREQDEST_CPU0 = 0,
275
276 /** Request packet for all VMCPU threads. */
277 VMREQDEST_BROADCAST = 0x1000,
278
279 /** Request packet for any VMCPU thread. */
280 VMREQDEST_ANY = 0x1001
281} VMREQDEST;
282
283/** Makes a VMREQDEST value from a VMCPU pointer. */
284#define VMREQDEST_FROM_VMCPU(pVCpu) ((VMREQDEST)(pVCpu)->idCpu)
285
286
287/**
288 * VM Request packet.
289 *
290 * This is used to request an action in the EMT. Usually the requester is
291 * another thread, but EMT can also end up being the requester in which case
292 * it's carried out synchronously.
293 */
294typedef struct VMREQ
295{
296 /** Pointer to the next request in the chain. */
297 struct VMREQ * volatile pNext;
298 /** Pointer to ring-3 VM structure which this request belongs to. */
299 PUVM pUVM;
300 /** Request state. */
301 volatile VMREQSTATE enmState;
302 /** VBox status code for the completed request. */
303 volatile int iStatus;
304 /** Requester event sem.
305 * The request can use this event semaphore to wait/poll for completion
306 * of the request.
307 */
308 RTSEMEVENT EventSem;
309 /** Set if the event semaphore is clear. */
310 volatile bool fEventSemClear;
311 /** Flags, VMR3REQ_FLAGS_*. */
312 unsigned fFlags;
313 /** Request type. */
314 VMREQTYPE enmType;
315 /** Request destination. */
316 VMREQDEST enmDest;
317 /** Request specific data. */
318 union VMREQ_U
319 {
320 /** VMREQTYPE_INTERNAL. */
321 struct
322 {
323 /** Pointer to the function to be called. */
324 PFNRT pfn;
325 /** Number of arguments. */
326 unsigned cArgs;
327 /** Array of arguments. */
328 uintptr_t aArgs[64];
329 } Internal;
330 } u;
331} VMREQ;
332/** Pointer to a VM request packet. */
333typedef VMREQ *PVMREQ;
334
335/** @} */
336
337
338#ifndef IN_RC
339/** @defgroup grp_vmm_apis_hc VM Host Context API
340 * @ingroup grp_vm
341 * @{ */
342
343/** @} */
344#endif
345
346
347#ifdef IN_RING3
348/** @defgroup grp_vmm_apis_r3 VM Host Context Ring 3 API
349 * This interface is a _draft_!
350 * @ingroup grp_vm
351 * @{ */
352
353/**
354 * Completion notification codes.
355 */
356typedef enum VMINITCOMPLETED
357{
358 /** The Ring3 init is completed. */
359 VMINITCOMPLETED_RING3 = 1,
360 /** The Ring0 init is completed. */
361 VMINITCOMPLETED_RING0,
362 /** The GC init is completed. */
363 VMINITCOMPLETED_GC
364} VMINITCOMPLETED;
365
366
367VMMR3DECL(int) VMR3Create(uint32_t cCPUs, PFNVMATERROR pfnVMAtError, void *pvUserVM, PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM, PVM *ppVM);
368VMMR3DECL(int) VMR3PowerOn(PVM pVM);
369VMMR3DECL(int) VMR3Suspend(PVM pVM);
370VMMR3DECL(int) VMR3SuspendNoSave(PVM pVM);
371VMMR3DECL(int) VMR3Resume(PVM pVM);
372VMMR3DECL(int) VMR3Reset(PVM pVM);
373
374/**
375 * Progress callback.
376 * This will report the completion percentage of an operation.
377 *
378 * @returns VINF_SUCCESS.
379 * @returns Error code to cancel the operation with.
380 * @param pVM The VM handle.
381 * @param uPercent Completetion precentage (0-100).
382 * @param pvUser User specified argument.
383 */
384typedef DECLCALLBACK(int) FNVMPROGRESS(PVM pVM, unsigned uPercent, void *pvUser);
385/** Pointer to a FNVMPROGRESS function. */
386typedef FNVMPROGRESS *PFNVMPROGRESS;
387
388VMMR3DECL(int) VMR3Save(PVM pVM, const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser);
389VMMR3DECL(int) VMR3Load(PVM pVM, const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser);
390VMMR3DECL(int) VMR3PowerOff(PVM pVM);
391VMMR3DECL(int) VMR3Destroy(PVM pVM);
392VMMR3DECL(void) VMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
393VMMR3DECL(PVM) VMR3EnumVMs(PVM pVMPrev);
394VMMR3DECL(int) VMR3WaitForResume(PVM pVM);
395
396/**
397 * VM destruction callback.
398 * @param pVM The VM which is about to be destroyed.
399 * @param pvUser The user parameter specified at registration.
400 */
401typedef DECLCALLBACK(void) FNVMATDTOR(PVM pVM, void *pvUser);
402/** Pointer to a VM destruction callback. */
403typedef FNVMATDTOR *PFNVMATDTOR;
404
405VMMR3DECL(int) VMR3AtDtorRegister(PFNVMATDTOR pfnAtDtor, void *pvUser);
406VMMR3DECL(int) VMR3AtDtorDeregister(PFNVMATDTOR pfnAtDtor);
407VMMR3DECL(int) VMR3AtResetRegister(PVM pVM, PPDMDEVINS pDevInst, PFNVMATRESET pfnCallback, void *pvUser, const char *pszDesc);
408VMMR3DECL(int) VMR3AtResetRegisterInternal(PVM pVM, PFNVMATRESETINT pfnCallback, void *pvUser, const char *pszDesc);
409VMMR3DECL(int) VMR3AtResetRegisterExternal(PVM pVM, PFNVMATRESETEXT pfnCallback, void *pvUser, const char *pszDesc);
410VMMR3DECL(int) VMR3AtResetDeregister(PVM pVM, PPDMDEVINS pDevInst, PFNVMATRESET pfnCallback);
411VMMR3DECL(int) VMR3AtResetDeregisterInternal(PVM pVM, PFNVMATRESETINT pfnCallback);
412VMMR3DECL(int) VMR3AtResetDeregisterExternal(PVM pVM, PFNVMATRESETEXT pfnCallback);
413VMMR3DECL(int) VMR3AtStateRegister(PVM pVM, PFNVMATSTATE pfnAtState, void *pvUser);
414VMMR3DECL(int) VMR3AtStateDeregister(PVM pVM, PFNVMATSTATE pfnAtState, void *pvUser);
415VMMR3DECL(VMSTATE) VMR3GetState(PVM pVM);
416VMMR3DECL(const char *) VMR3GetStateName(VMSTATE enmState);
417VMMR3DECL(int) VMR3AtErrorRegister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
418VMMR3DECL(int) VMR3AtErrorRegisterU(PUVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
419VMMR3DECL(int) VMR3AtErrorDeregister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
420VMMR3DECL(void) VMR3SetErrorWorker(PVM pVM);
421VMMR3DECL(int) VMR3AtRuntimeErrorRegister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser);
422VMMR3DECL(int) VMR3AtRuntimeErrorDeregister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser);
423VMMR3DECL(int) VMR3SetRuntimeErrorWorker(PVM pVM);
424VMMR3DECL(int) VMR3ReqCall(PVM pVM, VMREQDEST enmDest, PVMREQ *ppReq, unsigned cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
425VMMR3DECL(int) VMR3ReqCallVoidU(PUVM pUVM, VMREQDEST enmDest, PVMREQ *ppReq, unsigned cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
426VMMR3DECL(int) VMR3ReqCallVoid(PVM pVM, VMREQDEST enmDest, PVMREQ *ppReq, unsigned cMillies, PFNRT pfnFunction, unsigned cArgs, ...);
427VMMR3DECL(int) VMR3ReqCallEx(PVM pVM, VMREQDEST enmDest, PVMREQ *ppReq, unsigned cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
428VMMR3DECL(int) VMR3ReqCallU(PUVM pUVM, VMREQDEST enmDest, PVMREQ *ppReq, unsigned cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
429VMMR3DECL(int) VMR3ReqCallVU(PUVM pUVM, VMREQDEST enmDest, PVMREQ *ppReq, unsigned cMillies, unsigned fFlags, PFNRT pfnFunction, unsigned cArgs, va_list Args);
430VMMR3DECL(int) VMR3ReqAlloc(PVM pVM, PVMREQ *ppReq, VMREQTYPE enmType, VMREQDEST enmDest);
431VMMR3DECL(int) VMR3ReqAllocU(PUVM pUVM, PVMREQ *ppReq, VMREQTYPE enmType, VMREQDEST enmDest);
432VMMR3DECL(int) VMR3ReqFree(PVMREQ pReq);
433VMMR3DECL(int) VMR3ReqQueue(PVMREQ pReq, unsigned cMillies);
434VMMR3DECL(int) VMR3ReqWait(PVMREQ pReq, unsigned cMillies);
435VMMR3DECL(int) VMR3ReqProcessU(PUVM pUVM, VMREQDEST enmDest);
436VMMR3DECL(void) VMR3NotifyFF(PVM pVM, bool fNotifiedREM);
437VMMR3DECL(void) VMR3NotifyFFU(PUVM pUVM, bool fNotifiedREM);
438VMMR3DECL(int) VMR3WaitHalted(PVM pVM, PVMCPU pVCpu, bool fIgnoreInterrupts);
439VMMR3DECL(int) VMR3WaitU(PUVM pUVM);
440VMMR3DECL(RTCPUID) VMR3GetVMCPUId(PVM pVM);
441VMMR3DECL(RTTHREAD) VMR3GetVMCPUThread(PVM pVM);
442VMMR3DECL(RTTHREAD) VMR3GetVMCPUThreadU(PUVM pUVM);
443VMMR3DECL(RTNATIVETHREAD) VMR3GetVMCPUNativeThread(PVM pVM);
444VMMR3DECL(RTNATIVETHREAD) VMR3GetVMCPUNativeThreadU(PUVM pUVM);
445
446/** @} */
447#endif /* IN_RING3 */
448
449
450#ifdef IN_RC
451/** @defgroup grp_vmm_apis_gc VM Guest Context APIs
452 * @ingroup grp_vm
453 * @{ */
454
455/** @} */
456#endif
457
458__END_DECLS
459
460/** @} */
461
462#endif
463
464
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