VirtualBox

source: vbox/trunk/src/VBox/VMM/include/TRPMInternal.h@ 77922

Last change on this file since 77922 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 9.3 KB
Line 
1/* $Id: TRPMInternal.h 76585 2019-01-01 06:31:29Z vboxsync $ */
2/** @file
3 * TRPM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef VMM_INCLUDED_SRC_include_TRPMInternal_h
19#define VMM_INCLUDED_SRC_include_TRPMInternal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <VBox/cdefs.h>
25#include <VBox/types.h>
26#include <VBox/vmm/stam.h>
27#include <VBox/vmm/cpum.h>
28#include <VBox/vmm/pgm.h>
29
30RT_C_DECLS_BEGIN
31
32
33/** @defgroup grp_trpm_int Internals
34 * @ingroup grp_trpm
35 * @internal
36 * @{
37 */
38
39
40#ifdef VBOX_WITH_RAW_MODE
41/** Enable or disable tracking of Guest's IDT. */
42# define TRPM_TRACK_GUEST_IDT_CHANGES
43/** Enable or disable tracking of Shadow IDT. */
44# define TRPM_TRACK_SHADOW_IDT_CHANGES
45#endif
46
47
48/** Enable to allow trap forwarding in GC. */
49#ifdef VBOX_WITH_RAW_MODE
50# define TRPM_FORWARD_TRAPS_IN_GC
51#endif
52
53/** First interrupt handler. Used for validating input. */
54#define TRPM_HANDLER_INT_BASE 0x20
55
56
57/** @name TRPMGCTrapIn* flags.
58 * The lower bits are offsets into the CPUMCTXCORE structure.
59 * @{ */
60/** The mask for the operation. */
61#define TRPM_TRAP_IN_OP_MASK 0xffff
62/** Traps on MOV GS, eax. */
63#define TRPM_TRAP_IN_MOV_GS 1
64/** Traps on MOV FS, eax. */
65#define TRPM_TRAP_IN_MOV_FS 2
66/** Traps on MOV ES, eax. */
67#define TRPM_TRAP_IN_MOV_ES 3
68/** Traps on MOV DS, eax. */
69#define TRPM_TRAP_IN_MOV_DS 4
70/** Traps on IRET. */
71#define TRPM_TRAP_IN_IRET 5
72/** Set if this is a V86 resume. */
73#define TRPM_TRAP_IN_V86 RT_BIT(30)
74/** @} */
75
76
77#if 0 /* not used */
78/**
79 * Converts a TRPM pointer into a VM pointer.
80 * @returns Pointer to the VM structure the TRPM is part of.
81 * @param pTRPM Pointer to TRPM instance data.
82 */
83#define TRPM_2_VM(pTRPM) ( (PVM)((uint8_t *)(pTRPM) - (pTRPM)->offVM) )
84#endif
85
86/**
87 * Converts a TRPM pointer into a TRPMCPU pointer.
88 * @returns Pointer to the VM structure the TRPMCPU is part of.
89 * @param pTrpmCpu Pointer to TRPMCPU instance data.
90 * @remarks Raw-mode only, not SMP safe.
91 */
92#define TRPM_2_TRPMCPU(pTrpmCpu) ( (PTRPMCPU)((uint8_t *)(pTrpmCpu) + (pTrpmCpu)->offTRPMCPU) )
93
94
95/**
96 * TRPM Data (part of VM)
97 *
98 * IMPORTANT! Keep the nasm version of this struct up-to-date.
99 */
100typedef struct TRPM
101{
102 /** Offset to the VM structure.
103 * See TRPM_2_VM(). */
104 RTINT offVM;
105 /** Offset to the TRPMCPU structure.
106 * See TRPM2TRPMCPU(). */
107 RTINT offTRPMCPU;
108
109 /** Whether monitoring of the guest IDT is enabled or not.
110 *
111 * This configuration option is provided for speeding up guest like Solaris
112 * that put the IDT on the same page as a whole lot of other data that is
113 * frequently updated. The updates will cause \#PFs and have to be interpreted
114 * by PGMInterpretInstruction which is slow compared to raw execution.
115 *
116 * If the guest is well behaved and doesn't change the IDT after loading it,
117 * there is no problem with dropping the IDT monitoring.
118 *
119 * @cfgm{/TRPM/SafeToDropGuestIDTMonitoring, boolean, defaults to false.}
120 */
121 bool fSafeToDropGuestIDTMonitoring;
122
123 /** Padding to get the IDTs at a 16 byte alignment. */
124 uint8_t abPadding1[7];
125 /** IDTs. Aligned at 16 byte offset for speed. */
126 VBOXIDTE aIdt[256];
127
128 /** Bitmap for IDTEs that contain PATM handlers. (needed for relocation) */
129 uint32_t au32IdtPatched[8];
130
131 /** Temporary Hypervisor trap handlers.
132 * NULL means default action. */
133 RCPTRTYPE(void *) aTmpTrapHandlers[256];
134
135 /** RC Pointer to the IDT shadow area (aIdt) in HMA. */
136 RCPTRTYPE(void *) pvMonShwIdtRC;
137 /** padding. */
138 uint8_t au8Padding[2];
139 /** Current (last) Guest's IDTR. */
140 VBOXIDTR GuestIdtr;
141 /** Shadow IDT virtual write access handler type. */
142 PGMVIRTHANDLERTYPE hShadowIdtWriteHandlerType;
143 /** Guest IDT virtual write access handler type. */
144 PGMVIRTHANDLERTYPE hGuestIdtWriteHandlerType;
145
146 /** Checked trap & interrupt handler array */
147 RCPTRTYPE(void *) aGuestTrapHandler[256];
148
149 /** RC: The number of times writes to the Guest IDT were detected. */
150 STAMCOUNTER StatRCWriteGuestIDTFault;
151 STAMCOUNTER StatRCWriteGuestIDTHandled;
152
153 /** HC: Profiling of the TRPMR3SyncIDT() method. */
154 STAMPROFILE StatSyncIDT;
155 /** GC: Statistics for the trap handlers. */
156 STAMPROFILEADV aStatGCTraps[0x14];
157
158 STAMPROFILEADV StatForwardProfR3;
159 STAMPROFILEADV StatForwardProfRZ;
160 STAMCOUNTER StatForwardFailNoHandler;
161 STAMCOUNTER StatForwardFailPatchAddr;
162 STAMCOUNTER StatForwardFailR3;
163 STAMCOUNTER StatForwardFailRZ;
164
165 STAMPROFILE StatTrap0dDisasm;
166 STAMCOUNTER StatTrap0dRdTsc; /**< Number of RDTSC \#GPs. */
167
168#ifdef VBOX_WITH_STATISTICS
169 /** Statistics for interrupt handlers (allocated on the hypervisor heap) - R3
170 * pointer. */
171 R3PTRTYPE(PSTAMCOUNTER) paStatForwardedIRQR3;
172 /** Statistics for interrupt handlers - RC pointer. */
173 RCPTRTYPE(PSTAMCOUNTER) paStatForwardedIRQRC;
174
175 /** Host interrupt statistics (allocated on the hypervisor heap) - RC ptr. */
176 RCPTRTYPE(PSTAMCOUNTER) paStatHostIrqRC;
177 /** Host interrupt statistics (allocated on the hypervisor heap) - R3 ptr. */
178 R3PTRTYPE(PSTAMCOUNTER) paStatHostIrqR3;
179#endif
180} TRPM;
181AssertCompileMemberAlignment(TRPM, GuestIdtr.pIdt, 8);
182
183/** Pointer to TRPM Data. */
184typedef TRPM *PTRPM;
185
186
187/**
188 * Converts a TRPMCPU pointer into a VM pointer.
189 * @returns Pointer to the VM structure the TRPMCPU is part of.
190 * @param pTrpmCpu Pointer to TRPMCPU instance data.
191 */
192#define TRPMCPU_2_VM(pTrpmCpu) ( (PVM)((uint8_t *)(pTrpmCpu) - (pTrpmCpu)->offVM) )
193
194/**
195 * Converts a TRPMCPU pointer into a VMCPU pointer.
196 * @returns Pointer to the VMCPU structure the TRPMCPU is part of.
197 * @param pTrpmCpu Pointer to TRPMCPU instance data.
198 */
199#define TRPMCPU_2_VMCPU(pTrpmCpu) ( (PVMCPU)((uint8_t *)(pTrpmCpu) - (pTrpmCpu)->offVMCpu) )
200
201
202/**
203 * Per CPU data for TRPM.
204 */
205typedef struct TRPMCPU
206{
207 /** Offset into the VM structure.
208 * See TRPMCPU_2_VM(). */
209 uint32_t offVM;
210 /** Offset into the VMCPU structure.
211 * See TRPMCPU_2_VMCPU(). */
212 uint32_t offVMCpu;
213
214 /** Active Interrupt or trap vector number.
215 * If not UINT32_MAX this indicates that we're currently processing a
216 * interrupt, trap, fault, abort, whatever which have arrived at that
217 * vector number.
218 */
219 uint32_t uActiveVector;
220
221 /** Active trap type. */
222 TRPMEVENT enmActiveType;
223
224 /** Errorcode for the active interrupt/trap. */
225 RTGCUINT uActiveErrorCode; /**< @todo don't use RTGCUINT */
226
227 /** CR2 at the time of the active exception. */
228 RTGCUINTPTR uActiveCR2;
229
230 /** Saved trap vector number. */
231 RTGCUINT uSavedVector; /**< @todo don't use RTGCUINT */
232
233 /** Saved errorcode. */
234 RTGCUINT uSavedErrorCode;
235
236 /** Saved cr2. */
237 RTGCUINTPTR uSavedCR2;
238
239 /** Saved trap type. */
240 TRPMEVENT enmSavedType;
241
242 /** Instruction length for software interrupts and software exceptions
243 * (\#BP, \#OF) */
244 uint8_t cbInstr;
245
246 /** Saved instruction length. */
247 uint8_t cbSavedInstr;
248
249 /** Padding. */
250 uint8_t au8Padding[2];
251
252 /** Previous trap vector # - for debugging. */
253 RTGCUINT uPrevVector;
254} TRPMCPU;
255
256/** Pointer to TRPMCPU Data. */
257typedef TRPMCPU *PTRPMCPU;
258
259
260PGM_ALL_CB2_PROTO(FNPGMVIRTHANDLER) trpmGuestIDTWriteHandler;
261DECLEXPORT(FNPGMRCVIRTPFHANDLER) trpmRCGuestIDTWritePfHandler;
262DECLEXPORT(FNPGMRCVIRTPFHANDLER) trpmRCShadowIDTWritePfHandler;
263
264/**
265 * Clear guest trap/interrupt gate handler
266 *
267 * @returns VBox status code.
268 * @param pVM The cross context VM structure.
269 * @param iTrap Interrupt/trap number.
270 */
271VMMDECL(int) trpmClearGuestTrapHandler(PVM pVM, unsigned iTrap);
272
273
274#ifdef IN_RING3
275int trpmR3ClearPassThroughHandler(PVM pVM, unsigned iTrap);
276#endif
277
278
279#ifdef IN_RING0
280
281/**
282 * Calls the interrupt gate as if we received an interrupt while in Ring-0.
283 *
284 * @param uIP The interrupt gate IP.
285 * @param SelCS The interrupt gate CS.
286 * @param RSP The interrupt gate RSP. ~0 if no stack switch should take place. (only AMD64)
287 */
288DECLASM(void) trpmR0DispatchHostInterrupt(RTR0UINTPTR uIP, RTSEL SelCS, RTR0UINTPTR RSP);
289
290/**
291 * Issues a software interrupt to the specified interrupt vector.
292 *
293 * @param uActiveVector The vector number.
294 */
295DECLASM(void) trpmR0DispatchHostInterruptSimple(RTUINT uActiveVector);
296
297#endif /* IN_RING0 */
298
299/** @} */
300
301RT_C_DECLS_END
302
303#endif /* !VMM_INCLUDED_SRC_include_TRPMInternal_h */
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