VirtualBox

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

Last change on this file since 45563 was 45533, checked in by vboxsync, 12 years ago

#ifdef the raw-mode force flags to find more code to #ifdef out.

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