VirtualBox

source: vbox/trunk/include/VBox/selm.h@ 9658

Last change on this file since 9658 was 9658, checked in by vboxsync, 16 years ago

Renamed SELMIsSelector32Bit to SELMGetSelectorType.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.6 KB
Line 
1/** @file
2 * SELM - The Selector Monitor(/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/**
46 * Returns Hypervisor's Trap 08 (\#DF) selector.
47 *
48 * @returns Hypervisor's Trap 08 (\#DF) selector.
49 * @param pVM VM Handle.
50 */
51SELMDECL(RTSEL) SELMGetTrap8Selector(PVM pVM);
52
53/**
54 * Sets EIP of Hypervisor's Trap 08 (\#DF) TSS.
55 *
56 * @param pVM VM Handle.
57 * @param u32EIP EIP of Trap 08 handler.
58 */
59SELMDECL(void) SELMSetTrap8EIP(PVM pVM, uint32_t u32EIP);
60
61/**
62 * Sets ss:esp for ring1 in main Hypervisor's TSS.
63 *
64 * @param pVM VM Handle.
65 * @param ss Ring1 SS register value.
66 * @param esp Ring1 ESP register value.
67 */
68SELMDECL(void) SELMSetRing1Stack(PVM pVM, uint32_t ss, RTGCPTR32 esp);
69
70/**
71 * Gets ss:esp for ring1 in main Hypervisor's TSS.
72 *
73 * @returns VBox status code.
74 * @param pVM VM Handle.
75 * @param pSS Ring1 SS register value.
76 * @param pEsp Ring1 ESP register value.
77 */
78SELMDECL(int) SELMGetRing1Stack(PVM pVM, uint32_t *pSS, PRTGCPTR32 pEsp);
79
80/**
81 * Returns Guest TSS pointer
82 *
83 * @param pVM VM Handle.
84 */
85SELMDECL(RTGCPTR) SELMGetGuestTSS(PVM pVM);
86
87/**
88 * Gets the hypervisor code selector (CS).
89 * @returns CS selector.
90 * @param pVM The VM handle.
91 */
92SELMDECL(RTSEL) SELMGetHyperCS(PVM pVM);
93
94/**
95 * Gets the 64-mode hypervisor code selector (CS64).
96 * @returns CS selector.
97 * @param pVM The VM handle.
98 */
99SELMDECL(RTSEL) SELMGetHyperCS64(PVM pVM);
100
101/**
102 * Gets the hypervisor data selector (DS).
103 * @returns DS selector.
104 * @param pVM The VM handle.
105 */
106SELMDECL(RTSEL) SELMGetHyperDS(PVM pVM);
107
108/**
109 * Gets the hypervisor TSS selector.
110 * @returns TSS selector.
111 * @param pVM The VM handle.
112 */
113SELMDECL(RTSEL) SELMGetHyperTSS(PVM pVM);
114
115/**
116 * Gets the hypervisor TSS Trap 8 selector.
117 * @returns TSS Trap 8 selector.
118 * @param pVM The VM handle.
119 */
120SELMDECL(RTSEL) SELMGetHyperTSSTrap08(PVM pVM);
121
122/**
123 * Gets the address for the hypervisor GDT.
124 *
125 * @returns The GDT address.
126 * @param pVM The VM handle.
127 * @remark This is intended only for very special use, like in the world
128 * switchers. Don't exploit this API!
129 */
130SELMDECL(RTGCPTR) SELMGetHyperGDT(PVM pVM);
131
132/**
133 * Gets info about the current TSS.
134 *
135 * @returns VBox status code.
136 * @retval VINF_SUCCESS if we've got a TSS loaded.
137 * @retval VERR_SELM_NO_TSS if we haven't got a TSS (rather unlikely).
138 *
139 * @param pVM The VM handle.
140 * @param pGCPtrTss Where to store the TSS address.
141 * @param pcbTss Where to store the TSS size limit.
142 * @param pfCanHaveIOBitmap Where to store the can-have-I/O-bitmap indicator. (optional)
143 */
144SELMDECL(int) SELMGetTSSInfo(PVM pVM, PRTGCUINTPTR pGCPtrTss, PRTGCUINTPTR pcbTss, bool *pfCanHaveIOBitmap);
145
146/**
147 * Converts a GC selector based address to a flat address.
148 *
149 * No limit checks are done. Use the SELMToFlat*() or SELMValidate*() functions
150 * for that.
151 *
152 * @returns Flat address.
153 * @param pVM VM Handle.
154 * @param eflags Current eflags
155 * @param Sel Selector part.
156 * @param pHiddenSel Hidden selector register
157 * @param Addr Address part.
158 */
159SELMDECL(RTGCPTR) SELMToFlat(PVM pVM, X86EFLAGS eflags, RTSEL Sel, PCPUMSELREGHID pHiddenSel, RTGCPTR Addr);
160
161/** Flags for SELMToFlatEx().
162 * @{ */
163/** Don't check the RPL,DPL or CPL. */
164#define SELMTOFLAT_FLAGS_NO_PL RT_BIT(8)
165/** Flags contains CPL information. */
166#define SELMTOFLAT_FLAGS_HAVE_CPL RT_BIT(9)
167/** CPL is 3. */
168#define SELMTOFLAT_FLAGS_CPL3 3
169/** CPL is 2. */
170#define SELMTOFLAT_FLAGS_CPL2 2
171/** CPL is 1. */
172#define SELMTOFLAT_FLAGS_CPL1 1
173/** CPL is 0. */
174#define SELMTOFLAT_FLAGS_CPL0 0
175/** Get the CPL from the flags. */
176#define SELMTOFLAT_FLAGS_CPL(fFlags) ((fFlags) & X86_SEL_RPL)
177/** Allow converting using Hypervisor GDT entries. */
178#define SELMTOFLAT_FLAGS_HYPER RT_BIT(10)
179/** @} */
180
181/**
182 * Converts a GC selector based address to a flat address.
183 *
184 * Some basic checking is done, but not all kinds yet.
185 *
186 * @returns VBox status
187 * @param pVM VM Handle.
188 * @param eflags Current eflags
189 * @param Sel Selector part.
190 * @param Addr Address part.
191 * @param pHiddenSel Hidden selector register (can be NULL)
192 * @param fFlags SELMTOFLAT_FLAGS_*
193 * GDT entires are valid.
194 * @param ppvGC Where to store the GC flat address.
195 * @param pcb Where to store the bytes from *ppvGC which can be accessed according to
196 * the selector. NULL is allowed.
197 */
198SELMDECL(int) SELMToFlatEx(PVM pVM, X86EFLAGS eflags, RTSEL Sel, RTGCPTR Addr, PCPUMSELREGHID pHiddenSel, unsigned fFlags, PRTGCPTR ppvGC, uint32_t *pcb);
199
200/**
201 * Validates and converts a GC selector based code address to a flat address.
202 *
203 * @returns VBox status code.
204 * @param pVM VM Handle.
205 * @param eflags Current eflags
206 * @param SelCPL Current privilege level. Get this from SS - CS might be conforming!
207 * A full selector can be passed, we'll only use the RPL part.
208 * @param SelCS Selector part.
209 * @param pHiddenSel The hidden CS selector register.
210 * @param Addr Address part.
211 * @param ppvFlat Where to store the flat address.
212 */
213SELMDECL(int) SELMValidateAndConvertCSAddr(PVM pVM, X86EFLAGS eflags, RTSEL SelCPL, RTSEL SelCS, PCPUMSELREGHID pHiddenCSSel, RTGCPTR Addr, PRTGCPTR ppvFlat);
214
215/**
216 * Validates and converts a GC selector based code address to a flat address.
217 *
218 * This is like SELMValidateAndConvertCSAddr + SELMIsSelector32Bit but with
219 * invalid hidden CS data. It's customized for dealing efficiently with CS
220 * at GC trap time.
221 *
222 * @returns VBox status code.
223 * @param pVM VM Handle.
224 * @param eflags Current eflags
225 * @param SelCPL Current privilege level. Get this from SS - CS might be conforming!
226 * A full selector can be passed, we'll only use the RPL part.
227 * @param SelCS Selector part.
228 * @param Addr Address part.
229 * @param ppvFlat Where to store the flat address.
230 * @param pcBits Where to store the 64-bit/32-bit/16-bit indicator.
231 */
232SELMDECL(int) SELMValidateAndConvertCSAddrGCTrap(PVM pVM, X86EFLAGS eflags, RTSEL SelCPL, RTSEL SelCS, RTGCPTR Addr, PRTGCPTR ppvFlat, uint32_t *pcBits);
233
234/**
235 * Return the selector type
236 *
237 * @returns DISCPUMODE according to the selector type (16, 32 or 64 bits)
238 * @param pVM VM Handle.
239 * @param eflags Current eflags register
240 * @param Sel The selector.
241 * @param pHiddenSel The hidden selector register.
242 */
243SELMDECL(DISCPUMODE) SELMGetSelectorType(PVM pVM, X86EFLAGS eflags, RTSEL Sel, PCPUMSELREGHID pHiddenSel);
244
245/**
246 * Returns flat address and limit of LDT by LDT selector.
247 *
248 * Fully validate selector.
249 *
250 * @returns VBox status.
251 * @param pVM VM Handle.
252 * @param SelLdt LDT selector.
253 * @param ppvLdt Where to store the flat address of LDT.
254 * @param pcbLimit Where to store LDT limit.
255 */
256SELMDECL(int) SELMGetLDTFromSel(PVM pVM, RTSEL SelLdt, PRTGCPTR ppvLdt, unsigned *pcbLimit);
257
258
259/**
260 * Selector information structure.
261 */
262typedef struct SELMSELINFO
263{
264 /** The base address. */
265 RTGCPTR GCPtrBase;
266 /** The limit (-1). */
267 RTGCUINTPTR cbLimit;
268 /** The raw descriptor. */
269 VBOXDESC Raw;
270 /** The selector. */
271 RTSEL Sel;
272 /** Set if the selector is used by the hypervisor. */
273 bool fHyper;
274 /** Set if the selector is a real mode segment. */
275 bool fRealMode;
276} SELMSELINFO;
277/** Pointer to a SELM selector information struct. */
278typedef SELMSELINFO *PSELMSELINFO;
279/** Pointer to a const SELM selector information struct. */
280typedef const SELMSELINFO *PCSELMSELINFO;
281
282/**
283 * Validates a CS selector.
284 *
285 * @returns VBox status code.
286 * @param pSelInfo Pointer to the selector information for the CS selector.
287 * @param SelCPL The selector defining the CPL (SS).
288 */
289SELMDECL(int) SELMSelInfoValidateCS(PCSELMSELINFO pSelInfo, RTSEL SelCPL);
290
291/** @def SELMSelInfoIsExpandDown
292 * Tests whether the selector info describes an expand-down selector or now.
293 *
294 * @returns true / false.
295 * @param pSelInfo The selector info.
296 *
297 * @remark Realized as a macro for reasons of speed/lazyness and to avoid
298 * dragging in VBox/x86.h for now.
299 */
300#define SELMSelInfoIsExpandDown(pSelInfo) \
301 ( (pSelInfo)->Raw.Gen.u1DescType \
302 && ((pSelInfo)->Raw.Gen.u4Type & (X86_SEL_TYPE_DOWN | X86_SEL_TYPE_CODE)) == X86_SEL_TYPE_DOWN)
303
304
305
306#ifdef IN_RING3
307/** @defgroup grp_selm_r3 The Selector Monitor(/Manager) API
308 * @ingroup grp_selm
309 * @{
310 */
311
312/**
313 * Initializes the SELM.
314 *
315 * @returns VBox status code.
316 * @param pVM The VM to operate on.
317 */
318SELMR3DECL(int) SELMR3Init(PVM pVM);
319
320/**
321 * Finalizes HMA page attributes.
322 *
323 * @returns VBox status code.
324 * @param pVM The VM handle.
325 */
326SELMR3DECL(int) SELMR3InitFinalize(PVM pVM);
327
328/**
329 * Applies relocations to data and code managed by this
330 * component. This function will be called at init and
331 * whenever the VMM need to relocate it self inside the GC.
332 *
333 * @param pVM The VM.
334 */
335SELMR3DECL(void) SELMR3Relocate(PVM pVM);
336
337/**
338 * Notification callback which is called whenever there is a chance that a CR3
339 * value might have changed.
340 * This is called by PGM.
341 *
342 * @param pVM The VM handle
343 */
344SELMR3DECL(void) SELMR3PagingModeChanged(PVM pVM);
345
346/**
347 * Terminates the SELM.
348 *
349 * Termination means cleaning up and freeing all resources,
350 * the VM it self is at this point powered off or suspended.
351 *
352 * @returns VBox status code.
353 * @param pVM The VM to operate on.
354 */
355SELMR3DECL(int) SELMR3Term(PVM pVM);
356
357/**
358 * The VM is being reset.
359 *
360 * For the SELM component this means that any GDT/LDT/TSS monitors
361 * needs to be removed.
362 *
363 * @param pVM VM handle.
364 */
365SELMR3DECL(void) SELMR3Reset(PVM pVM);
366
367/**
368 * Updates the Guest GDT & LDT virtualization based on current CPU state.
369 *
370 * @returns VBox status code.
371 * @param pVM The VM to operate on.
372 */
373SELMR3DECL(int) SELMR3UpdateFromCPUM(PVM pVM);
374
375/**
376 * Compares the Guest GDT and LDT with the shadow tables.
377 * This is a VBOX_STRICT only function.
378 *
379 * @returns VBox status code.
380 * @param pVM The VM Handle.
381 */
382SELMR3DECL(int) SELMR3DebugCheck(PVM pVM);
383#ifdef VBOX_STRICT
384# define SELMR3DEBUGCHECK(pVM) SELMR3DebugCheck(pVM)
385#else
386# define SELMR3DEBUGCHECK(pVM) do { } while (0)
387#endif
388
389/**
390 * Check if the TSS ring 0 stack selector and pointer were updated (for now)
391 *
392 * @returns VBox status code.
393 * @param pVM The VM to operate on.
394 */
395SELMR3DECL(int) SELMR3SyncTSS(PVM pVM);
396
397/**
398 * Gets information about a selector.
399 * Intended for the debugger mostly and will prefer the guest
400 * descriptor tables over the shadow ones.
401 *
402 * @returns VINF_SUCCESS on success.
403 * @returns VERR_INVALID_SELECTOR if the selector isn't fully inside the descriptor table.
404 * @returns VERR_SELECTOR_NOT_PRESENT if the selector wasn't present.
405 * @returns VERR_PAGE_TABLE_NOT_PRESENT or VERR_PAGE_NOT_PRESENT if the pagetable or page
406 * backing the selector table wasn't present.
407 * @returns Other VBox status code on other errros.
408 *
409 * @param pVM VM handle.
410 * @param Sel The selector to get info about.
411 * @param pSelInfo Where to store the information.
412 */
413SELMR3DECL(int) SELMR3GetSelectorInfo(PVM pVM, RTSEL Sel, PSELMSELINFO pSelInfo);
414
415/**
416 * Gets information about a selector from the shadow tables.
417 *
418 * This is intended to be faster than the SELMR3GetSelectorInfo() method, but requires
419 * that the caller ensures that the shadow tables are up to date.
420 *
421 * @returns VINF_SUCCESS on success.
422 * @returns VERR_INVALID_SELECTOR if the selector isn't fully inside the descriptor table.
423 * @returns VERR_SELECTOR_NOT_PRESENT if the selector wasn't present.
424 * @returns VERR_PAGE_TABLE_NOT_PRESENT or VERR_PAGE_NOT_PRESENT if the pagetable or page
425 * backing the selector table wasn't present.
426 * @returns Other VBox status code on other errors.
427 *
428 * @param pVM VM handle.
429 * @param Sel The selector to get info about.
430 * @param pSelInfo Where to store the information.
431 */
432SELMR3DECL(int) SELMR3GetShadowSelectorInfo(PVM pVM, RTSEL Sel, PSELMSELINFO pSelInfo);
433
434/**
435 * Validates the RawR0 TSS values against the one in the Guest TSS.
436 *
437 * @returns true if it matches.
438 * @returns false and assertions on mismatch..
439 * @param pVM VM Handle.
440 */
441SELMR3DECL(bool) SELMR3CheckTSS(PVM pVM);
442
443
444/**
445 * Disable GDT/LDT/TSS monitoring and syncing
446 *
447 * @param pVM The VM to operate on.
448 */
449SELMR3DECL(void) SELMR3DisableMonitoring(PVM pVM);
450
451
452/**
453 * Dumps a descriptor.
454 *
455 * @param Desc Descriptor to dump.
456 * @param Sel Selector number.
457 * @param pszMsg Message to prepend the log entry with.
458 */
459SELMR3DECL(void) SELMR3DumpDescriptor(VBOXDESC Desc, RTSEL Sel, const char *pszMsg);
460
461/**
462 * Dumps the hypervisor GDT.
463 *
464 * @param pVM VM handle.
465 */
466SELMR3DECL(void) SELMR3DumpHyperGDT(PVM pVM);
467
468/**
469 * Dumps the hypervisor LDT.
470 *
471 * @param pVM VM handle.
472 */
473SELMR3DECL(void) SELMR3DumpHyperLDT(PVM pVM);
474
475/**
476 * Dumps the guest GDT.
477 *
478 * @param pVM VM handle.
479 */
480SELMR3DECL(void) SELMR3DumpGuestGDT(PVM pVM);
481
482/**
483 * Dumps the guest LDT.
484 *
485 * @param pVM VM handle.
486 */
487SELMR3DECL(void) SELMR3DumpGuestLDT(PVM pVM);
488
489/** @} */
490#endif
491
492
493/** @} */
494__END_DECLS
495
496
497#endif
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use