1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/* $Id: VMMRZ.cpp $ */
/** @file
* VMM - Virtual Machine Monitor, Raw-mode and ring-0 context code.
*/
/*
* Copyright (C) 2009 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <VBox/vmm.h>
#include "VMMInternal.h"
#include <VBox/vm.h>
#include <VBox/err.h>
#include <iprt/assert.h>
#include <iprt/string.h>
/**
* Calls the ring-3 host code.
*
* @returns VBox status code of the ring-3 call.
* @retval VERR_VMM_RING3_CALL_DISABLED if called at the wrong time. This must
* be passed up the stack, or if that isn't possible then VMMRZCallRing3
* needs to change it into an assertion.
*
*
* @param pVM The VM handle.
* @param pVCpu The virtual CPU handle of the calling EMT.
* @param enmOperation The operation.
* @param uArg The argument to the operation.
*/
VMMRZDECL(int) VMMRZCallRing3(PVM pVM, PVMCPU pVCpu, VMMCALLRING3 enmOperation, uint64_t uArg)
{
VMCPU_ASSERT_EMT(pVCpu);
/*
* Check if calling ring-3 has been disabled and only let let fatal calls thru.
*/
if (RT_UNLIKELY( pVCpu->vmm.s.cCallRing3Disabled != 0
&& enmOperation != VMMCALLRING3_VM_R0_ASSERTION))
{
/*
* In most cases, it's sufficient to return a status code which
* will then be propagated up the code usually encountering several
* AssertRC invocations along the way. Hitting one of those is more
* helpful than stopping here.
*
* However, some doesn't check the status code because they are called
* from void functions, and for these we'll turn this into a ring-0
* assertion host call.
*/
if (enmOperation != VMMCALLRING3_REM_REPLAY_HANDLER_NOTIFICATIONS)
return VERR_VMM_RING3_CALL_DISABLED;
#ifdef IN_RC
RTStrPrintf(g_szRTAssertMsg1, sizeof(pVM->vmm.s.szRing0AssertMsg1),
"VMMRZCallRing3: enmOperation=%d uArg=%#llx idCpu=%#x\n", enmOperation, uArg, pVCpu->idCpu);
#endif
RTStrPrintf(pVM->vmm.s.szRing0AssertMsg1, sizeof(pVM->vmm.s.szRing0AssertMsg1),
"VMMRZCallRing3: enmOperation=%d uArg=%#llx idCpu=%#x\n", enmOperation, uArg, pVCpu->idCpu);
enmOperation = VMMCALLRING3_VM_R0_ASSERTION;
}
/*
* The normal path.
*/
/** @todo profile this! */
pVCpu->vmm.s.enmCallRing3Operation = enmOperation;
pVCpu->vmm.s.u64CallRing3Arg = uArg;
pVCpu->vmm.s.rcCallRing3 = VERR_INTERNAL_ERROR;
#ifdef IN_RC
pVM->vmm.s.pfnGuestToHostRC(VINF_VMM_CALL_HOST);
#else
int rc = vmmR0CallRing3LongJmp(&pVCpu->vmm.s.CallRing3JmpBufR0, VINF_VMM_CALL_HOST);
if (RT_FAILURE(rc))
return rc;
#endif
return pVCpu->vmm.s.rcCallRing3;
}
/**
* Simple wrapper that adds the pVCpu argument.
*
* @returns VBox status code of the ring-3 call.
* @retval VERR_VMM_RING3_CALL_DISABLED if called at the wrong time. This must
* be passed up the stack, or if that isn't possible then VMMRZCallRing3
* needs to change it into an assertion.
*
* @param pVM The VM handle.
* @param enmOperation The operation.
* @param uArg The argument to the operation.
*/
VMMRZDECL(int) VMMRZCallRing3NoCpu(PVM pVM, VMMCALLRING3 enmOperation, uint64_t uArg)
{
return VMMRZCallRing3(pVM, VMMGetCpu(pVM), enmOperation, uArg);
}
/**
* Disables all host calls, except certain fatal ones.
*
* @param pVCpu The CPU struct for the calling EMT.
* @thread EMT.
*/
VMMRZDECL(void) VMMRZCallRing3Disable(PVMCPU pVCpu)
{
VMCPU_ASSERT_EMT(pVCpu);
Assert(pVCpu->vmm.s.cCallRing3Disabled < 16);
if (++pVCpu->vmm.s.cCallRing3Disabled == 1)
{
/** @todo it might make more sense to just disable logging here, then we
* won't flush away important bits... but that goes both ways really. */
#ifdef IN_RC
pVCpu->pVMRC->vmm.s.fRCLoggerFlushingDisabled = true;
#else
# ifdef LOG_ENABLED
if (pVCpu->vmm.s.pR0LoggerR0)
pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = true;
# endif
#endif
}
}
/**
* Counters VMMRZCallRing3Disable and re-enables host calls.
*
* @param pVCpu The CPU struct for the calling EMT.
* @thread EMT.
*/
VMMRZDECL(void) VMMRZCallRing3Enable(PVMCPU pVCpu)
{
VMCPU_ASSERT_EMT(pVCpu);
Assert(pVCpu->vmm.s.cCallRing3Disabled > 0);
if (--pVCpu->vmm.s.cCallRing3Disabled == 0)
{
#ifdef IN_RC
pVCpu->pVMRC->vmm.s.fRCLoggerFlushingDisabled = false;
#else
# ifdef LOG_ENABLED
if (pVCpu->vmm.s.pR0LoggerR0)
pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = false;
# endif
#endif
}
}
/**
* Checks whether its possible to call host context or not.
*
* @returns true if it's safe, false if it isn't.
* @param pVCpu The CPU struct for the calling EMT.
*/
VMMRZDECL(bool) VMMRZCallRing3IsEnabled(PVMCPU pVCpu)
{
VMCPU_ASSERT_EMT(pVCpu);
Assert(pVCpu->vmm.s.cCallRing3Disabled <= 16);
return pVCpu->vmm.s.cCallRing3Disabled == 0;
}
|