VirtualBox

source: vbox/trunk/src/VBox/VMM/include/SELMInternal.h@ 45485

Last change on this file since 45485 was 45485, checked in by vboxsync, 12 years ago
  • *: Where possible, drop the #ifdef VBOX_WITH_RAW_RING1 when EMIsRawRing1Enabled is used.
  • SELM: Don't shadow TSS.esp1/ss1 unless ring-1 compression is enabled (also fixed a log statement there).
  • SELM: selmGuestToShadowDesc should not push ring-1 selectors into ring-2 unless EMIsRawRing1Enabled() holds true.
  • REM: Don't set CPU_INTERRUPT_EXTERNAL_EXIT in helper_ltr() for now.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.0 KB
Line 
1/* $Id: SELMInternal.h 45485 2013-04-11 14:46:04Z vboxsync $ */
2/** @file
3 * SELM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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 ___SELMInternal_h
19#define ___SELMInternal_h
20
21#include <VBox/cdefs.h>
22#include <VBox/types.h>
23#include <VBox/vmm/stam.h>
24#include <VBox/vmm/cpum.h>
25#include <VBox/log.h>
26#include <iprt/x86.h>
27
28
29
30/** @defgroup grp_selm_int Internals
31 * @ingroup grp_selm
32 * @internal
33 * @{
34 */
35
36/**
37 * Enable or disable tracking of Shadow GDT/LDT/TSS.
38 * @{
39 */
40#define SELM_TRACK_SHADOW_GDT_CHANGES
41#define SELM_TRACK_SHADOW_LDT_CHANGES
42#define SELM_TRACK_SHADOW_TSS_CHANGES
43/** @} */
44
45/**
46 * Enable or disable tracking of Guest GDT/LDT/TSS.
47 * @{
48 */
49#define SELM_TRACK_GUEST_GDT_CHANGES
50#define SELM_TRACK_GUEST_LDT_CHANGES
51#define SELM_TRACK_GUEST_TSS_CHANGES
52/** @} */
53
54
55/** The number of GDTS allocated for our GDT. (full size) */
56#define SELM_GDT_ELEMENTS 8192
57
58/** aHyperSel index to retrieve hypervisor selectors */
59/** The Flat CS selector used by the VMM inside the GC. */
60#define SELM_HYPER_SEL_CS 0
61/** The Flat DS selector used by the VMM inside the GC. */
62#define SELM_HYPER_SEL_DS 1
63/** The 64-bit mode CS selector used by the VMM inside the GC. */
64#define SELM_HYPER_SEL_CS64 2
65/** The TSS selector used by the VMM inside the GC. */
66#define SELM_HYPER_SEL_TSS 3
67/** The TSS selector for taking trap 08 (\#DF). */
68#define SELM_HYPER_SEL_TSS_TRAP08 4
69/** Number of GDTs we need for internal use */
70#define SELM_HYPER_SEL_MAX (SELM_HYPER_SEL_TSS_TRAP08 + 1)
71
72
73/** Default GDT selectors we use for the hypervisor. */
74#define SELM_HYPER_DEFAULT_SEL_CS ((SELM_GDT_ELEMENTS - 0x1) << 3)
75#define SELM_HYPER_DEFAULT_SEL_DS ((SELM_GDT_ELEMENTS - 0x2) << 3)
76#define SELM_HYPER_DEFAULT_SEL_CS64 ((SELM_GDT_ELEMENTS - 0x3) << 3)
77#define SELM_HYPER_DEFAULT_SEL_TSS ((SELM_GDT_ELEMENTS - 0x4) << 3)
78#define SELM_HYPER_DEFAULT_SEL_TSS_TRAP08 ((SELM_GDT_ELEMENTS - 0x5) << 3)
79/** The lowest value default we use. */
80#define SELM_HYPER_DEFAULT_BASE SELM_HYPER_DEFAULT_SEL_TSS_TRAP08
81
82/**
83 * Converts a SELM pointer into a VM pointer.
84 * @returns Pointer to the VM structure the SELM is part of.
85 * @param pSELM Pointer to SELM instance data.
86 */
87#define SELM2VM(pSELM) ( (PVM)((char *)pSELM - pSELM->offVM) )
88
89
90
91/**
92 * SELM Data (part of VM)
93 */
94typedef struct SELM
95{
96 /** Offset to the VM structure.
97 * See SELM2VM(). */
98 RTINT offVM;
99
100 /** Flat CS, DS, 64 bit mode CS, TSS & trap 8 TSS. */
101 RTSEL aHyperSel[SELM_HYPER_SEL_MAX];
102
103 /** Pointer to the GCs - R3 Ptr.
104 * This size is governed by SELM_GDT_ELEMENTS. */
105 R3PTRTYPE(PX86DESC) paGdtR3;
106 /** Pointer to the GCs - RC Ptr.
107 * This is not initialized until the first relocation because it's used to
108 * check if the shadow GDT virtual handler requires deregistration. */
109 RCPTRTYPE(PX86DESC) paGdtRC;
110 /** Current (last) Guest's GDTR.
111 * The pGdt member is set to RTRCPTR_MAX if we're not monitoring the guest GDT. */
112 VBOXGDTR GuestGdtr;
113 /** The current (last) effective Guest GDT size. */
114 RTUINT cbEffGuestGdtLimit;
115
116 uint32_t padding0;
117
118 /** R3 pointer to the LDT shadow area in HMA. */
119 R3PTRTYPE(void *) pvLdtR3;
120 /** RC pointer to the LDT shadow area in HMA. */
121 RCPTRTYPE(void *) pvLdtRC;
122#if GC_ARCH_BITS == 64
123 RTRCPTR padding1;
124#endif
125 /** The address of the guest LDT.
126 * RTRCPTR_MAX if not monitored. */
127 RTGCPTR GCPtrGuestLdt;
128 /** Current LDT limit, both Guest and Shadow. */
129 RTUINT cbLdtLimit;
130 /** Current LDT offset relative to pvLdtR3/pvLdtRC. */
131 RTUINT offLdtHyper;
132#if HC_ARCH_BITS == 32 && GC_ARCH_BITS == 64
133 uint32_t padding2[2];
134#endif
135 /** TSS. (This is 16 byte aligned!)
136 * @todo I/O bitmap & interrupt redirection table? */
137 VBOXTSS Tss;
138
139 /** TSS for trap 08 (\#DF). */
140 VBOXTSS TssTrap08;
141
142 /** Monitored shadow TSS address. */
143 RCPTRTYPE(void *) pvMonShwTssRC;
144#if GC_ARCH_BITS == 64
145 RTRCPTR padding3;
146#endif
147 /** GC Pointer to the current Guest's TSS.
148 * RTRCPTR_MAX if not monitored. */
149 RTGCPTR GCPtrGuestTss;
150 /** The size of the guest TSS. */
151 RTUINT cbGuestTss;
152 /** Set if it's a 32-bit TSS. */
153 bool fGuestTss32Bit;
154 /** The size of the Guest's TSS part we're monitoring. */
155 RTUINT cbMonitoredGuestTss;
156 /** The guest TSS selector at last sync (part of monitoring).
157 * Contains RTSEL_MAX if not set. */
158 RTSEL GCSelTss;
159 /** The last known offset of the I/O bitmap.
160 * This is only used if we monitor the bitmap. */
161 uint16_t offGuestIoBitmap;
162
163 /** Indicates that the Guest GDT access handler have been registered. */
164 bool fGDTRangeRegistered;
165
166 /** Indicates whether LDT/GDT/TSS monitoring and syncing is disabled. */
167 bool fDisableMonitoring;
168
169 /** Indicates whether the TSS stack selector & base address need to be refreshed. */
170 bool fSyncTSSRing0Stack;
171 bool fPadding2[1+2];
172
173 /** SELMR3UpdateFromCPUM() profiling. */
174 STAMPROFILE StatUpdateFromCPUM;
175 /** SELMR3SyncTSS() profiling. */
176 STAMPROFILE StatTSSSync;
177
178 /** GC: The number of handled writes to the Guest's GDT. */
179 STAMCOUNTER StatRCWriteGuestGDTHandled;
180 /** GC: The number of unhandled write to the Guest's GDT. */
181 STAMCOUNTER StatRCWriteGuestGDTUnhandled;
182 /** GC: The number of times writes to Guest's LDT was detected. */
183 STAMCOUNTER StatRCWriteGuestLDT;
184 /** GC: The number of handled writes to the Guest's TSS. */
185 STAMCOUNTER StatRCWriteGuestTSSHandled;
186 /** GC: The number of handled writes to the Guest's TSS where we detected a change. */
187 STAMCOUNTER StatRCWriteGuestTSSHandledChanged;
188 /** GC: The number of handled redir writes to the Guest's TSS where we detected a change. */
189 STAMCOUNTER StatRCWriteGuestTSSRedir;
190 /** GC: The number of unhandled writes to the Guest's TSS. */
191 STAMCOUNTER StatRCWriteGuestTSSUnhandled;
192 /** The number of times we had to relocate our hypervisor selectors. */
193 STAMCOUNTER StatHyperSelsChanged;
194 /** The number of times we had find free hypervisor selectors. */
195 STAMCOUNTER StatScanForHyperSels;
196 /** Counts the times we detected state selectors in SELMR3UpdateFromCPUM. */
197 STAMCOUNTER aStatDetectedStaleSReg[X86_SREG_COUNT];
198 /** Counts the times we were called with already state selectors in
199 * SELMR3UpdateFromCPUM. */
200 STAMCOUNTER aStatAlreadyStaleSReg[X86_SREG_COUNT];
201 /** Counts the times we found a stale selector becomming valid again. */
202 STAMCOUNTER StatStaleToUnstaleSReg;
203#ifdef VBOX_WITH_STATISTICS
204 /** Times we updated hidden selector registers in CPUMR3UpdateFromCPUM. */
205 STAMCOUNTER aStatUpdatedSReg[X86_SREG_COUNT];
206 STAMCOUNTER StatLoadHidSelGst;
207 STAMCOUNTER StatLoadHidSelShw;
208#endif
209 STAMCOUNTER StatLoadHidSelReadErrors;
210 STAMCOUNTER StatLoadHidSelGstNoGood;
211} SELM, *PSELM;
212
213RT_C_DECLS_BEGIN
214
215VMMRCDECL(int) selmRCGuestGDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
216VMMRCDECL(int) selmRCGuestLDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
217VMMRCDECL(int) selmRCGuestTSSWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
218
219VMMRCDECL(int) selmRCShadowGDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
220VMMRCDECL(int) selmRCShadowLDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
221VMMRCDECL(int) selmRCShadowTSSWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
222
223void selmSetRing1Stack(PVM pVM, uint32_t ss, RTGCPTR32 esp);
224#ifdef VBOX_WITH_RAW_RING1
225void selmSetRing2Stack(PVM pVM, uint32_t ss, RTGCPTR32 esp);
226#endif
227
228RT_C_DECLS_END
229
230/** @} */
231
232#endif
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette