VirtualBox

source: vbox/trunk/include/VBox/trpm.h@ 10353

Last change on this file since 10353 was 9289, checked in by vboxsync, 17 years ago

Updates for 64 bits guests

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.6 KB
Line 
1/** @file
2 * TRPM - The Trap Monitor.
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_trpm_h
31#define ___VBox_trpm_h
32
33#include <VBox/cdefs.h>
34#include <VBox/types.h>
35#include <VBox/x86.h>
36
37
38__BEGIN_DECLS
39/** @defgroup grp_trpm The Trap Monitor API
40 * @{
41 */
42
43/**
44 * Trap: error code present or not
45 */
46typedef enum
47{
48 TRPM_TRAP_HAS_ERRORCODE = 0,
49 TRPM_TRAP_NO_ERRORCODE,
50 /** The usual 32-bit paranoia. */
51 TRPM_TRAP_32BIT_HACK = 0x7fffffff
52} TRPMERRORCODE;
53
54/**
55 * TRPM event type
56 */
57/** Note: must match trpm.mac! */
58typedef enum
59{
60 TRPM_TRAP = 0,
61 TRPM_HARDWARE_INT = 1,
62 TRPM_SOFTWARE_INT = 2,
63 /** The usual 32-bit paranoia. */
64 TRPM_32BIT_HACK = 0x7fffffff
65} TRPMEVENT;
66/** Pointer to a TRPM event type. */
67typedef TRPMEVENT *PTRPMEVENT;
68/** Pointer to a const TRPM event type. */
69typedef TRPMEVENT const *PCTRPMEVENT;
70
71/**
72 * Invalid trap handler for trampoline calls
73 */
74#define TRPM_INVALID_HANDLER 0
75
76/**
77 * Query info about the current active trap/interrupt.
78 * If no trap is active active an error code is returned.
79 *
80 * @returns VBox status code.
81 * @param pVM The virtual machine.
82 * @param pu8TrapNo Where to store the trap number.
83 * @param pEnmType Where to store the trap type.
84 */
85TRPMDECL(int) TRPMQueryTrap(PVM pVM, uint8_t *pu8TrapNo, PTRPMEVENT pEnmType);
86
87/**
88 * Gets the trap number for the current trap.
89 *
90 * The caller is responsible for making sure there is an active trap which
91 * takes an error code when making this request.
92 *
93 * @returns The current trap number.
94 * @param pVM VM handle.
95 */
96TRPMDECL(uint8_t) TRPMGetTrapNo(PVM pVM);
97
98/**
99 * Gets the error code for the current trap.
100 *
101 * The caller is responsible for making sure there is an active trap which
102 * takes an error code when making this request.
103 *
104 * @returns Error code.
105 * @param pVM VM handle.
106 */
107TRPMDECL(RTGCUINT) TRPMGetErrorCode(PVM pVM);
108
109/**
110 * Gets the fault address for the current trap.
111 *
112 * The caller is responsible for making sure there is an active trap 0x0e when
113 * making this request.
114 *
115 * @returns Fault address associated with the trap.
116 * @param pVM VM handle.
117 */
118TRPMDECL(RTGCUINTPTR) TRPMGetFaultAddress(PVM pVM);
119
120/**
121 * Clears the current active trap/exception/interrupt.
122 *
123 * The caller is responsible for making sure there is an active trap
124 * when making this request.
125 *
126 * @returns VBox status code.
127 * @param pVM The virtual machine handle.
128 */
129TRPMDECL(int) TRPMResetTrap(PVM pVM);
130
131/**
132 * Assert trap/exception/interrupt.
133 *
134 * The caller is responsible for making sure there is no active trap
135 * when making this request.
136 *
137 * @returns VBox status code.
138 * @param pVM The virtual machine.
139 * @param u8TrapNo The trap vector to assert.
140 * @param enmType Trap type.
141 */
142TRPMDECL(int) TRPMAssertTrap(PVM pVM, uint8_t u8TrapNo, TRPMEVENT enmType);
143
144/**
145 * Sets the error code of the current trap.
146 * (This function is for use in trap handlers and such.)
147 *
148 * The caller is responsible for making sure there is an active trap
149 * which takes an errorcode when making this request.
150 *
151 * @param pVM The virtual machine.
152 * @param uErrorCode The new error code.
153 */
154TRPMDECL(void) TRPMSetErrorCode(PVM pVM, RTGCUINT uErrorCode);
155
156/**
157 * Sets the error code of the current trap.
158 * (This function is for use in trap handlers and such.)
159 *
160 * The caller is responsible for making sure there is an active trap 0e
161 * when making this request.
162 *
163 * @param pVM The virtual machine.
164 * @param uCR2 The new fault address (cr2 register).
165 */
166TRPMDECL(void) TRPMSetFaultAddress(PVM pVM, RTGCUINTPTR uCR2);
167
168/**
169 * Checks if the current active trap/interrupt/exception/fault/whatever is a software
170 * interrupt or not.
171 *
172 * The caller is responsible for making sure there is an active trap
173 * when making this request.
174 *
175 * @returns true if software interrupt, false if not.
176 *
177 * @param pVM VM handle.
178 */
179TRPMDECL(bool) TRPMIsSoftwareInterrupt(PVM pVM);
180
181/**
182 * Check if there is an active trap.
183 *
184 * @returns true if trap active, false if not.
185 * @param pVM The virtual machine.
186 */
187TRPMDECL(bool) TRPMHasTrap(PVM pVM);
188
189/**
190 * Query all info about the current active trap/interrupt.
191 * If no trap is active active an error code is returned.
192 *
193 * @returns VBox status code.
194 * @param pVM The virtual machine.
195 * @param pu8TrapNo Where to store the trap number.
196 * @param pEnmType Where to store the trap type.
197 * @param puErrorCode Where to store the error code associated with some traps.
198 * ~0U is stored if the trap have no error code.
199 * @param puCR2 Where to store the CR2 associated with a trap 0E.
200 */
201TRPMDECL(int) TRPMQueryTrapAll(PVM pVM, uint8_t *pu8TrapNo, PTRPMEVENT pEnmType, PRTGCUINT puErrorCode, PRTGCUINTPTR puCR2);
202
203
204/**
205 * Save the active trap.
206 *
207 * This routine useful when doing try/catch in the hypervisor.
208 * Any function which uses temporary trap handlers should
209 * probably also use this facility to save the original trap.
210 *
211 * @param pVM VM handle.
212 */
213TRPMDECL(void) TRPMSaveTrap(PVM pVM);
214
215/**
216 * Restore a saved trap.
217 *
218 * Multiple restores of a saved trap is possible.
219 *
220 * @param pVM VM handle.
221 */
222TRPMDECL(void) TRPMRestoreTrap(PVM pVM);
223
224/**
225 * Forward trap or interrupt to the guest's handler
226 *
227 *
228 * @returns VBox status code.
229 * or does not return at all (when the trap is actually forwarded)
230 *
231 * @param pVM The VM to operate on.
232 * @param pRegFrame Pointer to the register frame for the trap.
233 * @param iGate Trap or interrupt gate number
234 * @param opsize Instruction size (only relevant for software interrupts)
235 * @param enmError TRPM_TRAP_HAS_ERRORCODE or TRPM_TRAP_NO_ERRORCODE.
236 * @param enmType TRPM event type
237 * @param iOrgTrap Original trap.
238 * @internal
239 */
240TRPMDECL(int) TRPMForwardTrap(PVM pVM, PCPUMCTXCORE pRegFrame, uint32_t iGate, uint32_t opsize, TRPMERRORCODE enmError, TRPMEVENT enmType, int32_t iOrgTrap);
241
242/**
243 * Raises a cpu exception which doesn't take an error code.
244 *
245 * This function may or may not dispatch the exception before returning.
246 *
247 * @returns VBox status code fit for scheduling.
248 * @retval VINF_EM_RAW_GUEST_TRAP if the exception was left pending.
249 * @retval VINF_TRPM_XCPT_DISPATCHED if the exception was raised and dispatched for raw-mode execution.
250 * @retval VINF_EM_RESCHEDULE_REM if the exception was dispatched and cannot be executed in raw-mode.
251 *
252 * @param pVM The VM handle.
253 * @param pCtxCore The CPU context core.
254 * @param enmXcpt The exception.
255 */
256TRPMDECL(int) TRPMRaiseXcpt(PVM pVM, PCPUMCTXCORE pCtxCore, X86XCPT enmXcpt);
257
258/**
259 * Raises a cpu exception with an errorcode.
260 *
261 * This function may or may not dispatch the exception before returning.
262 *
263 * @returns VBox status code fit for scheduling.
264 * @retval VINF_EM_RAW_GUEST_TRAP if the exception was left pending.
265 * @retval VINF_TRPM_XCPT_DISPATCHED if the exception was raised and dispatched for raw-mode execution.
266 * @retval VINF_EM_RESCHEDULE_REM if the exception was dispatched and cannot be executed in raw-mode.
267 *
268 * @param pVM The VM handle.
269 * @param pCtxCore The CPU context core.
270 * @param enmXcpt The exception.
271 * @param uErr The error code.
272 */
273TRPMDECL(int) TRPMRaiseXcptErr(PVM pVM, PCPUMCTXCORE pCtxCore, X86XCPT enmXcpt, uint32_t uErr);
274
275/**
276 * Raises a cpu exception with an errorcode and CR2.
277 *
278 * This function may or may not dispatch the exception before returning.
279 *
280 * @returns VBox status code fit for scheduling.
281 * @retval VINF_EM_RAW_GUEST_TRAP if the exception was left pending.
282 * @retval VINF_TRPM_XCPT_DISPATCHED if the exception was raised and dispatched for raw-mode execution.
283 * @retval VINF_EM_RESCHEDULE_REM if the exception was dispatched and cannot be executed in raw-mode.
284 *
285 * @param pVM The VM handle.
286 * @param pCtxCore The CPU context core.
287 * @param enmXcpt The exception.
288 * @param uErr The error code.
289 * @param uCR2 The CR2 value.
290 */
291TRPMDECL(int) TRPMRaiseXcptErrCR2(PVM pVM, PCPUMCTXCORE pCtxCore, X86XCPT enmXcpt, uint32_t uErr, RTGCUINTPTR uCR2);
292
293
294#ifdef IN_RING3
295/** @defgroup grp_trpm_r3 TRPM Host Context Ring 3 API
296 * @ingroup grp_trpm
297 * @{
298 */
299
300/**
301 * Initializes the SELM.
302 *
303 * @returns VBox status code.
304 * @param pVM The VM to operate on.
305 */
306TRPMR3DECL(int) TRPMR3Init(PVM pVM);
307
308/**
309 * Applies relocations to data and code managed by this component.
310 *
311 * This function will be called at init and whenever the VMM need
312 * to relocate itself inside the GC.
313 *
314 * @param pVM The VM handle.
315 * @param offDelta Relocation delta relative to old location.
316 */
317TRPMR3DECL(void) TRPMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
318
319/**
320 * The VM is being reset.
321 *
322 * For the TRPM component this means that any IDT write monitors
323 * needs to be removed, any pending trap cleared, and the IDT reset.
324 *
325 * @param pVM VM handle.
326 */
327TRPMR3DECL(void) TRPMR3Reset(PVM pVM);
328
329/**
330 * Set interrupt gate handler
331 * Used for setting up interrupt gates used for kernel calls.
332 *
333 * @returns VBox status code.
334 * @param pVM The VM to operate on.
335 * @param iTrap Interrupt number.
336 */
337TRPMR3DECL(int) TRPMR3EnableGuestTrapHandler(PVM pVM, unsigned iTrap);
338
339/**
340 * Set guest trap/interrupt gate handler
341 * Used for setting up trap gates used for kernel calls.
342 *
343 * @returns VBox status code.
344 * @param pVM The VM to operate on.
345 * @param iTrap Interrupt/trap number.
346 * @parapm pHandler GC handler pointer
347 */
348TRPMR3DECL(int) TRPMR3SetGuestTrapHandler(PVM pVM, unsigned iTrap, RTRCPTR pHandler);
349
350/**
351 * Get guest trap/interrupt gate handler
352 *
353 * @returns Guest trap handler address or TRPM_INVALID_HANDLER if none installed
354 * @param pVM The VM to operate on.
355 * @param iTrap Interrupt/trap number.
356 */
357TRPMR3DECL(RTRCPTR) TRPMR3GetGuestTrapHandler(PVM pVM, unsigned iTrap);
358
359/**
360 * Disable IDT monitoring and syncing
361 *
362 * @param pVM The VM to operate on.
363 */
364TRPMR3DECL(void) TRPMR3DisableMonitoring(PVM pVM);
365
366/**
367 * Check if gate handlers were updated
368 *
369 * @returns VBox status code.
370 * @param pVM The VM to operate on.
371 */
372TRPMR3DECL(int) TRPMR3SyncIDT(PVM pVM);
373
374/**
375 * Check if address is a gate handler (interrupt/trap/task/anything).
376 *
377 * @returns True is gate handler, false if not.
378 *
379 * @param pVM VM handle.
380 * @param GCPtr GC address to check.
381 */
382TRPMR3DECL(bool) TRPMR3IsGateHandler(PVM pVM, RTRCPTR GCPtr);
383
384/**
385 * Check if address is a gate handler (interrupt or trap).
386 *
387 * @returns gate nr or ~0 is not found
388 *
389 * @param pVM VM handle.
390 * @param GCPtr GC address to check.
391 */
392TRPMR3DECL(uint32_t) TRPMR3QueryGateByHandler(PVM pVM, RTRCPTR GCPtr);
393
394/**
395 * Initializes the SELM.
396 *
397 * @returns VBox status code.
398 * @param pVM The VM to operate on.
399 */
400TRPMR3DECL(int) TRPMR3Term(PVM pVM);
401
402
403/**
404 * Inject event (such as external irq or trap)
405 *
406 * @returns VBox status code.
407 * @param pVM The VM to operate on.
408 * @param enmEvent Trpm event type
409 */
410TRPMR3DECL(int) TRPMR3InjectEvent(PVM pVM, TRPMEVENT enmEvent);
411
412/** @} */
413#endif
414
415
416#ifdef IN_GC
417/** @defgroup grp_trpm_gc The TRPM Guest Context API
418 * @ingroup grp_trpm
419 * @{
420 */
421
422/**
423 * Guest Context temporary trap handler
424 *
425 * @returns VBox status code (appropriate for GC return).
426 * In this context VBOX_SUCCESS means to restart the instruction.
427 * @param pVM VM handle.
428 * @param pRegFrame Trap register frame.
429 */
430typedef DECLCALLBACK(int) FNTRPMGCTRAPHANDLER(PVM pVM, PCPUMCTXCORE pRegFrame);
431/** Pointer to a TRPMGCTRAPHANDLER() function. */
432typedef FNTRPMGCTRAPHANDLER *PFNTRPMGCTRAPHANDLER;
433
434/**
435 * Arms a temporary trap handler for traps in Hypervisor code.
436 *
437 * The operation is similar to a System V signal handler. I.e. when the handler
438 * is called it is first set to default action. So, if you need to handler more
439 * than one trap, you must reinstall the handler.
440 *
441 * To uninstall the temporary handler, call this function with pfnHandler set to NULL.
442 *
443 * @returns VBox status.
444 * @param pVM VM handle.
445 * @param iTrap Trap number to install handler [0..255].
446 * @param pfnHandler Pointer to the handler. Use NULL for uninstalling the handler.
447 */
448TRPMGCDECL(int) TRPMGCSetTempHandler(PVM pVM, unsigned iTrap, PFNTRPMGCTRAPHANDLER pfnHandler);
449
450/**
451 * Return to host context from a hypervisor trap handler.
452 * It will also reset any traps that are pending.
453 *
454 * This function will *never* return.
455 *
456 * @param pVM The VM handle.
457 * @param rc The return code for host context.
458 */
459TRPMGCDECL(void) TRPMGCHyperReturnToHost(PVM pVM, int rc);
460
461/** @} */
462#endif
463
464
465#ifdef IN_RING0
466/** @defgroup grp_trpm_r0 TRPM Host Context Ring 0 API
467 * @ingroup grp_trpm
468 * @{
469 */
470
471/**
472 * Dispatches an interrupt that arrived while we were in the guest context.
473 *
474 * @param pVM The VM handle.
475 * @remark Must be called with interrupts disabled.
476 */
477TRPMR0DECL(void) TRPMR0DispatchHostInterrupt(PVM pVM);
478
479/**
480 * Changes the VMMR0Entry() call frame and stack used by the IDT patch code
481 * so that we'll dispatch an interrupt rather than returning directly to Ring-3
482 * when VMMR0Entry() returns.
483 *
484 * @param pVM Pointer to the VM.
485 * @param pvRet Pointer to the return address of VMMR0Entry() on the stack.
486 */
487TRPMR0DECL(void) TRPMR0SetupInterruptDispatcherFrame(PVM pVM, void *pvRet);
488
489/** @} */
490#endif
491
492/** @} */
493__END_DECLS
494
495#endif
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