1 | /** @file
|
---|
2 | * SELM - The Selector Manager.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
27 | * additional information or have any questions.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef ___VBox_selm_h
|
---|
31 | #define ___VBox_selm_h
|
---|
32 |
|
---|
33 | #include <VBox/cdefs.h>
|
---|
34 | #include <VBox/types.h>
|
---|
35 | #include <VBox/x86.h>
|
---|
36 | #include <VBox/dis.h>
|
---|
37 |
|
---|
38 |
|
---|
39 | __BEGIN_DECLS
|
---|
40 |
|
---|
41 | /** @defgroup grp_selm The Selector Monitor(/Manager) API
|
---|
42 | * @{
|
---|
43 | */
|
---|
44 |
|
---|
45 | VMMDECL(RTSEL) SELMGetTrap8Selector(PVM pVM);
|
---|
46 | VMMDECL(void) SELMSetTrap8EIP(PVM pVM, uint32_t u32EIP);
|
---|
47 | VMMDECL(void) SELMSetRing1Stack(PVM pVM, uint32_t ss, RTGCPTR32 esp);
|
---|
48 | VMMDECL(int) SELMGetRing1Stack(PVM pVM, uint32_t *pSS, PRTGCPTR32 pEsp);
|
---|
49 | VMMDECL(RTGCPTR) SELMGetGuestTSS(PVM pVM);
|
---|
50 | VMMDECL(RTSEL) SELMGetHyperCS(PVM pVM);
|
---|
51 | VMMDECL(RTSEL) SELMGetHyperCS64(PVM pVM);
|
---|
52 | VMMDECL(RTSEL) SELMGetHyperDS(PVM pVM);
|
---|
53 | VMMDECL(RTSEL) SELMGetHyperTSS(PVM pVM);
|
---|
54 | VMMDECL(RTSEL) SELMGetHyperTSSTrap08(PVM pVM);
|
---|
55 | VMMDECL(RTRCPTR) SELMGetHyperGDT(PVM pVM);
|
---|
56 | VMMDECL(int) SELMGetTSSInfo(PVM pVM, PRTGCUINTPTR pGCPtrTss, PRTGCUINTPTR pcbTss, bool *pfCanHaveIOBitmap);
|
---|
57 | VMMDECL(RTGCPTR) SELMToFlat(PVM pVM, DIS_SELREG SelReg, PCPUMCTXCORE pCtxCore, RTGCPTR Addr);
|
---|
58 | VMMDECL(RTGCPTR) SELMToFlatBySel(PVM pVM, RTSEL Sel, RTGCPTR Addr);
|
---|
59 |
|
---|
60 | /** Flags for SELMToFlatEx().
|
---|
61 | * @{ */
|
---|
62 | /** Don't check the RPL,DPL or CPL. */
|
---|
63 | #define SELMTOFLAT_FLAGS_NO_PL RT_BIT(8)
|
---|
64 | /** Flags contains CPL information. */
|
---|
65 | #define SELMTOFLAT_FLAGS_HAVE_CPL RT_BIT(9)
|
---|
66 | /** CPL is 3. */
|
---|
67 | #define SELMTOFLAT_FLAGS_CPL3 3
|
---|
68 | /** CPL is 2. */
|
---|
69 | #define SELMTOFLAT_FLAGS_CPL2 2
|
---|
70 | /** CPL is 1. */
|
---|
71 | #define SELMTOFLAT_FLAGS_CPL1 1
|
---|
72 | /** CPL is 0. */
|
---|
73 | #define SELMTOFLAT_FLAGS_CPL0 0
|
---|
74 | /** Get the CPL from the flags. */
|
---|
75 | #define SELMTOFLAT_FLAGS_CPL(fFlags) ((fFlags) & X86_SEL_RPL)
|
---|
76 | /** Allow converting using Hypervisor GDT entries. */
|
---|
77 | #define SELMTOFLAT_FLAGS_HYPER RT_BIT(10)
|
---|
78 | /** @} */
|
---|
79 |
|
---|
80 | VMMDECL(int) SELMToFlatEx(PVM pVM, DIS_SELREG SelReg, PCCPUMCTXCORE pCtxCore, RTGCPTR Addr, unsigned fFlags, PRTGCPTR ppvGC);
|
---|
81 | VMMDECL(int) SELMToFlatBySelEx(PVM pVM, X86EFLAGS eflags, RTSEL Sel, RTGCPTR Addr, PCPUMSELREGHID pHiddenSel, unsigned fFlags, PRTGCPTR ppvGC, uint32_t *pcb);
|
---|
82 | VMMDECL(int) SELMValidateAndConvertCSAddr(PVM pVM, X86EFLAGS eflags, RTSEL SelCPL, RTSEL SelCS, PCPUMSELREGHID pHiddenCSSel, RTGCPTR Addr, PRTGCPTR ppvFlat);
|
---|
83 | VMMDECL(int) SELMValidateAndConvertCSAddrGCTrap(PVM pVM, X86EFLAGS eflags, RTSEL SelCPL, RTSEL SelCS, RTGCPTR Addr, PRTGCPTR ppvFlat, uint32_t *pcBits);
|
---|
84 | VMMDECL(DISCPUMODE) SELMGetCpuModeFromSelector(PVM pVM, X86EFLAGS eflags, RTSEL Sel, PCPUMSELREGHID pHiddenSel);
|
---|
85 | VMMDECL(int) SELMGetLDTFromSel(PVM pVM, RTSEL SelLdt, PRTGCPTR ppvLdt, unsigned *pcbLimit);
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Selector information structure.
|
---|
89 | */
|
---|
90 | typedef struct SELMSELINFO
|
---|
91 | {
|
---|
92 | /** The base address. */
|
---|
93 | RTGCPTR GCPtrBase;
|
---|
94 | /** The limit (-1). */
|
---|
95 | RTGCUINTPTR cbLimit;
|
---|
96 | /** The raw descriptor. */
|
---|
97 | union
|
---|
98 | {
|
---|
99 | X86DESC Raw;
|
---|
100 | X86DESC64 Raw64;
|
---|
101 | };
|
---|
102 | /** The selector. */
|
---|
103 | RTSEL Sel;
|
---|
104 | /** Set if the selector is used by the hypervisor. */
|
---|
105 | bool fHyper;
|
---|
106 | /** Set if the selector is a real mode segment. */
|
---|
107 | bool fRealMode;
|
---|
108 | } SELMSELINFO;
|
---|
109 | /** Pointer to a SELM selector information struct. */
|
---|
110 | typedef SELMSELINFO *PSELMSELINFO;
|
---|
111 | /** Pointer to a const SELM selector information struct. */
|
---|
112 | typedef const SELMSELINFO *PCSELMSELINFO;
|
---|
113 |
|
---|
114 | VMMDECL(int) SELMSelInfoValidateCS(PCSELMSELINFO pSelInfo, RTSEL SelCPL);
|
---|
115 |
|
---|
116 | /** @def SELMSelInfoIsExpandDown
|
---|
117 | * Tests whether the selector info describes an expand-down selector or now.
|
---|
118 | *
|
---|
119 | * @returns true / false.
|
---|
120 | * @param pSelInfo The selector info.
|
---|
121 | *
|
---|
122 | * @remark Realized as a macro for reasons of speed/lazyness and to avoid
|
---|
123 | * dragging in VBox/x86.h for now.
|
---|
124 | */
|
---|
125 | #define SELMSelInfoIsExpandDown(pSelInfo) \
|
---|
126 | ( (pSelInfo)->Raw.Gen.u1DescType \
|
---|
127 | && ((pSelInfo)->Raw.Gen.u4Type & (X86_SEL_TYPE_DOWN | X86_SEL_TYPE_CODE)) == X86_SEL_TYPE_DOWN)
|
---|
128 |
|
---|
129 |
|
---|
130 | #ifdef IN_RING3
|
---|
131 | /** @defgroup grp_selm_r3 The Selector Monitor(/Manager) API
|
---|
132 | * @ingroup grp_selm
|
---|
133 | * @{
|
---|
134 | */
|
---|
135 | VMMR3DECL(int) SELMR3Init(PVM pVM);
|
---|
136 | VMMR3DECL(int) SELMR3InitFinalize(PVM pVM);
|
---|
137 | VMMR3DECL(void) SELMR3Relocate(PVM pVM);
|
---|
138 | VMMR3DECL(void) SELMR3PagingModeChanged(PVM pVM);
|
---|
139 | VMMR3DECL(int) SELMR3Term(PVM pVM);
|
---|
140 | VMMR3DECL(void) SELMR3Reset(PVM pVM);
|
---|
141 | VMMR3DECL(int) SELMR3UpdateFromCPUM(PVM pVM);
|
---|
142 | VMMR3DECL(int) SELMR3SyncTSS(PVM pVM);
|
---|
143 | VMMR3DECL(int) SELMR3GetSelectorInfo(PVM pVM, RTSEL Sel, PSELMSELINFO pSelInfo);
|
---|
144 | VMMR3DECL(int) SELMR3GetShadowSelectorInfo(PVM pVM, RTSEL Sel, PSELMSELINFO pSelInfo);
|
---|
145 | VMMR3DECL(void) SELMR3DisableMonitoring(PVM pVM);
|
---|
146 | VMMR3DECL(void) SELMR3DumpDescriptor(X86DESC Desc, RTSEL Sel, const char *pszMsg);
|
---|
147 | VMMR3DECL(void) SELMR3DumpHyperGDT(PVM pVM);
|
---|
148 | VMMR3DECL(void) SELMR3DumpHyperLDT(PVM pVM);
|
---|
149 | VMMR3DECL(void) SELMR3DumpGuestGDT(PVM pVM);
|
---|
150 | VMMR3DECL(void) SELMR3DumpGuestLDT(PVM pVM);
|
---|
151 | VMMR3DECL(bool) SELMR3CheckTSS(PVM pVM);
|
---|
152 | VMMR3DECL(int) SELMR3DebugCheck(PVM pVM);
|
---|
153 | /** @def SELMR3_DEBUG_CHECK
|
---|
154 | * Invokes SELMR3DebugCheck in stricts builds. */
|
---|
155 | # ifdef VBOX_STRICT
|
---|
156 | # define SELMR3_DEBUG_CHECK(pVM) SELMR3DebugCheck(pVM)
|
---|
157 | # else
|
---|
158 | # define SELMR3_DEBUG_CHECK(pVM) do { } while (0)
|
---|
159 | # endif
|
---|
160 | /** @} */
|
---|
161 | #endif /* IN_RING3 */
|
---|
162 |
|
---|
163 | /** @} */
|
---|
164 | __END_DECLS
|
---|
165 |
|
---|
166 | #endif
|
---|
167 |
|
---|