VirtualBox

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

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

Rewrote SELMToFlatEx for long mode.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.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 SelReg Selector register
155 * @param pCtxCore CPU context
156 * @param Addr Address part.
157 */
158SELMDECL(RTGCPTR) SELMToFlat(PVM pVM, DIS_SELREG SelReg, PCPUMCTXCORE pCtxCore, RTGCPTR Addr);
159
160/**
161 * Converts a GC selector based address to a flat address.
162 *
163 * No limit checks are done. Use the SELMToFlat*() or SELMValidate*() functions
164 * for that.
165 *
166 * Note: obsolete; DO NOT USE!
167 *
168 * @returns Flat address.
169 * @param pVM VM Handle.
170 * @param Sel Selector part.
171 * @param Addr Address part.
172 */
173SELMDECL(RTGCPTR) SELMToFlatBySel(PVM pVM, RTSEL Sel, RTGCPTR Addr);
174
175/** Flags for SELMToFlatEx().
176 * @{ */
177/** Don't check the RPL,DPL or CPL. */
178#define SELMTOFLAT_FLAGS_NO_PL RT_BIT(8)
179/** Flags contains CPL information. */
180#define SELMTOFLAT_FLAGS_HAVE_CPL RT_BIT(9)
181/** CPL is 3. */
182#define SELMTOFLAT_FLAGS_CPL3 3
183/** CPL is 2. */
184#define SELMTOFLAT_FLAGS_CPL2 2
185/** CPL is 1. */
186#define SELMTOFLAT_FLAGS_CPL1 1
187/** CPL is 0. */
188#define SELMTOFLAT_FLAGS_CPL0 0
189/** Get the CPL from the flags. */
190#define SELMTOFLAT_FLAGS_CPL(fFlags) ((fFlags) & X86_SEL_RPL)
191/** Allow converting using Hypervisor GDT entries. */
192#define SELMTOFLAT_FLAGS_HYPER RT_BIT(10)
193/** @} */
194
195/**
196 * Converts a GC selector based address to a flat address.
197 *
198 * Some basic checking is done, but not all kinds yet.
199 *
200 * @returns VBox status
201 * @param pVM VM Handle.
202 * @param SelReg Selector register
203 * @param pCtxCore CPU context
204 * @param Addr Address part.
205 * @param fFlags SELMTOFLAT_FLAGS_*
206 * GDT entires are valid.
207 * @param ppvGC Where to store the GC flat address.
208 */
209SELMDECL(int) SELMToFlatEx(PVM pVM, DIS_SELREG SelReg, PCPUMCTXCORE pCtxCore, RTGCPTR Addr, unsigned fFlags, PRTGCPTR ppvGC);
210
211/**
212 * Converts a GC selector based address to a flat address.
213 *
214 * Some basic checking is done, but not all kinds yet.
215 *
216 * Note: Obsolete: DO NOT USE
217 *
218 * @returns VBox status
219 * @param pVM VM Handle.
220 * @param eflags Current eflags
221 * @param Sel Selector part.
222 * @param Addr Address part.
223 * @param pHiddenSel Hidden selector register (can be NULL)
224 * @param fFlags SELMTOFLAT_FLAGS_*
225 * GDT entires are valid.
226 * @param ppvGC Where to store the GC flat address.
227 * @param pcb Where to store the bytes from *ppvGC which can be accessed according to
228 * the selector. NULL is allowed.
229 */
230SELMDECL(int) SELMToFlatBySelEx(PVM pVM, X86EFLAGS eflags, RTSEL Sel, RTGCPTR Addr, CPUMSELREGHID *pHiddenSel, unsigned fFlags, PRTGCPTR ppvGC, uint32_t *pcb);
231
232/**
233 * Validates and converts a GC selector based code address to a flat address.
234 *
235 * @returns VBox status code.
236 * @param pVM VM Handle.
237 * @param eflags Current eflags
238 * @param SelCPL Current privilege level. Get this from SS - CS might be conforming!
239 * A full selector can be passed, we'll only use the RPL part.
240 * @param SelCS Selector part.
241 * @param pHiddenSel The hidden CS selector register.
242 * @param Addr Address part.
243 * @param ppvFlat Where to store the flat address.
244 */
245SELMDECL(int) SELMValidateAndConvertCSAddr(PVM pVM, X86EFLAGS eflags, RTSEL SelCPL, RTSEL SelCS, PCPUMSELREGHID pHiddenCSSel, RTGCPTR Addr, PRTGCPTR ppvFlat);
246
247/**
248 * Validates and converts a GC selector based code address to a flat address.
249 *
250 * This is like SELMValidateAndConvertCSAddr + SELMIsSelector32Bit but with
251 * invalid hidden CS data. It's customized for dealing efficiently with CS
252 * at GC trap time.
253 *
254 * @returns VBox status code.
255 * @param pVM VM Handle.
256 * @param eflags Current eflags
257 * @param SelCPL Current privilege level. Get this from SS - CS might be conforming!
258 * A full selector can be passed, we'll only use the RPL part.
259 * @param SelCS Selector part.
260 * @param Addr Address part.
261 * @param ppvFlat Where to store the flat address.
262 * @param pcBits Where to store the 64-bit/32-bit/16-bit indicator.
263 */
264SELMDECL(int) SELMValidateAndConvertCSAddrGCTrap(PVM pVM, X86EFLAGS eflags, RTSEL SelCPL, RTSEL SelCS, RTGCPTR Addr, PRTGCPTR ppvFlat, uint32_t *pcBits);
265
266/**
267 * Return the cpu mode corresponding to the (CS) selector
268 *
269 * @returns DISCPUMODE according to the selector type (16, 32 or 64 bits)
270 * @param pVM VM Handle.
271 * @param eflags Current eflags register
272 * @param Sel The selector.
273 * @param pHiddenSel The hidden selector register.
274 */
275SELMDECL(DISCPUMODE) SELMGetCpuModeFromSelector(PVM pVM, X86EFLAGS eflags, RTSEL Sel, CPUMSELREGHID *pHiddenSel);
276
277/**
278 * Returns flat address and limit of LDT by LDT selector.
279 *
280 * Fully validate selector.
281 *
282 * @returns VBox status.
283 * @param pVM VM Handle.
284 * @param SelLdt LDT selector.
285 * @param ppvLdt Where to store the flat address of LDT.
286 * @param pcbLimit Where to store LDT limit.
287 */
288SELMDECL(int) SELMGetLDTFromSel(PVM pVM, RTSEL SelLdt, PRTGCPTR ppvLdt, unsigned *pcbLimit);
289
290
291/**
292 * Selector information structure.
293 */
294typedef struct SELMSELINFO
295{
296 /** The base address. */
297 RTGCPTR GCPtrBase;
298 /** The limit (-1). */
299 RTGCUINTPTR cbLimit;
300 /** The raw descriptor. */
301 VBOXDESC Raw;
302 /** The selector. */
303 RTSEL Sel;
304 /** Set if the selector is used by the hypervisor. */
305 bool fHyper;
306 /** Set if the selector is a real mode segment. */
307 bool fRealMode;
308} SELMSELINFO;
309/** Pointer to a SELM selector information struct. */
310typedef SELMSELINFO *PSELMSELINFO;
311/** Pointer to a const SELM selector information struct. */
312typedef const SELMSELINFO *PCSELMSELINFO;
313
314/**
315 * Validates a CS selector.
316 *
317 * @returns VBox status code.
318 * @param pSelInfo Pointer to the selector information for the CS selector.
319 * @param SelCPL The selector defining the CPL (SS).
320 */
321SELMDECL(int) SELMSelInfoValidateCS(PCSELMSELINFO pSelInfo, RTSEL SelCPL);
322
323/** @def SELMSelInfoIsExpandDown
324 * Tests whether the selector info describes an expand-down selector or now.
325 *
326 * @returns true / false.
327 * @param pSelInfo The selector info.
328 *
329 * @remark Realized as a macro for reasons of speed/lazyness and to avoid
330 * dragging in VBox/x86.h for now.
331 */
332#define SELMSelInfoIsExpandDown(pSelInfo) \
333 ( (pSelInfo)->Raw.Gen.u1DescType \
334 && ((pSelInfo)->Raw.Gen.u4Type & (X86_SEL_TYPE_DOWN | X86_SEL_TYPE_CODE)) == X86_SEL_TYPE_DOWN)
335
336
337
338#ifdef IN_RING3
339/** @defgroup grp_selm_r3 The Selector Monitor(/Manager) API
340 * @ingroup grp_selm
341 * @{
342 */
343
344/**
345 * Initializes the SELM.
346 *
347 * @returns VBox status code.
348 * @param pVM The VM to operate on.
349 */
350SELMR3DECL(int) SELMR3Init(PVM pVM);
351
352/**
353 * Finalizes HMA page attributes.
354 *
355 * @returns VBox status code.
356 * @param pVM The VM handle.
357 */
358SELMR3DECL(int) SELMR3InitFinalize(PVM pVM);
359
360/**
361 * Applies relocations to data and code managed by this
362 * component. This function will be called at init and
363 * whenever the VMM need to relocate it self inside the GC.
364 *
365 * @param pVM The VM.
366 */
367SELMR3DECL(void) SELMR3Relocate(PVM pVM);
368
369/**
370 * Notification callback which is called whenever there is a chance that a CR3
371 * value might have changed.
372 * This is called by PGM.
373 *
374 * @param pVM The VM handle
375 */
376SELMR3DECL(void) SELMR3PagingModeChanged(PVM pVM);
377
378/**
379 * Terminates the SELM.
380 *
381 * Termination means cleaning up and freeing all resources,
382 * the VM it self is at this point powered off or suspended.
383 *
384 * @returns VBox status code.
385 * @param pVM The VM to operate on.
386 */
387SELMR3DECL(int) SELMR3Term(PVM pVM);
388
389/**
390 * The VM is being reset.
391 *
392 * For the SELM component this means that any GDT/LDT/TSS monitors
393 * needs to be removed.
394 *
395 * @param pVM VM handle.
396 */
397SELMR3DECL(void) SELMR3Reset(PVM pVM);
398
399/**
400 * Updates the Guest GDT & LDT virtualization based on current CPU state.
401 *
402 * @returns VBox status code.
403 * @param pVM The VM to operate on.
404 */
405SELMR3DECL(int) SELMR3UpdateFromCPUM(PVM pVM);
406
407/**
408 * Compares the Guest GDT and LDT with the shadow tables.
409 * This is a VBOX_STRICT only function.
410 *
411 * @returns VBox status code.
412 * @param pVM The VM Handle.
413 */
414SELMR3DECL(int) SELMR3DebugCheck(PVM pVM);
415#ifdef VBOX_STRICT
416# define SELMR3DEBUGCHECK(pVM) SELMR3DebugCheck(pVM)
417#else
418# define SELMR3DEBUGCHECK(pVM) do { } while (0)
419#endif
420
421/**
422 * Check if the TSS ring 0 stack selector and pointer were updated (for now)
423 *
424 * @returns VBox status code.
425 * @param pVM The VM to operate on.
426 */
427SELMR3DECL(int) SELMR3SyncTSS(PVM pVM);
428
429/**
430 * Gets information about a selector.
431 * Intended for the debugger mostly and will prefer the guest
432 * descriptor tables over the shadow ones.
433 *
434 * @returns VINF_SUCCESS on success.
435 * @returns VERR_INVALID_SELECTOR if the selector isn't fully inside the descriptor table.
436 * @returns VERR_SELECTOR_NOT_PRESENT if the selector wasn't present.
437 * @returns VERR_PAGE_TABLE_NOT_PRESENT or VERR_PAGE_NOT_PRESENT if the pagetable or page
438 * backing the selector table wasn't present.
439 * @returns Other VBox status code on other errros.
440 *
441 * @param pVM VM handle.
442 * @param Sel The selector to get info about.
443 * @param pSelInfo Where to store the information.
444 */
445SELMR3DECL(int) SELMR3GetSelectorInfo(PVM pVM, RTSEL Sel, PSELMSELINFO pSelInfo);
446
447/**
448 * Gets information about a selector from the shadow tables.
449 *
450 * This is intended to be faster than the SELMR3GetSelectorInfo() method, but requires
451 * that the caller ensures that the shadow tables are up to date.
452 *
453 * @returns VINF_SUCCESS on success.
454 * @returns VERR_INVALID_SELECTOR if the selector isn't fully inside the descriptor table.
455 * @returns VERR_SELECTOR_NOT_PRESENT if the selector wasn't present.
456 * @returns VERR_PAGE_TABLE_NOT_PRESENT or VERR_PAGE_NOT_PRESENT if the pagetable or page
457 * backing the selector table wasn't present.
458 * @returns Other VBox status code on other errors.
459 *
460 * @param pVM VM handle.
461 * @param Sel The selector to get info about.
462 * @param pSelInfo Where to store the information.
463 */
464SELMR3DECL(int) SELMR3GetShadowSelectorInfo(PVM pVM, RTSEL Sel, PSELMSELINFO pSelInfo);
465
466/**
467 * Validates the RawR0 TSS values against the one in the Guest TSS.
468 *
469 * @returns true if it matches.
470 * @returns false and assertions on mismatch..
471 * @param pVM VM Handle.
472 */
473SELMR3DECL(bool) SELMR3CheckTSS(PVM pVM);
474
475
476/**
477 * Disable GDT/LDT/TSS monitoring and syncing
478 *
479 * @param pVM The VM to operate on.
480 */
481SELMR3DECL(void) SELMR3DisableMonitoring(PVM pVM);
482
483
484/**
485 * Dumps a descriptor.
486 *
487 * @param Desc Descriptor to dump.
488 * @param Sel Selector number.
489 * @param pszMsg Message to prepend the log entry with.
490 */
491SELMR3DECL(void) SELMR3DumpDescriptor(VBOXDESC Desc, RTSEL Sel, const char *pszMsg);
492
493/**
494 * Dumps the hypervisor GDT.
495 *
496 * @param pVM VM handle.
497 */
498SELMR3DECL(void) SELMR3DumpHyperGDT(PVM pVM);
499
500/**
501 * Dumps the hypervisor LDT.
502 *
503 * @param pVM VM handle.
504 */
505SELMR3DECL(void) SELMR3DumpHyperLDT(PVM pVM);
506
507/**
508 * Dumps the guest GDT.
509 *
510 * @param pVM VM handle.
511 */
512SELMR3DECL(void) SELMR3DumpGuestGDT(PVM pVM);
513
514/**
515 * Dumps the guest LDT.
516 *
517 * @param pVM VM handle.
518 */
519SELMR3DECL(void) SELMR3DumpGuestLDT(PVM pVM);
520
521/** @} */
522#endif
523
524
525/** @} */
526__END_DECLS
527
528
529#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