1 | /** @file
|
---|
2 | * VMM - The Virtual Machine Monitor.
|
---|
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 as published by the Free Software Foundation,
|
---|
12 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef ___VBox_vmm_h
|
---|
18 | #define ___VBox_vmm_h
|
---|
19 |
|
---|
20 | #include <VBox/cdefs.h>
|
---|
21 | #include <VBox/types.h>
|
---|
22 | #include <VBox/vmapi.h>
|
---|
23 | #include <iprt/stdarg.h>
|
---|
24 |
|
---|
25 | __BEGIN_DECLS
|
---|
26 |
|
---|
27 | /** @defgroup grp_vmm The Virtual Machine Monitor API
|
---|
28 | * @{
|
---|
29 | */
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * World switcher identifiers.
|
---|
33 | */
|
---|
34 | typedef enum VMMSWITCHER
|
---|
35 | {
|
---|
36 | /** The usual invalid 0. */
|
---|
37 | VMMSWITCHER_INVALID = 0,
|
---|
38 | /** Switcher for 32-bit host to 32-bit shadow paging. */
|
---|
39 | VMMSWITCHER_32_TO_32,
|
---|
40 | /** Switcher for 32-bit host paging to PAE shadow paging. */
|
---|
41 | VMMSWITCHER_32_TO_PAE,
|
---|
42 | /** Switcher for 32-bit host paging to AMD64 shadow paging. */
|
---|
43 | VMMSWITCHER_32_TO_AMD64,
|
---|
44 | /** Switcher for PAE host to 32-bit shadow paging. */
|
---|
45 | VMMSWITCHER_PAE_TO_32,
|
---|
46 | /** Switcher for PAE host to PAE shadow paging. */
|
---|
47 | VMMSWITCHER_PAE_TO_PAE,
|
---|
48 | /** Switcher for PAE host paging to AMD64 shadow paging. */
|
---|
49 | VMMSWITCHER_PAE_TO_AMD64,
|
---|
50 | /** Switcher for AMD64 host paging to PAE shadow paging. */
|
---|
51 | VMMSWITCHER_AMD64_TO_PAE,
|
---|
52 | /** Switcher for AMD64 host paging to AMD64 shadow paging. */
|
---|
53 | VMMSWITCHER_AMD64_TO_AMD64,
|
---|
54 | /** Used to make a count for array declarations and suchlike. */
|
---|
55 | VMMSWITCHER_MAX,
|
---|
56 | /** The usual 32-bit paranoia. */
|
---|
57 | VMMSWITCHER_32BIT_HACK = 0x7fffffff
|
---|
58 | } VMMSWITCHER;
|
---|
59 |
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * VMMGCCallHost operations.
|
---|
63 | */
|
---|
64 | typedef enum VMMCALLHOST
|
---|
65 | {
|
---|
66 | /** Invalid operation. */
|
---|
67 | VMMCALLHOST_INVALID = 0,
|
---|
68 | /** Acquire the PDM lock. */
|
---|
69 | VMMCALLHOST_PDM_LOCK,
|
---|
70 | /** Call PDMR3QueueFlushWorker. */
|
---|
71 | VMMCALLHOST_PDM_QUEUE_FLUSH,
|
---|
72 | /** Acquire the PGM lock. */
|
---|
73 | VMMCALLHOST_PGM_LOCK,
|
---|
74 | /** Grow the PGM shadow page pool. */
|
---|
75 | VMMCALLHOST_PGM_POOL_GROW,
|
---|
76 | /** Dynamically allocate physical guest RAM. */
|
---|
77 | VMMCALLHOST_PGM_RAM_GROW_RANGE,
|
---|
78 | /** Replay the REM handler notifications. */
|
---|
79 | VMMCALLHOST_REM_REPLAY_HANDLER_NOTIFICATIONS,
|
---|
80 | /** Flush the GC/R0 logger. */
|
---|
81 | VMMCALLHOST_VMM_LOGGER_FLUSH,
|
---|
82 | /** Set the VM error message. */
|
---|
83 | VMMCALLHOST_VM_SET_ERROR,
|
---|
84 | /** Set the VM runtime error message. */
|
---|
85 | VMMCALLHOST_VM_SET_RUNTIME_ERROR,
|
---|
86 | /** The usual 32-bit hack. */
|
---|
87 | VMMCALLHOST_32BIT_HACK = 0x7fffffff
|
---|
88 | } VMMCALLHOST;
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Gets the bottom of the hypervisor stack - GC Ptr.
|
---|
94 | * I.e. the returned address is not actually writable.
|
---|
95 | *
|
---|
96 | * @returns bottom of the stack.
|
---|
97 | * @param pVM The VM handle.
|
---|
98 | */
|
---|
99 | RTGCPTR VMMGetStackGC(PVM pVM);
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Gets the bottom of the hypervisor stack - HC Ptr.
|
---|
103 | * I.e. the returned address is not actually writable.
|
---|
104 | *
|
---|
105 | * @returns bottom of the stack.
|
---|
106 | * @param pVM The VM handle.
|
---|
107 | */
|
---|
108 | RTHCPTR VMMGetHCStack(PVM pVM);
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 | #ifdef IN_RING3
|
---|
113 | /** @defgroup grp_vmm_r3 The VMM Host Context Ring 3 API
|
---|
114 | * @ingroup grp_vmm
|
---|
115 | * @{
|
---|
116 | */
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Initializes the VMM.
|
---|
120 | *
|
---|
121 | * @returns VBox status code.
|
---|
122 | * @param pVM The VM to operate on.
|
---|
123 | */
|
---|
124 | VMMR3DECL(int) VMMR3Init(PVM pVM);
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Ring-3 init finalizing.
|
---|
128 | *
|
---|
129 | * @returns VBox status code.
|
---|
130 | * @param pVM The VM handle.
|
---|
131 | */
|
---|
132 | VMMR3DECL(int) VMMR3InitFinalize(PVM pVM);
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Initializes the R0 VMM.
|
---|
136 | *
|
---|
137 | * @returns VBox status code.
|
---|
138 | * @param pVM The VM to operate on.
|
---|
139 | */
|
---|
140 | VMMR3DECL(int) VMMR3InitR0(PVM pVM);
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Initializes the GC VMM.
|
---|
144 | *
|
---|
145 | * @returns VBox status code.
|
---|
146 | * @param pVM The VM to operate on.
|
---|
147 | */
|
---|
148 | VMMR3DECL(int) VMMR3InitGC(PVM pVM);
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Destroy the VMM bits.
|
---|
152 | *
|
---|
153 | * @returns VINF_SUCCESS.
|
---|
154 | * @param pVM The VM handle.
|
---|
155 | */
|
---|
156 | VMMR3DECL(int) VMMR3Term(PVM pVM);
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * Applies relocations to data and code managed by this
|
---|
160 | * component. This function will be called at init and
|
---|
161 | * whenever the VMM need to relocate it self inside the GC.
|
---|
162 | *
|
---|
163 | * The VMM will need to apply relocations to the core code.
|
---|
164 | *
|
---|
165 | * @param pVM The VM handle.
|
---|
166 | * @param offDelta The relocation delta.
|
---|
167 | */
|
---|
168 | VMMR3DECL(void) VMMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Updates the settings for the GC (and R0?) loggers.
|
---|
172 | *
|
---|
173 | * @returns VBox status code.
|
---|
174 | * @param pVM The VM handle.
|
---|
175 | */
|
---|
176 | VMMR3DECL(int) VMMR3UpdateLoggers(PVM pVM);
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * Gets the pointer to g_szRTAssertMsg1 in GC.
|
---|
180 | * @returns Pointer to VMMGC::g_szRTAssertMsg1.
|
---|
181 | * Returns NULL if not present.
|
---|
182 | * @param pVM The VM handle.
|
---|
183 | */
|
---|
184 | VMMR3DECL(const char *) VMMR3GetGCAssertMsg1(PVM pVM);
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Gets the pointer to g_szRTAssertMsg2 in GC.
|
---|
188 | * @returns Pointer to VMMGC::g_szRTAssertMsg2.
|
---|
189 | * Returns NULL if not present.
|
---|
190 | * @param pVM The VM handle.
|
---|
191 | */
|
---|
192 | VMMR3DECL(const char *) VMMR3GetGCAssertMsg2(PVM pVM);
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Resolve a builtin GC symbol.
|
---|
196 | * Called by PDM when loading or relocating GC modules.
|
---|
197 | *
|
---|
198 | * @returns VBox status.
|
---|
199 | * @param pVM VM Handle.
|
---|
200 | * @param pszSymbol Symbol to resolv
|
---|
201 | * @param pGCPtrValue Where to store the symbol value.
|
---|
202 | * @remark This has to work before VMMR3Relocate() is called.
|
---|
203 | */
|
---|
204 | VMMR3DECL(int) VMMR3GetImportGC(PVM pVM, const char *pszSymbol, PRTGCPTR pGCPtrValue);
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Selects the switcher to be used for switching to GC.
|
---|
208 | *
|
---|
209 | * @returns VBox status code.
|
---|
210 | * @param pVM VM handle.
|
---|
211 | * @param enmSwitcher The new switcher.
|
---|
212 | * @remark This function may be called before the VMM is initialized.
|
---|
213 | */
|
---|
214 | VMMR3DECL(int) VMMR3SelectSwitcher(PVM pVM, VMMSWITCHER enmSwitcher);
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * Disable the switcher logic permanently.
|
---|
218 | *
|
---|
219 | * @returns VBox status code.
|
---|
220 | * @param pVM VM handle.
|
---|
221 | */
|
---|
222 | VMMR3DECL(int) VMMR3DisableSwitcher(PVM pVM);
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Executes guest code.
|
---|
226 | *
|
---|
227 | * @param pVM VM handle.
|
---|
228 | */
|
---|
229 | VMMR3DECL(int) VMMR3RawRunGC(PVM pVM);
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * Executes guest code (Intel VMX and AMD SVM).
|
---|
233 | *
|
---|
234 | * @param pVM VM handle.
|
---|
235 | */
|
---|
236 | VMMR3DECL(int) VMMR3HwAccRunGC(PVM pVM);
|
---|
237 |
|
---|
238 | /**
|
---|
239 | * Calls GC a function.
|
---|
240 | *
|
---|
241 | * @param pVM The VM handle.
|
---|
242 | * @param GCPtrEntry The GC function address.
|
---|
243 | * @param cArgs The number of arguments in the ....
|
---|
244 | * @param ... Arguments to the function.
|
---|
245 | */
|
---|
246 | VMMR3DECL(int) VMMR3CallGC(PVM pVM, RTGCPTR GCPtrEntry, unsigned cArgs, ...);
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Calls GC a function.
|
---|
250 | *
|
---|
251 | * @param pVM The VM handle.
|
---|
252 | * @param GCPtrEntry The GC function address.
|
---|
253 | * @param cArgs The number of arguments in the ....
|
---|
254 | * @param args Arguments to the function.
|
---|
255 | */
|
---|
256 | VMMR3DECL(int) VMMR3CallGCV(PVM pVM, RTGCPTR GCPtrEntry, unsigned cArgs, va_list args);
|
---|
257 |
|
---|
258 | /**
|
---|
259 | * Resumes executing hypervisor code when interrupted
|
---|
260 | * by a queue flush or a debug event.
|
---|
261 | *
|
---|
262 | * @returns VBox status code.
|
---|
263 | * @param pVM VM handle.
|
---|
264 | */
|
---|
265 | VMMR3DECL(int) VMMR3ResumeHyper(PVM pVM);
|
---|
266 |
|
---|
267 | /**
|
---|
268 | * Dumps the VM state on a fatal error.
|
---|
269 | *
|
---|
270 | * @param pVM VM Handle.
|
---|
271 | * @param rcErr VBox status code.
|
---|
272 | */
|
---|
273 | VMMR3DECL(void) VMMR3FatalDump(PVM pVM, int rcErr);
|
---|
274 |
|
---|
275 | /**
|
---|
276 | * Acquire global VM lock
|
---|
277 | *
|
---|
278 | * @returns VBox status code
|
---|
279 | * @param pVM The VM to operate on.
|
---|
280 | */
|
---|
281 | VMMR3DECL(int) VMMR3Lock(PVM pVM);
|
---|
282 |
|
---|
283 | /**
|
---|
284 | * Release global VM lock
|
---|
285 | *
|
---|
286 | * @returns VBox status code
|
---|
287 | * @param pVM The VM to operate on.
|
---|
288 | */
|
---|
289 | VMMR3DECL(int) VMMR3Unlock(PVM pVM);
|
---|
290 |
|
---|
291 | /**
|
---|
292 | * Return global VM lock owner
|
---|
293 | *
|
---|
294 | * @returns NIL_RTNATIVETHREAD -> no owner, otherwise thread id of owner
|
---|
295 | * @param pVM The VM to operate on.
|
---|
296 | */
|
---|
297 | VMMR3DECL(RTNATIVETHREAD) VMMR3LockGetOwner(PVM pVM);
|
---|
298 |
|
---|
299 | /**
|
---|
300 | * Checks if the current thread is the owner of the global VM lock.
|
---|
301 | *
|
---|
302 | * @returns true if owner.
|
---|
303 | * @returns false if not owner.
|
---|
304 | * @param pVM The VM to operate on.
|
---|
305 | */
|
---|
306 | VMMR3DECL(bool) VMMR3LockIsOwner(PVM pVM);
|
---|
307 |
|
---|
308 | /**
|
---|
309 | * Suspends the the CPU yielder.
|
---|
310 | *
|
---|
311 | * @param pVM The VM handle.
|
---|
312 | */
|
---|
313 | VMMR3DECL(void) VMMR3YieldSuspend(PVM pVM);
|
---|
314 |
|
---|
315 | /**
|
---|
316 | * Stops the the CPU yielder.
|
---|
317 | *
|
---|
318 | * @param pVM The VM handle.
|
---|
319 | */
|
---|
320 | VMMR3DECL(void) VMMR3YieldStop(PVM pVM);
|
---|
321 |
|
---|
322 | /**
|
---|
323 | * Resumes the CPU yielder when it has been a suspended or stopped.
|
---|
324 | *
|
---|
325 | * @param pVM The VM handle.
|
---|
326 | */
|
---|
327 | VMMR3DECL(void) VMMR3YieldResume(PVM pVM);
|
---|
328 |
|
---|
329 | /** @} */
|
---|
330 | #endif
|
---|
331 |
|
---|
332 | /** @defgroup grp_vmm_r0 The VMM Host Context Ring 0 API
|
---|
333 | * @ingroup grp_vmm
|
---|
334 | * @{
|
---|
335 | */
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * The VMMR0Entry() codes.
|
---|
339 | */
|
---|
340 | typedef enum VMMR0OPERATION
|
---|
341 | {
|
---|
342 | /** Run guest context. */
|
---|
343 | VMMR0_DO_RAW_RUN = 0,
|
---|
344 | VMMR0_DO_RUN_GC = VMMR0_DO_RAW_RUN,
|
---|
345 | /** Run guest code using the available hardware acceleration technology. */
|
---|
346 | VMMR0_DO_HWACC_RUN,
|
---|
347 | /** Call VMMR0 Per VM Init. */
|
---|
348 | VMMR0_DO_VMMR0_INIT,
|
---|
349 | /** Call VMMR0 Per VM Termination. */
|
---|
350 | VMMR0_DO_VMMR0_TERM,
|
---|
351 | /** Setup the hardware accelerated raw-mode session. */
|
---|
352 | VMMR0_DO_HWACC_SETUP_VM,
|
---|
353 | /** Calls function in the hypervisor.
|
---|
354 | * The caller must setup the hypervisor context so the call will be performed.
|
---|
355 | * The difference between VMMR0_DO_RUN_GC and this one is the handling of
|
---|
356 | * the return GC code. The return code will not be interpreted by this operation.
|
---|
357 | */
|
---|
358 | VMMR0_DO_CALL_HYPERVISOR,
|
---|
359 |
|
---|
360 | /** The start of the R0 service operations. */
|
---|
361 | VMMR0_DO_SRV_START,
|
---|
362 | /** Call INTNETR0Open(). */
|
---|
363 | VMMR0_DO_INTNET_OPEN,
|
---|
364 | /** Call INTNETR0IfClose(). */
|
---|
365 | VMMR0_DO_INTNET_IF_CLOSE,
|
---|
366 | /** Call INTNETR0IfGetRing3Buffer(). */
|
---|
367 | VMMR0_DO_INTNET_IF_GET_RING3_BUFFER,
|
---|
368 | /** Call INTNETR0IfSetPromiscuousMode(). */
|
---|
369 | VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE,
|
---|
370 | /** Call INTNETR0IfSend(). */
|
---|
371 | VMMR0_DO_INTNET_IF_SEND,
|
---|
372 | /** Call INTNETR0IfWait(). */
|
---|
373 | VMMR0_DO_INTNET_IF_WAIT,
|
---|
374 | /** The end of the R0 service operations. */
|
---|
375 | VMMR0_DO_SRV_END,
|
---|
376 |
|
---|
377 | /** Official NOP that we use for profiling. */
|
---|
378 | VMMR0_DO_NOP,
|
---|
379 | /** Official call we use for testing Ring-0 APIs. */
|
---|
380 | VMMR0_DO_TESTS,
|
---|
381 |
|
---|
382 | /** The usual 32-bit type blow up. */
|
---|
383 | VMMR0_DO_32BIT_HACK = 0x7fffffff
|
---|
384 | } VMMR0OPERATION;
|
---|
385 |
|
---|
386 | /**
|
---|
387 | * The Ring 0 entry point, called by the support library (SUP).
|
---|
388 | *
|
---|
389 | * @returns VBox status code.
|
---|
390 | * @param pVM The VM to operate on.
|
---|
391 | * @param uOperation Which operation to execute (VMMR0OPERATION).
|
---|
392 | * @param pvArg Argument to the operation.
|
---|
393 | */
|
---|
394 | VMMR0DECL(int) VMMR0Entry(PVM pVM, unsigned /* make me an enum */ uOperation, void *pvArg);
|
---|
395 |
|
---|
396 | /**
|
---|
397 | * Calls the ring-3 host code.
|
---|
398 | *
|
---|
399 | * @returns VBox status code of the ring-3 call.
|
---|
400 | * @param pVM The VM handle.
|
---|
401 | * @param enmOperation The operation.
|
---|
402 | * @param uArg The argument to the operation.
|
---|
403 | */
|
---|
404 | VMMR0DECL(int) VMMR0CallHost(PVM pVM, VMMCALLHOST enmOperation, uint64_t uArg);
|
---|
405 |
|
---|
406 | /** @} */
|
---|
407 |
|
---|
408 |
|
---|
409 | #ifdef IN_GC
|
---|
410 | /** @defgroup grp_vmm_gc The VMM Guest Context API
|
---|
411 | * @ingroup grp_vmm
|
---|
412 | * @{
|
---|
413 | */
|
---|
414 |
|
---|
415 | /**
|
---|
416 | * The GC entry point.
|
---|
417 | *
|
---|
418 | * @returns VBox status code.
|
---|
419 | * @param pVM The VM to operate on.
|
---|
420 | * @param uOperation Which operation to execute (VMMGCOPERATION).
|
---|
421 | * @param uArg Argument to that operation.
|
---|
422 | * @param ... Additional arguments.
|
---|
423 | */
|
---|
424 | VMMGCDECL(int) VMMGCEntry(PVM pVM, unsigned uOperation, unsigned uArg, ...);
|
---|
425 |
|
---|
426 | /**
|
---|
427 | * Switches from guest context to host context.
|
---|
428 | *
|
---|
429 | * @param pVM The VM handle.
|
---|
430 | * @param rc The status code.
|
---|
431 | */
|
---|
432 | VMMGCDECL(void) VMMGCGuestToHost(PVM pVM, int rc);
|
---|
433 |
|
---|
434 | /**
|
---|
435 | * Calls the ring-3 host code.
|
---|
436 | *
|
---|
437 | * @returns VBox status code of the ring-3 call.
|
---|
438 | * @param pVM The VM handle.
|
---|
439 | * @param enmOperation The operation.
|
---|
440 | * @param uArg The argument to the operation.
|
---|
441 | */
|
---|
442 | VMMGCDECL(int) VMMGCCallHost(PVM pVM, VMMCALLHOST enmOperation, uint64_t uArg);
|
---|
443 |
|
---|
444 | /** @} */
|
---|
445 | #endif
|
---|
446 |
|
---|
447 |
|
---|
448 | /** @} */
|
---|
449 | __END_DECLS
|
---|
450 |
|
---|
451 |
|
---|
452 | #endif
|
---|