VirtualBox

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

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

Eliminate cpum.h dependency (shuts up a bunch of .c warnings). Fixed the header tests.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use