VirtualBox

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

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

string.h & stdio.h + header cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1/* $Id: TRPMGC.cpp 23 2007-01-15 14:08:28Z 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 (appropritate 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 ////LogCom(("trpmgcGuestIDTWriteHandler: eip=%08X pvFault=%08X pvRange=%08X\r\n", pRegFrame->eip, pvFault, pvRange));
108 VM_FF_SET(pVM, VM_FF_TRPM_SYNC_IDT);
109 /** @todo Check which IDT entry and keep the update cost low in TRPMR3SyncIDT() and CSAMCheckGates(). */
110
111 STAM_COUNTER_INC(&pVM->trpm.s.StatGCWriteGuestIDT);
112 return VINF_EM_RAW_EMULATE_INSTR_IDT_FAULT;
113}
114
115
116/**
117 * \#PF Virtual Handler callback for Guest write access to the VBox shadow IDT.
118 *
119 * @returns VBox status code (appropritate for trap handling and GC return).
120 * @param pVM VM Handle.
121 * @param uErrorCode CPU Error code.
122 * @param pRegFrame Trap register frame.
123 * @param pvFault The fault address (cr2).
124 * @param pvRange The base address of the handled virtual range.
125 * @param offRange The offset of the access into this range.
126 * (If it's a EIP range this's the EIP, if not it's pvFault.)
127 */
128TRPMGCDECL(int) trpmgcShadowIDTWriteHandler(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, void *pvFault, void *pvRange, uintptr_t offRange)
129{
130 ////LogCom(("trpmgcShadowIDTWriteHandler: eip=%08X pvFault=%08X pvRange=%08X\r\n", pRegFrame->eip, pvFault, pvRange));
131 return VERR_TRPM_SHADOW_IDT_WRITE;
132}
133
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