VirtualBox

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

Last change on this file since 5605 was 5605, checked in by vboxsync, 17 years ago

BIT => RT_BIT, BIT64 => RT_BIT_64. BIT() is defined in Linux 2.6.24

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