VirtualBox

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

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