VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMGC/TRPMGC.cpp@ 1327

Last change on this file since 1327 was 1327, checked in by vboxsync, 18 years ago

Some more logging.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1/* $Id: TRPMGC.cpp 1327 2007-03-08 12:23:15Z vboxsync $ */
2/** @file
3 * TRPM - The Trap Monitor, Guest Context
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_TRPM
27#include <VBox/trpm.h>
28#include <VBox/cpum.h>
29#include <VBox/vmm.h>
30#include "TRPMInternal.h"
31#include <VBox/vm.h>
32
33#include <VBox/err.h>
34#include <VBox/x86.h>
35#include <iprt/assert.h>
36#include <iprt/asm.h>
37#include <VBox/log.h>
38
39
40
41/**
42 * Arms a temporary trap handler for traps in Hypervisor code.
43 *
44 * The operation is similar to a System V signal handler. I.e. when the handler
45 * is called it is first set to default action. So, if you need to handler more
46 * than one trap, you must reinstall the handler.
47 *
48 * To uninstall the temporary handler, call this function with pfnHandler set to NULL.
49 *
50 * @returns VBox status.
51 * @param pVM VM handle.
52 * @param iTrap Trap number to install handler [0..255].
53 * @param pfnHandler Pointer to the handler. Use NULL for uninstalling the handler.
54 */
55TRPMGCDECL(int) TRPMGCSetTempHandler(PVM pVM, unsigned iTrap, PFNTRPMGCTRAPHANDLER pfnHandler)
56{
57 /*
58 * Validate input.
59 */
60 if (iTrap >= ELEMENTS(pVM->trpm.s.aTmpTrapHandlers))
61 {
62 AssertMsgFailed(("Trap handler iTrap=%u is out of range!\n", iTrap));
63 return VERR_INVALID_PARAMETER;
64 }
65
66 /*
67 * Install handler.
68 */
69 pVM->trpm.s.aTmpTrapHandlers[iTrap] = (RTGCPTR)(RTGCUINTPTR)pfnHandler;
70 return VINF_SUCCESS;
71}
72
73
74/**
75 * Return to host context from a hypervisor trap handler.
76 *
77 * This function will *never* return.
78 * It will also reset any traps that are pending.
79 *
80 * @param pVM The VM handle.
81 * @param rc The return code for host context.
82 */
83TRPMGCDECL(void) TRPMGCHyperReturnToHost(PVM pVM, int rc)
84{
85 LogFlow(("TRPMGCHyperReturnToHost: rc=%Vrc\n", rc));
86 TRPMResetTrap(pVM);
87 CPUMHyperSetCtxCore(pVM, NULL);
88 VMMGCGuestToHost(pVM, rc);
89 AssertReleaseFailed();
90}
91
92
93/**
94 * \#PF Virtual Handler callback for Guest write access to the Guest's own current IDT.
95 *
96 * @returns VBox status code (appropriate for trap handling and GC return).
97 * @param pVM VM Handle.
98 * @param uErrorCode CPU Error code.
99 * @param pRegFrame Trap register frame.
100 * @param pvFault The fault address (cr2).
101 * @param pvRange The base address of the handled virtual range.
102 * @param offRange The offset of the access into this range.
103 * (If it's a EIP range this's the EIP, if not it's pvFault.)
104 */
105TRPMGCDECL(int) trpmgcGuestIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, void *pvRange, uintptr_t offRange)
106{
107 uint16_t cbIDT;
108 RTGCPTR GCPtrIDT = (RTGCPTR)CPUMGetGuestIDTR(pVM, &cbIDT);
109#ifdef VBOX_STRICT
110 RTGCPTR GCPtrIDTEnd = (RTGCPTR)((RTGCUINTPTR)GCPtrIDT + cbIDT + 1);
111 uint32_t iTrap = ((RTGCUINTPTR)pvFault - (RTGCUINTPTR)GCPtrIDT)/sizeof(VBOXIDTE);
112#endif
113
114 Assert(pvFault >= GCPtrIDT && pvFault < GCPtrIDTEnd);
115 Log(("trpmgcGuestIDTWriteHandler: write to gate %x\n", iTrap));
116
117 ////LogCom(("trpmgcGuestIDTWriteHandler: eip=%08X pvFault=%08X pvRange=%08X\r\n", pRegFrame->eip, pvFault, pvRange));
118 VM_FF_SET(pVM, VM_FF_TRPM_SYNC_IDT);
119 /** @todo Check which IDT entry and keep the update cost low in TRPMR3SyncIDT() and CSAMCheckGates(). */
120
121 STAM_COUNTER_INC(&pVM->trpm.s.StatGCWriteGuestIDT);
122 return VINF_EM_RAW_EMULATE_INSTR_IDT_FAULT;
123}
124
125
126/**
127 * \#PF Virtual Handler callback for Guest write access to the VBox shadow IDT.
128 *
129 * @returns VBox status code (appropriate for trap handling and GC return).
130 * @param pVM VM Handle.
131 * @param uErrorCode CPU Error code.
132 * @param pRegFrame Trap register frame.
133 * @param pvFault The fault address (cr2).
134 * @param pvRange The base address of the handled virtual range.
135 * @param offRange The offset of the access into this range.
136 * (If it's a EIP range this's the EIP, if not it's pvFault.)
137 */
138TRPMGCDECL(int) trpmgcShadowIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, void *pvRange, uintptr_t offRange)
139{
140 ////LogCom(("trpmgcShadowIDTWriteHandler: eip=%08X pvFault=%08X pvRange=%08X\r\n", pRegFrame->eip, pvFault, pvRange));
141 return VERR_TRPM_SHADOW_IDT_WRITE;
142}
143
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