VirtualBox

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

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

The Big Sun Rebranding Header Change

  • 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
37
38__BEGIN_DECLS
39
40/** @defgroup grp_selm The Selector Monitor(/Manager) API
41 * @{
42 */
43
44/**
45 * Returns Hypervisor's Trap 08 (\#DF) selector.
46 *
47 * @returns Hypervisor's Trap 08 (\#DF) selector.
48 * @param pVM VM Handle.
49 */
50SELMDECL(RTSEL) SELMGetTrap8Selector(PVM pVM);
51
52/**
53 * Sets EIP of Hypervisor's Trap 08 (\#DF) TSS.
54 *
55 * @param pVM VM Handle.
56 * @param u32EIP EIP of Trap 08 handler.
57 */
58SELMDECL(void) SELMSetTrap8EIP(PVM pVM, uint32_t u32EIP);
59
60/**
61 * Sets ss:esp for ring1 in main Hypervisor's TSS.
62 *
63 * @param pVM VM Handle.
64 * @param ss Ring1 SS register value.
65 * @param esp Ring1 ESP register value.
66 */
67SELMDECL(void) SELMSetRing1Stack(PVM pVM, uint32_t ss, uint32_t esp);
68
69/**
70 * Gets ss:esp for ring1 in main Hypervisor's TSS.
71 *
72 * @returns VBox status code.
73 * @param pVM VM Handle.
74 * @param pSS Ring1 SS register value.
75 * @param pEsp Ring1 ESP register value.
76 */
77SELMDECL(int) SELMGetRing1Stack(PVM pVM, uint32_t *pSS, uint32_t *pEsp);
78
79/**
80 * Returns Guest TSS pointer
81 *
82 * @param pVM VM Handle.
83 */
84SELMDECL(RTGCPTR) SELMGetGuestTSS(PVM pVM);
85
86/**
87 * Gets the hypervisor code selector (CS).
88 * @returns CS selector.
89 * @param pVM The VM handle.
90 */
91SELMDECL(RTSEL) SELMGetHyperCS(PVM pVM);
92
93/**
94 * Gets the 64-mode hypervisor code selector (CS64).
95 * @returns CS selector.
96 * @param pVM The VM handle.
97 */
98SELMDECL(RTSEL) SELMGetHyperCS64(PVM pVM);
99
100/**
101 * Gets the hypervisor data selector (DS).
102 * @returns DS selector.
103 * @param pVM The VM handle.
104 */
105SELMDECL(RTSEL) SELMGetHyperDS(PVM pVM);
106
107/**
108 * Gets the hypervisor TSS selector.
109 * @returns TSS selector.
110 * @param pVM The VM handle.
111 */
112SELMDECL(RTSEL) SELMGetHyperTSS(PVM pVM);
113
114/**
115 * Gets the hypervisor TSS Trap 8 selector.
116 * @returns TSS Trap 8 selector.
117 * @param pVM The VM handle.
118 */
119SELMDECL(RTSEL) SELMGetHyperTSSTrap08(PVM pVM);
120
121/**
122 * Gets the address for the hypervisor GDT.
123 *
124 * @returns The GDT address.
125 * @param pVM The VM handle.
126 * @remark This is intended only for very special use, like in the world
127 * switchers. Don't exploit this API!
128 */
129SELMDECL(RTGCPTR) SELMGetHyperGDT(PVM pVM);
130
131/**
132 * Gets info about the current TSS.
133 *
134 * @returns VBox status code.
135 * @retval VINF_SUCCESS if we've got a TSS loaded.
136 * @retval VERR_SELM_NO_TSS if we haven't got a TSS (rather unlikely).
137 *
138 * @param pVM The VM handle.
139 * @param pGCPtrTss Where to store the TSS address.
140 * @param pcbTss Where to store the TSS size limit.
141 * @param pfCanHaveIOBitmap Where to store the can-have-I/O-bitmap indicator. (optional)
142 */
143SELMDECL(int) SELMGetTSSInfo(PVM pVM, PRTGCUINTPTR pGCPtrTss, PRTGCUINTPTR pcbTss, bool *pfCanHaveIOBitmap);
144
145/**
146 * Converts a GC selector based address to a flat address.
147 *
148 * No limit checks are done. Use the SELMToFlat*() or SELMValidate*() functions
149 * for that.
150 *
151 * @returns Flat address.
152 * @param pVM VM Handle.
153 * @param eflags Current eflags
154 * @param Sel Selector part.
155 * @param pHiddenSel Hidden selector register
156 * @param Addr Address part.
157 */
158SELMDECL(RTGCPTR) SELMToFlat(PVM pVM, X86EFLAGS eflags, RTSEL Sel, PCPUMSELREGHID pHiddenSel, RTGCPTR Addr);
159
160/** Flags for SELMToFlatEx().
161 * @{ */
162/** Don't check the RPL,DPL or CPL. */
163#define SELMTOFLAT_FLAGS_NO_PL RT_BIT(8)
164/** Flags contains CPL information. */
165#define SELMTOFLAT_FLAGS_HAVE_CPL RT_BIT(9)
166/** CPL is 3. */
167#define SELMTOFLAT_FLAGS_CPL3 3
168/** CPL is 2. */
169#define SELMTOFLAT_FLAGS_CPL2 2
170/** CPL is 1. */
171#define SELMTOFLAT_FLAGS_CPL1 1
172/** CPL is 0. */
173#define SELMTOFLAT_FLAGS_CPL0 0
174/** Get the CPL from the flags. */
175#define SELMTOFLAT_FLAGS_CPL(fFlags) ((fFlags) & X86_SEL_RPL)
176/** Allow converting using Hypervisor GDT entries. */
177#define SELMTOFLAT_FLAGS_HYPER RT_BIT(10)
178/** @} */
179
180/**
181 * Converts a GC selector based address to a flat address.
182 *
183 * Some basic checking is done, but not all kinds yet.
184 *
185 * @returns VBox status
186 * @param pVM VM Handle.
187 * @param eflags Current eflags
188 * @param Sel Selector part.
189 * @param Addr Address part.
190 * @param pHiddenSel Hidden selector register (can be NULL)
191 * @param fFlags SELMTOFLAT_FLAGS_*
192 * GDT entires are valid.
193 * @param ppvGC Where to store the GC flat address.
194 * @param pcb Where to store the bytes from *ppvGC which can be accessed according to
195 * the selector. NULL is allowed.
196 */
197SELMDECL(int) SELMToFlatEx(PVM pVM, X86EFLAGS eflags, RTSEL Sel, RTGCPTR Addr, PCPUMSELREGHID pHiddenSel, unsigned fFlags, PRTGCPTR ppvGC, uint32_t *pcb);
198
199/**
200 * Validates and converts a GC selector based code address to a flat address.
201 *
202 * @returns VBox status code.
203 * @param pVM VM Handle.
204 * @param eflags Current eflags
205 * @param SelCPL Current privilege level. Get this from SS - CS might be conforming!
206 * A full selector can be passed, we'll only use the RPL part.
207 * @param SelCS Selector part.
208 * @param pHiddenSel The hidden CS selector register.
209 * @param Addr Address part.
210 * @param ppvFlat Where to store the flat address.
211 */
212SELMDECL(int) SELMValidateAndConvertCSAddr(PVM pVM, X86EFLAGS eflags, RTSEL SelCPL, RTSEL SelCS, PCPUMSELREGHID pHiddenCSSel, RTGCPTR Addr, PRTGCPTR ppvFlat);
213
214/**
215 * Validates and converts a GC selector based code address to a flat address.
216 *
217 * This is like SELMValidateAndConvertCSAddr + SELMIsSelector32Bit but with
218 * invalid hidden CS data. It's customized for dealing efficiently with CS
219 * at GC trap time.
220 *
221 * @returns VBox status code.
222 * @param pVM VM Handle.
223 * @param eflags Current eflags
224 * @param SelCPL Current privilege level. Get this from SS - CS might be conforming!
225 * A full selector can be passed, we'll only use the RPL part.
226 * @param SelCS Selector part.
227 * @param Addr Address part.
228 * @param ppvFlat Where to store the flat address.
229 * @param pcBits Where to store the 64-bit/32-bit/16-bit indicator.
230 */
231SELMDECL(int) SELMValidateAndConvertCSAddrGCTrap(PVM pVM, X86EFLAGS eflags, RTSEL SelCPL, RTSEL SelCS, RTGCPTR Addr, PRTGCPTR ppvFlat, uint32_t *pcBits);
232
233/**
234 * Checks if a selector is 32-bit or 16-bit.
235 *
236 * @returns True if it is 32-bit.
237 * @returns False if it is 16-bit.
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(bool) SELMIsSelector32Bit(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.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette