VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/PDMAllCritSectBoth.cpp

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: PDMAllCritSectBoth.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * PDM - Code Common to Both Critical Section Types, All Contexts.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_PDM_CRITSECT
33#include "PDMInternal.h"
34#include <VBox/vmm/pdmcritsect.h>
35#include <VBox/vmm/pdmcritsectrw.h>
36#include <VBox/vmm/vmcc.h>
37#include <iprt/errcore.h>
38
39#include <VBox/log.h>
40#include <iprt/assert.h>
41#include <iprt/asm.h>
42
43
44#if defined(IN_RING3) /*|| defined(IN_RING0) - not called from ring-0 */
45/**
46 * Process the critical sections (both types) queued for ring-3 'leave'.
47 *
48 * @param pVM The cross context VM structure.
49 * @param pVCpu The cross context virtual CPU structure.
50 */
51VMM_INT_DECL(void) PDMCritSectBothFF(PVMCC pVM, PVMCPUCC pVCpu)
52{
53 uint32_t i;
54 Assert( pVCpu->pdm.s.cQueuedCritSectLeaves > 0
55 || pVCpu->pdm.s.cQueuedCritSectRwShrdLeaves > 0
56 || pVCpu->pdm.s.cQueuedCritSectRwExclLeaves > 0);
57
58 /* Shared leaves. */
59 i = pVCpu->pdm.s.cQueuedCritSectRwShrdLeaves;
60 pVCpu->pdm.s.cQueuedCritSectRwShrdLeaves = 0;
61 while (i-- > 0)
62 {
63# ifdef IN_RING3
64 PPDMCRITSECTRW pCritSectRw = pVCpu->pdm.s.apQueuedCritSectRwShrdLeaves[i];
65# else
66 PPDMCRITSECTRW pCritSectRw = (PPDMCRITSECTRW)MMHyperR3ToCC(pVCpu->CTX_SUFF(pVM),
67 pVCpu->pdm.s.apQueuedCritSectRwShrdLeaves[i]);
68# endif
69
70 pdmCritSectRwLeaveSharedQueued(pVM, pCritSectRw);
71 LogIt(RTLOGGRPFLAGS_FLOW, LOG_GROUP_PDM_CRITSECTRW, ("PDMR3CritSectFF: %p (shared)\n", pCritSectRw));
72 }
73
74 /* Last, exclusive leaves. */
75 i = pVCpu->pdm.s.cQueuedCritSectRwExclLeaves;
76 pVCpu->pdm.s.cQueuedCritSectRwExclLeaves = 0;
77 while (i-- > 0)
78 {
79# ifdef IN_RING3
80 PPDMCRITSECTRW pCritSectRw = pVCpu->pdm.s.apQueuedCritSectRwExclLeaves[i];
81# else
82 PPDMCRITSECTRW pCritSectRw = (PPDMCRITSECTRW)MMHyperR3ToCC(pVCpu->CTX_SUFF(pVM),
83 pVCpu->pdm.s.apQueuedCritSectRwExclLeaves[i]);
84# endif
85
86 pdmCritSectRwLeaveExclQueued(pVM, pCritSectRw);
87 LogIt(RTLOGGRPFLAGS_FLOW, LOG_GROUP_PDM_CRITSECTRW, ("PDMR3CritSectFF: %p (exclusive)\n", pCritSectRw));
88 }
89
90 /* Normal leaves. */
91 i = pVCpu->pdm.s.cQueuedCritSectLeaves;
92 pVCpu->pdm.s.cQueuedCritSectLeaves = 0;
93 while (i-- > 0)
94 {
95# ifdef IN_RING3
96 PPDMCRITSECT pCritSect = pVCpu->pdm.s.apQueuedCritSectLeaves[i];
97# else
98 PPDMCRITSECT pCritSect = (PPDMCRITSECT)MMHyperR3ToCC(pVCpu->CTX_SUFF(pVM), pVCpu->pdm.s.apQueuedCritSectLeaves[i]);
99# endif
100 Assert(pCritSect->s.Core.NativeThreadOwner == pVCpu->hNativeThread);
101
102 /* Note! We *must* clear the pending-unlock flag here and not depend on
103 PDMCritSectLeave to do it, as the EMT might be sitting on
104 further nestings since it queued the section to be left, and
105 leaving it set would throw subsequent PDMCritSectIsOwner calls.
106
107 This will happen with the PGM lock if we nip back to ring-3 for
108 more handy pages or similar where the lock is supposed to be
109 held while in ring-3. */
110 ASMAtomicAndU32(&pCritSect->s.Core.fFlags, ~PDMCRITSECT_FLAGS_PENDING_UNLOCK);
111 PDMCritSectLeave(pVM, pCritSect);
112 LogFlow(("PDMR3CritSectFF: %p\n", pCritSect));
113 }
114
115 VMCPU_FF_CLEAR(pVCpu, VMCPU_FF_PDM_CRITSECT);
116}
117#endif /* IN_RING3 || IN_RING0 */
118
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use