1 | /* $Id: VMMRZ.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMM - Virtual Machine Monitor, Raw-mode and ring-0 context code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2022 Oracle Corporation
|
---|
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 (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_VMM
|
---|
23 | #include <VBox/vmm/vmm.h>
|
---|
24 | #include "VMMInternal.h"
|
---|
25 | #include <VBox/vmm/vmcc.h>
|
---|
26 |
|
---|
27 | #include <iprt/assert.h>
|
---|
28 | #include <iprt/asm-amd64-x86.h>
|
---|
29 | #include <iprt/errcore.h>
|
---|
30 | #include <iprt/string.h>
|
---|
31 |
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Disables all host calls, except certain fatal ones.
|
---|
35 | *
|
---|
36 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
37 | * @thread EMT.
|
---|
38 | */
|
---|
39 | VMMRZDECL(void) VMMRZCallRing3Disable(PVMCPUCC pVCpu)
|
---|
40 | {
|
---|
41 | VMCPU_ASSERT_EMT(pVCpu);
|
---|
42 | #if defined(LOG_ENABLED) && defined(IN_RING0)
|
---|
43 | RTCCUINTREG fFlags = ASMIntDisableFlags(); /* preemption consistency. */
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | Assert(pVCpu->vmmr0.s.cCallRing3Disabled < 16);
|
---|
47 | if (ASMAtomicUoIncU32(&pVCpu->vmmr0.s.cCallRing3Disabled) == 1)
|
---|
48 | {
|
---|
49 | #ifdef IN_RC
|
---|
50 | pVCpu->pVMRC->vmm.s.fRCLoggerFlushingDisabled = true;
|
---|
51 | #else
|
---|
52 | pVCpu->vmmr0.s.fLogFlushingDisabled = true;
|
---|
53 | #endif
|
---|
54 | }
|
---|
55 |
|
---|
56 | #if defined(LOG_ENABLED) && defined(IN_RING0)
|
---|
57 | ASMSetFlags(fFlags);
|
---|
58 | #endif
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Counters VMMRZCallRing3Disable() and re-enables host calls.
|
---|
64 | *
|
---|
65 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
66 | * @thread EMT.
|
---|
67 | */
|
---|
68 | VMMRZDECL(void) VMMRZCallRing3Enable(PVMCPUCC pVCpu)
|
---|
69 | {
|
---|
70 | VMCPU_ASSERT_EMT(pVCpu);
|
---|
71 | #if defined(LOG_ENABLED) && defined(IN_RING0)
|
---|
72 | RTCCUINTREG fFlags = ASMIntDisableFlags(); /* preemption consistency. */
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | Assert(pVCpu->vmmr0.s.cCallRing3Disabled > 0);
|
---|
76 | if (ASMAtomicUoDecU32(&pVCpu->vmmr0.s.cCallRing3Disabled) == 0)
|
---|
77 | {
|
---|
78 | #ifdef IN_RC
|
---|
79 | pVCpu->pVMRC->vmm.s.fRCLoggerFlushingDisabled = false;
|
---|
80 | #else
|
---|
81 | pVCpu->vmmr0.s.fLogFlushingDisabled = false;
|
---|
82 | #endif
|
---|
83 | }
|
---|
84 |
|
---|
85 | #if defined(LOG_ENABLED) && defined(IN_RING0)
|
---|
86 | ASMSetFlags(fFlags);
|
---|
87 | #endif
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Checks whether its possible to call host context or not.
|
---|
93 | *
|
---|
94 | * @returns true if it's safe, false if it isn't.
|
---|
95 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
96 | */
|
---|
97 | VMMRZDECL(bool) VMMRZCallRing3IsEnabled(PVMCPUCC pVCpu)
|
---|
98 | {
|
---|
99 | VMCPU_ASSERT_EMT(pVCpu);
|
---|
100 | Assert(pVCpu->vmmr0.s.cCallRing3Disabled <= 16);
|
---|
101 | return pVCpu->vmmr0.s.cCallRing3Disabled == 0;
|
---|
102 | }
|
---|
103 |
|
---|