VirtualBox

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

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

SELMSelInfoIsExpandDown

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.1 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, CPUMSELREGHID *pHiddenSel, RTGCPTR Addr);
146
147/** Flags for SELMToFlatEx().
148 * @{ */
149/** Don't check the RPL,DPL or CPL. */
150#define SELMTOFLAT_FLAGS_NO_PL BIT(8)
151/** Flags contains CPL information. */
152#define SELMTOFLAT_FLAGS_HAVE_CPL 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 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, CPUMSELREGHID *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 Flat address.
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, CPUMSELREGHID *pHiddenCSSel, RTGCPTR Addr, PRTGCPTR ppvFlat);
200
201/**
202 * Checks if a selector is 32-bit or 16-bit.
203 *
204 * @returns True if it is 32-bit.
205 * @returns False if it is 16-bit.
206 * @param pVM VM Handle.
207 * @param eflags Current eflags register
208 * @param Sel The selector.
209 * @param pHiddenSel The hidden selector register.
210 */
211SELMDECL(bool) SELMIsSelector32Bit(PVM pVM, X86EFLAGS eflags, RTSEL Sel, CPUMSELREGHID *pHiddenSel);
212
213/**
214 * Returns flat address and limit of LDT by LDT selector.
215 *
216 * Fully validate selector.
217 *
218 * @returns VBox status.
219 * @param pVM VM Handle.
220 * @param SelLdt LDT selector.
221 * @param ppvLdt Where to store the flat address of LDT.
222 * @param pcbLimit Where to store LDT limit.
223 */
224SELMDECL(int) SELMGetLDTFromSel(PVM pVM, RTSEL SelLdt, PRTGCPTR ppvLdt, unsigned *pcbLimit);
225
226
227/**
228 * Selector information structure.
229 */
230typedef struct SELMSELINFO
231{
232 /** The base address. */
233 RTGCPTR GCPtrBase;
234 /** The limit (-1). */
235 RTGCUINTPTR cbLimit;
236 /** The raw descriptor. */
237 VBOXDESC Raw;
238 /** The selector. */
239 RTSEL Sel;
240 /** Set if the selector is used by the hypervisor. */
241 bool fHyper;
242 /** Set if the selector is a real mode segment. */
243 bool fRealMode;
244} SELMSELINFO;
245/** Pointer to a SELM selector information struct. */
246typedef SELMSELINFO *PSELMSELINFO;
247/** Pointer to a const SELM selector information struct. */
248typedef const SELMSELINFO *PCSELMSELINFO;
249
250/**
251 * Validates a CS selector.
252 *
253 * @returns VBox status code.
254 * @param pSelInfo Pointer to the selector information for the CS selector.
255 * @param SelCPL The selector defining the CPL (SS).
256 */
257SELMDECL(int) SELMSelInfoValidateCS(PCSELMSELINFO pSelInfo, RTSEL SelCPL);
258
259/** @def SELMSelInfoIsExpandDown
260 * Tests whether the selector info describes an expand-down selector or now.
261 *
262 * @returns true / false.
263 * @param pSelInfo The selector info.
264 *
265 * @remark Realized as a macro for reasons of speed/lazyness and to avoid
266 * dragging in VBox/x86.h for now.
267 */
268#define SELMSelInfoIsExpandDown(pSelInfo) \
269 ( (pSelInfo)->Raw.Gen.u1DescType \
270 && ((pSelInfo)->Raw.Gen.u4Type & (X86_SEL_TYPE_DOWN | X86_SEL_TYPE_CODE)) == X86_SEL_TYPE_DOWN)
271
272
273
274#ifdef IN_RING3
275/** @defgroup grp_selm_r3 The Selector Monitor(/Manager) API
276 * @ingroup grp_selm
277 * @{
278 */
279
280/**
281 * Initializes the SELM.
282 *
283 * @returns VBox status code.
284 * @param pVM The VM to operate on.
285 */
286SELMR3DECL(int) SELMR3Init(PVM pVM);
287
288/**
289 * Finalizes HMA page attributes.
290 *
291 * @returns VBox status code.
292 * @param pVM The VM handle.
293 */
294SELMR3DECL(int) SELMR3InitFinalize(PVM pVM);
295
296/**
297 * Applies relocations to data and code managed by this
298 * component. This function will be called at init and
299 * whenever the VMM need to relocate it self inside the GC.
300 *
301 * @param pVM The VM.
302 */
303SELMR3DECL(void) SELMR3Relocate(PVM pVM);
304
305/**
306 * Notification callback which is called whenever there is a chance that a CR3
307 * value might have changed.
308 * This is called by PGM.
309 *
310 * @param pVM The VM handle
311 */
312SELMR3DECL(void) SELMR3PagingModeChanged(PVM pVM);
313
314/**
315 * Terminates the SELM.
316 *
317 * Termination means cleaning up and freeing all resources,
318 * the VM it self is at this point powered off or suspended.
319 *
320 * @returns VBox status code.
321 * @param pVM The VM to operate on.
322 */
323SELMR3DECL(int) SELMR3Term(PVM pVM);
324
325/**
326 * The VM is being reset.
327 *
328 * For the SELM component this means that any GDT/LDT/TSS monitors
329 * needs to be removed.
330 *
331 * @param pVM VM handle.
332 */
333SELMR3DECL(void) SELMR3Reset(PVM pVM);
334
335/**
336 * Updates the Guest GDT & LDT virtualization based on current CPU state.
337 *
338 * @returns VBox status code.
339 * @param pVM The VM to operate on.
340 */
341SELMR3DECL(int) SELMR3UpdateFromCPUM(PVM pVM);
342
343/**
344 * Compares the Guest GDT and LDT with the shadow tables.
345 * This is a VBOX_STRICT only function.
346 *
347 * @returns VBox status code.
348 * @param pVM The VM Handle.
349 */
350SELMR3DECL(int) SELMR3DebugCheck(PVM pVM);
351#ifdef VBOX_STRICT
352# define SELMR3DEBUGCHECK(pVM) SELMR3DebugCheck(pVM)
353#else
354# define SELMR3DEBUGCHECK(pVM) do { } while (0)
355#endif
356
357/**
358 * Check if the TSS ring 0 stack selector and pointer were updated (for now)
359 *
360 * @returns VBox status code.
361 * @param pVM The VM to operate on.
362 */
363SELMR3DECL(int) SELMR3SyncTSS(PVM pVM);
364
365/**
366 * Gets information about a selector.
367 * Intended for the debugger mostly and will prefer the guest
368 * descriptor tables over the shadow ones.
369 *
370 * @returns VINF_SUCCESS on success.
371 * @returns VERR_INVALID_SELECTOR if the selector isn't fully inside the descriptor table.
372 * @returns VERR_SELECTOR_NOT_PRESENT if the selector wasn't present.
373 * @returns VERR_PAGE_TABLE_NOT_PRESENT or VERR_PAGE_NOT_PRESENT if the pagetable or page
374 * backing the selector table wasn't present.
375 * @returns Other VBox status code on other errros.
376 *
377 * @param pVM VM handle.
378 * @param Sel The selector to get info about.
379 * @param pSelInfo Where to store the information.
380 */
381SELMR3DECL(int) SELMR3GetSelectorInfo(PVM pVM, RTSEL Sel, PSELMSELINFO pSelInfo);
382
383/**
384 * Gets information about a selector from the shadow tables.
385 *
386 * This is intended to be faster than the SELMR3GetSelectorInfo() method, but requires
387 * that the caller ensures that the shadow tables are up to date.
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 errors.
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) SELMR3GetShadowSelectorInfo(PVM pVM, RTSEL Sel, PSELMSELINFO pSelInfo);
401
402/**
403 * Validates the RawR0 TSS values against the one in the Guest TSS.
404 *
405 * @returns true if it matches.
406 * @returns false and assertions on mismatch..
407 * @param pVM VM Handle.
408 */
409SELMR3DECL(bool) SELMR3CheckTSS(PVM pVM);
410
411
412/**
413 * Disable GDT/LDT/TSS monitoring and syncing
414 *
415 * @param pVM The VM to operate on.
416 */
417SELMR3DECL(void) SELMR3DisableMonitoring(PVM pVM);
418
419
420/**
421 * Dumps a descriptor.
422 *
423 * @param Desc Descriptor to dump.
424 * @param Sel Selector number.
425 * @param pszMsg Message to prepend the log entry with.
426 */
427SELMR3DECL(void) SELMR3DumpDescriptor(VBOXDESC Desc, RTSEL Sel, const char *pszMsg);
428
429/**
430 * Dumps the hypervisor GDT.
431 *
432 * @param pVM VM handle.
433 */
434SELMR3DECL(void) SELMR3DumpHyperGDT(PVM pVM);
435
436/**
437 * Dumps the hypervisor LDT.
438 *
439 * @param pVM VM handle.
440 */
441SELMR3DECL(void) SELMR3DumpHyperLDT(PVM pVM);
442
443/**
444 * Dumps the guest GDT.
445 *
446 * @param pVM VM handle.
447 */
448SELMR3DECL(void) SELMR3DumpGuestGDT(PVM pVM);
449
450/**
451 * Dumps the guest LDT.
452 *
453 * @param pVM VM handle.
454 */
455SELMR3DECL(void) SELMR3DumpGuestLDT(PVM pVM);
456
457/** @} */
458#endif
459
460
461/** @} */
462__END_DECLS
463
464
465#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