VirtualBox

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

Last change on this file since 7409 was 7133, checked in by vboxsync, 17 years ago

Eliminate cpum.h dependency (shuts up a bunch of .c warnings). Fixed the header tests.

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