VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/PDMCritSect.cpp@ 45152

Last change on this file since 45152 was 45152, checked in by vboxsync, 12 years ago

PDMCritSectRw: Early morphing stage - untested, ring-3 only.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 39.7 KB
Line 
1/* $Id: PDMCritSect.cpp 45152 2013-03-23 20:36:23Z vboxsync $ */
2/** @file
3 * PDM - Critical Sections, Ring-3.
4 */
5
6/*
7 * Copyright (C) 2006-2012 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_PDM//_CRITSECT
23#include "PDMInternal.h"
24#include <VBox/vmm/pdmcritsect.h>
25#include <VBox/vmm/pdmcritsectrw.h>
26#include <VBox/vmm/mm.h>
27#include <VBox/vmm/vm.h>
28#include <VBox/vmm/uvm.h>
29
30#include <VBox/err.h>
31#include <VBox/log.h>
32#include <VBox/sup.h>
33#include <iprt/asm.h>
34#include <iprt/assert.h>
35#include <iprt/lockvalidator.h>
36#include <iprt/string.h>
37#include <iprt/thread.h>
38
39
40/*******************************************************************************
41* Internal Functions *
42*******************************************************************************/
43static int pdmR3CritSectDeleteOne(PVM pVM, PUVM pUVM, PPDMCRITSECTINT pCritSect, PPDMCRITSECTINT pPrev, bool fFinal);
44static int pdmR3CritSectRwDeleteOne(PVM pVM, PUVM pUVM, PPDMCRITSECTRWINT pCritSect, PPDMCRITSECTRWINT pPrev, bool fFinal);
45
46
47
48/**
49 * Register statistics related to the critical sections.
50 *
51 * @returns VBox status code.
52 * @param pVM Pointer to the VM.
53 */
54int pdmR3CritSectBothInitStats(PVM pVM)
55{
56 STAM_REG(pVM, &pVM->pdm.s.StatQueuedCritSectLeaves, STAMTYPE_COUNTER, "/PDM/QueuedCritSectLeaves", STAMUNIT_OCCURENCES,
57 "Number of times a critical section leave request needed to be queued for ring-3 execution.");
58 return VINF_SUCCESS;
59}
60
61
62/**
63 * Relocates all the critical sections.
64 *
65 * @param pVM Pointer to the VM.
66 */
67void pdmR3CritSectBothRelocate(PVM pVM)
68{
69 PUVM pUVM = pVM->pUVM;
70 RTCritSectEnter(&pUVM->pdm.s.ListCritSect);
71
72 for (PPDMCRITSECTINT pCur = pUVM->pdm.s.pCritSects;
73 pCur;
74 pCur = pCur->pNext)
75 pCur->pVMRC = pVM->pVMRC;
76
77 for (PPDMCRITSECTRWINT pCur = pUVM->pdm.s.pRwCritSects;
78 pCur;
79 pCur = pCur->pNext)
80 pCur->pVMRC = pVM->pVMRC;
81
82 RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
83}
84
85
86/**
87 * Deletes all remaining critical sections.
88 *
89 * This is called at the very end of the termination process. It is also called
90 * at the end of vmR3CreateU failure cleanup, which may cause it to be called
91 * twice depending on where vmR3CreateU actually failed. We have to do the
92 * latter call because other components expect the critical sections to be
93 * automatically deleted.
94 *
95 * @returns VBox status.
96 * First error code, rest is lost.
97 * @param pVMU The user mode VM handle.
98 * @remark Don't confuse this with PDMR3CritSectDelete.
99 */
100VMMR3_INT_DECL(int) PDMR3CritSectBothTerm(PVM pVM)
101{
102 PUVM pUVM = pVM->pUVM;
103 int rc = VINF_SUCCESS;
104 RTCritSectEnter(&pUVM->pdm.s.ListCritSect);
105
106 while (pUVM->pdm.s.pCritSects)
107 {
108 int rc2 = pdmR3CritSectDeleteOne(pVM, pUVM, pUVM->pdm.s.pCritSects, NULL, true /* final */);
109 AssertRC(rc2);
110 if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
111 rc = rc2;
112 }
113
114 while (pUVM->pdm.s.pRwCritSects)
115 {
116 int rc2 = pdmR3CritSectRwDeleteOne(pVM, pUVM, pUVM->pdm.s.pRwCritSects, NULL, true /* final */);
117 AssertRC(rc2);
118 if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
119 rc = rc2;
120 }
121
122 RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
123 return rc;
124}
125
126
127/**
128 * Initializes a critical section and inserts it into the list.
129 *
130 * @returns VBox status code.
131 * @param pVM Pointer to the VM.
132 * @param pCritSect The critical section.
133 * @param pvKey The owner key.
134 * @param RT_SRC_POS_DECL The source position.
135 * @param pszName The name of the critical section (for statistics).
136 * @param pszNameFmt Format string for naming the critical section. For
137 * statistics and lock validation.
138 * @param va Arguments for the format string.
139 */
140static int pdmR3CritSectInitOne(PVM pVM, PPDMCRITSECTINT pCritSect, void *pvKey, RT_SRC_POS_DECL,
141 const char *pszNameFmt, va_list va)
142{
143 VM_ASSERT_EMT(pVM);
144 Assert(pCritSect->Core.u32Magic != RTCRITSECT_MAGIC);
145
146 /*
147 * Allocate the semaphore.
148 */
149 AssertCompile(sizeof(SUPSEMEVENT) == sizeof(pCritSect->Core.EventSem));
150 int rc = SUPSemEventCreate(pVM->pSession, (PSUPSEMEVENT)&pCritSect->Core.EventSem);
151 if (RT_SUCCESS(rc))
152 {
153 /* Only format the name once. */
154 char *pszName = RTStrAPrintf2V(pszNameFmt, va); /** @todo plug the "leak"... */
155 if (pszName)
156 {
157#ifndef PDMCRITSECT_STRICT
158 pCritSect->Core.pValidatorRec = NULL;
159#else
160 rc = RTLockValidatorRecExclCreate(&pCritSect->Core.pValidatorRec,
161# ifdef RT_LOCK_STRICT_ORDER
162 RTLockValidatorClassForSrcPos(RT_SRC_POS_ARGS, "%s", pszName),
163# else
164 NIL_RTLOCKVALCLASS,
165# endif
166 RTLOCKVAL_SUB_CLASS_NONE,
167 pCritSect, true, "%s", pszName);
168#endif
169 if (RT_SUCCESS(rc))
170 {
171 /*
172 * Initialize the structure (first bit is c&p from RTCritSectInitEx).
173 */
174 pCritSect->Core.u32Magic = RTCRITSECT_MAGIC;
175 pCritSect->Core.fFlags = 0;
176 pCritSect->Core.cNestings = 0;
177 pCritSect->Core.cLockers = -1;
178 pCritSect->Core.NativeThreadOwner = NIL_RTNATIVETHREAD;
179 pCritSect->pVMR3 = pVM;
180 pCritSect->pVMR0 = pVM->pVMR0;
181 pCritSect->pVMRC = pVM->pVMRC;
182 pCritSect->pvKey = pvKey;
183 pCritSect->fAutomaticDefaultCritsect = false;
184 pCritSect->fUsedByTimerOrSimilar = false;
185 pCritSect->EventToSignal = NIL_RTSEMEVENT;
186 pCritSect->pszName = pszName;
187
188 STAMR3RegisterF(pVM, &pCritSect->StatContentionRZLock, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSects/%s/ContentionRZLock", pCritSect->pszName);
189 STAMR3RegisterF(pVM, &pCritSect->StatContentionRZUnlock,STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSects/%s/ContentionRZUnlock", pCritSect->pszName);
190 STAMR3RegisterF(pVM, &pCritSect->StatContentionR3, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSects/%s/ContentionR3", pCritSect->pszName);
191#ifdef VBOX_WITH_STATISTICS
192 STAMR3RegisterF(pVM, &pCritSect->StatLocked, STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, NULL, "/PDM/CritSects/%s/Locked", pCritSect->pszName);
193#endif
194
195 PUVM pUVM = pVM->pUVM;
196 RTCritSectEnter(&pUVM->pdm.s.ListCritSect);
197 pCritSect->pNext = pUVM->pdm.s.pCritSects;
198 pUVM->pdm.s.pCritSects = pCritSect;
199 RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
200
201 return VINF_SUCCESS;
202 }
203
204 RTStrFree(pszName);
205 }
206 else
207 rc = VERR_NO_STR_MEMORY;
208 SUPSemEventClose(pVM->pSession, (SUPSEMEVENT)pCritSect->Core.EventSem);
209 }
210 return rc;
211}
212
213
214/**
215 * Initializes a read/write critical section and inserts it into the list.
216 *
217 * @returns VBox status code.
218 * @param pVM Pointer to the VM.
219 * @param pCritSect The read/write critical section.
220 * @param pvKey The owner key.
221 * @param RT_SRC_POS_DECL The source position.
222 * @param pszName The name of the critical section (for statistics).
223 * @param pszNameFmt Format string for naming the critical section. For
224 * statistics and lock validation.
225 * @param va Arguments for the format string.
226 */
227static int pdmR3CritSectRwInitOne(PVM pVM, PPDMCRITSECTRWINT pCritSect, void *pvKey, RT_SRC_POS_DECL,
228 const char *pszNameFmt, va_list va)
229{
230 VM_ASSERT_EMT(pVM);
231 Assert(pCritSect->Core.u32Magic != RTCRITSECTRW_MAGIC);
232
233 /*
234 * Allocate the semaphores.
235 */
236 AssertCompile(sizeof(SUPSEMEVENT) == sizeof(pCritSect->Core.hEvtWrite));
237 int rc = SUPSemEventCreate(pVM->pSession, (PSUPSEMEVENT)&pCritSect->Core.hEvtWrite);
238 if (RT_SUCCESS(rc))
239 {
240 AssertCompile(sizeof(SUPSEMEVENTMULTI) == sizeof(pCritSect->Core.hEvtRead));
241 rc = SUPSemEventMultiCreate(pVM->pSession, (PSUPSEMEVENT)&pCritSect->Core.hEvtRead);
242 if (RT_SUCCESS(rc))
243 {
244 /* Only format the name once. */
245 char *pszName = RTStrAPrintf2V(pszNameFmt, va); /** @todo plug the "leak"... */
246 if (pszName)
247 {
248 pCritSect->Core.pValidatorRead = NULL;
249 pCritSect->Core.pValidatorWrite = NULL;
250#ifdef PDMCRITSECT_STRICT
251# ifdef RT_LOCK_STRICT_ORDER
252 RTLOCKVALCLASS hClass = RTLockValidatorClassForSrcPos(RT_SRC_POS_ARGS, "%s", pszName);
253# else
254 RTLOCKVALCLASS hClass = NIL_RTLOCKVALCLASS;
255# endif
256 rc = RTLockValidatorRecExclCreate(&pCritSect->Core.pValidatorWrite, hClass, RTLOCKVAL_SUB_CLASS_NONE,
257 pCritSect, true, "%s", pszName);
258 if (RT_SUCCESS(rc))
259 rc = RTLockValidatorRecSharedCreate(&pCritSect->Core.pValidatorRead, hClass, RTLOCKVAL_SUB_CLASS_NONE,
260 pCritSect, false /*fSignaller*/, true, "%s", pszName);
261#endif
262 if (RT_SUCCESS(rc))
263 {
264 /*
265 * Initialize the structure (first bit is c&p from RTCritSectRwInitEx).
266 */
267 pCritSect->Core.u32Magic = RTCRITSECTRW_MAGIC_DEAD;
268 pCritSect->Core.fNeedReset = false;
269 pCritSect->Core.u64State = 0;
270 pCritSect->Core.hNativeWriter = NIL_RTNATIVETHREAD;
271 pCritSect->Core.cWriterReads = 0;
272 pCritSect->Core.cWriteRecursions = 0;
273 pCritSect->Core.pValidatorWrite = NULL;
274 pCritSect->Core.pValidatorRead = NULL;
275#if HC_ARCH_BITS == 32
276 pCritSect->Core.HCPtrPadding = NIL_RTHCPTR;
277#endif
278 pCritSect->pVMR3 = pVM;
279 pCritSect->pVMR0 = pVM->pVMR0;
280 pCritSect->pVMRC = pVM->pVMRC;
281 pCritSect->pvKey = pvKey;
282 pCritSect->pszName = pszName;
283
284 STAMR3RegisterF(pVM, &pCritSect->StatContentionRZEnterExcl, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSectsRw/%s/ContentionRZEnterExcl", pCritSect->pszName);
285 STAMR3RegisterF(pVM, &pCritSect->StatContentionRZLeaveExcl, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSectsRw/%s/ContentionRZLeaveExcl", pCritSect->pszName);
286 STAMR3RegisterF(pVM, &pCritSect->StatContentionRZEnterShared, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSectsRw/%s/ContentionRZEnterShared", pCritSect->pszName);
287 STAMR3RegisterF(pVM, &pCritSect->StatContentionRZLeaveShared, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSectsRw/%s/ContentionRZLeaveShared", pCritSect->pszName);
288 STAMR3RegisterF(pVM, &pCritSect->StatContentionR3EnterExcl, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSectsRw/%s/ContentionR3EnterExcl", pCritSect->pszName);
289 STAMR3RegisterF(pVM, &pCritSect->StatContentionR3EnterShared, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSectsRw/%s/ContentionR3EnterShared", pCritSect->pszName);
290 STAMR3RegisterF(pVM, &pCritSect->StatRZEnterExcl, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSectsRw/%s/RZEnterExcl", pCritSect->pszName);
291 STAMR3RegisterF(pVM, &pCritSect->StatRZEnterShared, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSectsRw/%s/RZEnterShared", pCritSect->pszName);
292 STAMR3RegisterF(pVM, &pCritSect->StatR3EnterExcl, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSectsRw/%s/R3EnterExcl", pCritSect->pszName);
293 STAMR3RegisterF(pVM, &pCritSect->StatR3EnterShared, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, NULL, "/PDM/CritSectsRw/%s/R3EnterShared", pCritSect->pszName);
294#ifdef VBOX_WITH_STATISTICS
295 STAMR3RegisterF(pVM, &pCritSect->StatWriteLocked, STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE, NULL, "/PDM/CritSectsRw/%s/WriteLocked", pCritSect->pszName);
296#endif
297
298 PUVM pUVM = pVM->pUVM;
299 RTCritSectEnter(&pUVM->pdm.s.ListCritSect);
300 pCritSect->pNext = pUVM->pdm.s.pRwCritSects;
301 pUVM->pdm.s.pRwCritSects = pCritSect;
302 RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
303
304 return VINF_SUCCESS;
305 }
306
307 RTStrFree(pszName);
308 }
309 else
310 rc = VERR_NO_STR_MEMORY;
311 SUPSemEventMultiClose(pVM->pSession, (SUPSEMEVENT)pCritSect->Core.hEvtRead);
312 }
313 SUPSemEventClose(pVM->pSession, (SUPSEMEVENT)pCritSect->Core.hEvtWrite);
314 }
315 return rc;
316}
317
318
319/**
320 * Initializes a PDM critical section for internal use.
321 *
322 * The PDM critical sections are derived from the IPRT critical sections, but
323 * works in ring-0 and raw-mode context as well.
324 *
325 * @returns VBox status code.
326 * @param pVM Pointer to the VM.
327 * @param pDevIns Device instance.
328 * @param pCritSect Pointer to the critical section.
329 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
330 * @param pszNameFmt Format string for naming the critical section. For
331 * statistics and lock validation.
332 * @param ... Arguments for the format string.
333 * @thread EMT
334 */
335VMMR3DECL(int) PDMR3CritSectInit(PVM pVM, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL, const char *pszNameFmt, ...)
336{
337#if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 32
338 AssertCompile(sizeof(pCritSect->padding) >= sizeof(pCritSect->s));
339#endif
340 Assert(RT_ALIGN_P(pCritSect, sizeof(uintptr_t)) == pCritSect);
341 va_list va;
342 va_start(va, pszNameFmt);
343 int rc = pdmR3CritSectInitOne(pVM, &pCritSect->s, pCritSect, RT_SRC_POS_ARGS, pszNameFmt, va);
344 va_end(va);
345 return rc;
346}
347
348
349/**
350 * Initializes a PDM read/write critical section for internal use.
351 *
352 * The PDM read/write critical sections are derived from the IPRT read/write
353 * critical sections, but works in ring-0 and raw-mode context as well.
354 *
355 * @returns VBox status code.
356 * @param pVM Pointer to the VM.
357 * @param pDevIns Device instance.
358 * @param pCritSect Pointer to the read/write critical section.
359 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
360 * @param pszNameFmt Format string for naming the critical section. For
361 * statistics and lock validation.
362 * @param ... Arguments for the format string.
363 * @thread EMT
364 */
365VMMR3DECL(int) PDMR3CritSectRwInit(PVM pVM, PPDMCRITSECTRW pCritSect, RT_SRC_POS_DECL, const char *pszNameFmt, ...)
366{
367#if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 32
368 AssertCompile(sizeof(pCritSect->padding) >= sizeof(pCritSect->s));
369#endif
370 Assert(RT_ALIGN_P(pCritSect, sizeof(uintptr_t)) == pCritSect);
371 va_list va;
372 va_start(va, pszNameFmt);
373 int rc = pdmR3CritSectRwInitOne(pVM, &pCritSect->s, pCritSect, RT_SRC_POS_ARGS, pszNameFmt, va);
374 va_end(va);
375 return rc;
376}
377
378
379/**
380 * Initializes a PDM critical section for a device.
381 *
382 * @returns VBox status code.
383 * @param pVM Pointer to the VM.
384 * @param pDevIns Device instance.
385 * @param pCritSect Pointer to the critical section.
386 * @param pszNameFmt Format string for naming the critical section. For
387 * statistics and lock validation.
388 * @param va Arguments for the format string.
389 */
390int pdmR3CritSectInitDevice(PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
391 const char *pszNameFmt, va_list va)
392{
393 return pdmR3CritSectInitOne(pVM, &pCritSect->s, pDevIns, RT_SRC_POS_ARGS, pszNameFmt, va);
394}
395
396
397/**
398 * Initializes a PDM read/write critical section for a device.
399 *
400 * @returns VBox status code.
401 * @param pVM Pointer to the VM.
402 * @param pDevIns Device instance.
403 * @param pCritSect Pointer to the read/write critical section.
404 * @param pszNameFmt Format string for naming the critical section. For
405 * statistics and lock validation.
406 * @param va Arguments for the format string.
407 */
408int pdmR3CritSectRwInitDevice(PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECTRW pCritSect, RT_SRC_POS_DECL,
409 const char *pszNameFmt, va_list va)
410{
411 return pdmR3CritSectRwInitOne(pVM, &pCritSect->s, pDevIns, RT_SRC_POS_ARGS, pszNameFmt, va);
412}
413
414
415/**
416 * Initializes the automatic default PDM critical section for a device.
417 *
418 * @returns VBox status code.
419 * @param pVM Pointer to the VM.
420 * @param pDevIns Device instance.
421 * @param pCritSect Pointer to the critical section.
422 */
423int pdmR3CritSectInitDeviceAuto(PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
424 const char *pszNameFmt, ...)
425{
426 va_list va;
427 va_start(va, pszNameFmt);
428 int rc = pdmR3CritSectInitOne(pVM, &pCritSect->s, pDevIns, RT_SRC_POS_ARGS, pszNameFmt, va);
429 if (RT_SUCCESS(rc))
430 pCritSect->s.fAutomaticDefaultCritsect = true;
431 va_end(va);
432 return rc;
433}
434
435
436/**
437 * Initializes a PDM critical section for a driver.
438 *
439 * @returns VBox status code.
440 * @param pVM Pointer to the VM.
441 * @param pDrvIns Driver instance.
442 * @param pCritSect Pointer to the critical section.
443 * @param pszNameFmt Format string for naming the critical section. For
444 * statistics and lock validation.
445 * @param ... Arguments for the format string.
446 */
447int pdmR3CritSectInitDriver(PVM pVM, PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
448 const char *pszNameFmt, ...)
449{
450 va_list va;
451 va_start(va, pszNameFmt);
452 int rc = pdmR3CritSectInitOne(pVM, &pCritSect->s, pDrvIns, RT_SRC_POS_ARGS, pszNameFmt, va);
453 va_end(va);
454 return rc;
455}
456
457
458/**
459 * Initializes a PDM read/write critical section for a driver.
460 *
461 * @returns VBox status code.
462 * @param pVM Pointer to the VM.
463 * @param pDrvIns Driver instance.
464 * @param pCritSect Pointer to the read/write critical section.
465 * @param pszNameFmt Format string for naming the critical section. For
466 * statistics and lock validation.
467 * @param ... Arguments for the format string.
468 */
469int pdmR3CritSectRwInitDriver(PVM pVM, PPDMDRVINS pDrvIns, PPDMCRITSECTRW pCritSect, RT_SRC_POS_DECL,
470 const char *pszNameFmt, ...)
471{
472 va_list va;
473 va_start(va, pszNameFmt);
474 int rc = pdmR3CritSectRwInitOne(pVM, &pCritSect->s, pDrvIns, RT_SRC_POS_ARGS, pszNameFmt, va);
475 va_end(va);
476 return rc;
477}
478
479
480/**
481 * Deletes one critical section.
482 *
483 * @returns Return code from RTCritSectDelete.
484 *
485 * @param pVM Pointer to the VM.
486 * @param pCritSect The critical section.
487 * @param pPrev The previous critical section in the list.
488 * @param fFinal Set if this is the final call and statistics shouldn't be deregistered.
489 *
490 * @remarks Caller must have entered the ListCritSect.
491 */
492static int pdmR3CritSectDeleteOne(PVM pVM, PUVM pUVM, PPDMCRITSECTINT pCritSect, PPDMCRITSECTINT pPrev, bool fFinal)
493{
494 /*
495 * Assert free waiters and so on (c&p from RTCritSectDelete).
496 */
497 Assert(pCritSect->Core.u32Magic == RTCRITSECT_MAGIC);
498 Assert(pCritSect->Core.cNestings == 0);
499 Assert(pCritSect->Core.cLockers == -1);
500 Assert(pCritSect->Core.NativeThreadOwner == NIL_RTNATIVETHREAD);
501 Assert(RTCritSectIsOwner(&pUVM->pdm.s.ListCritSect));
502
503 /*
504 * Unlink it.
505 */
506 if (pPrev)
507 pPrev->pNext = pCritSect->pNext;
508 else
509 pUVM->pdm.s.pCritSects = pCritSect->pNext;
510
511 /*
512 * Delete it (parts taken from RTCritSectDelete).
513 * In case someone is waiting we'll signal the semaphore cLockers + 1 times.
514 */
515 ASMAtomicWriteU32(&pCritSect->Core.u32Magic, 0);
516 SUPSEMEVENT hEvent = (SUPSEMEVENT)pCritSect->Core.EventSem;
517 pCritSect->Core.EventSem = NIL_RTSEMEVENT;
518 while (pCritSect->Core.cLockers-- >= 0)
519 SUPSemEventSignal(pVM->pSession, hEvent);
520 ASMAtomicWriteS32(&pCritSect->Core.cLockers, -1);
521 int rc = SUPSemEventClose(pVM->pSession, hEvent);
522 AssertRC(rc);
523 RTLockValidatorRecExclDestroy(&pCritSect->Core.pValidatorRec);
524 pCritSect->pNext = NULL;
525 pCritSect->pvKey = NULL;
526 pCritSect->pVMR3 = NULL;
527 pCritSect->pVMR0 = NIL_RTR0PTR;
528 pCritSect->pVMRC = NIL_RTRCPTR;
529 RTStrFree((char *)pCritSect->pszName);
530 pCritSect->pszName = NULL;
531 if (!fFinal)
532 {
533 STAMR3Deregister(pVM, &pCritSect->StatContentionRZLock);
534 STAMR3Deregister(pVM, &pCritSect->StatContentionRZUnlock);
535 STAMR3Deregister(pVM, &pCritSect->StatContentionR3);
536#ifdef VBOX_WITH_STATISTICS
537 STAMR3Deregister(pVM, &pCritSect->StatLocked);
538#endif
539 }
540 return rc;
541}
542
543
544/**
545 * Deletes one read/write critical section.
546 *
547 * @returns VBox status code.
548 *
549 * @param pVM Pointer to the VM.
550 * @param pCritSect The read/write critical section.
551 * @param pPrev The previous critical section in the list.
552 * @param fFinal Set if this is the final call and statistics shouldn't be deregistered.
553 *
554 * @remarks Caller must have entered the ListCritSect.
555 */
556static int pdmR3CritSectRwDeleteOne(PVM pVM, PUVM pUVM, PPDMCRITSECTRWINT pCritSect, PPDMCRITSECTRWINT pPrev, bool fFinal)
557{
558 /*
559 * Assert free waiters and so on (c&p from RTCritSectRwDelete).
560 */
561 Assert(pCritSect->Core.u32Magic == RTCRITSECTRW_MAGIC);
562 //Assert(pCritSect->Core.cNestings == 0);
563 //Assert(pCritSect->Core.cLockers == -1);
564 Assert(pCritSect->Core.hNativeWriter == NIL_RTNATIVETHREAD);
565
566 /*
567 * Invalidate the structure and free the semaphores.
568 */
569 if (!ASMAtomicCmpXchgU32(&pCritSect->Core.u32Magic, RTCRITSECTRW_MAGIC_DEAD, RTCRITSECTRW_MAGIC))
570 AssertFailed();
571
572 /*
573 * Unlink it.
574 */
575 if (pPrev)
576 pPrev->pNext = pCritSect->pNext;
577 else
578 pUVM->pdm.s.pRwCritSects = pCritSect->pNext;
579
580 /*
581 * Delete it (parts taken from RTCritSectRwDelete).
582 * In case someone is waiting we'll signal the semaphore cLockers + 1 times.
583 */
584 pCritSect->Core.fFlags = 0;
585 pCritSect->Core.u64State = 0;
586
587 SUPSEMEVENT hEvtWrite = (SUPSEMEVENT)pCritSect->Core.hEvtWrite;
588 pCritSect->Core.hEvtWrite = NIL_RTSEMEVENT;
589 AssertCompile(sizeof(hEvtWrite) == sizeof(pCritSect->Core.hEvtWrite));
590
591 SUPSEMEVENTMULTI hEvtRead = (SUPSEMEVENTMULTI)pCritSect->Core.hEvtRead;
592 pCritSect->Core.hEvtRead = NIL_RTSEMEVENTMULTI;
593 AssertCompile(sizeof(hEvtRead) == sizeof(pCritSect->Core.hEvtRead));
594
595 int rc1 = SUPSemEventClose(pVM->pSession, hEvtWrite); AssertRC(rc1);
596 int rc2 = SUPSemEventMultiClose(pVM->pSession, hEvtRead); AssertRC(rc2);
597
598 RTLockValidatorRecSharedDestroy(&pCritSect->Core.pValidatorRead);
599 RTLockValidatorRecExclDestroy(&pCritSect->Core.pValidatorWrite);
600
601 pCritSect->pNext = NULL;
602 pCritSect->pvKey = NULL;
603 pCritSect->pVMR3 = NULL;
604 pCritSect->pVMR0 = NIL_RTR0PTR;
605 pCritSect->pVMRC = NIL_RTRCPTR;
606 RTStrFree((char *)pCritSect->pszName);
607 pCritSect->pszName = NULL;
608 if (!fFinal)
609 {
610 STAMR3Deregister(pVM, &pCritSect->StatContentionRZEnterExcl);
611 STAMR3Deregister(pVM, &pCritSect->StatContentionRZLeaveExcl);
612 STAMR3Deregister(pVM, &pCritSect->StatContentionRZEnterShared);
613 STAMR3Deregister(pVM, &pCritSect->StatContentionRZLeaveShared);
614 STAMR3Deregister(pVM, &pCritSect->StatRZEnterExcl);
615 STAMR3Deregister(pVM, &pCritSect->StatRZEnterShared);
616 STAMR3Deregister(pVM, &pCritSect->StatContentionR3EnterExcl);
617 STAMR3Deregister(pVM, &pCritSect->StatContentionR3EnterShared);
618 STAMR3Deregister(pVM, &pCritSect->StatR3EnterExcl);
619 STAMR3Deregister(pVM, &pCritSect->StatR3EnterShared);
620#ifdef VBOX_WITH_STATISTICS
621 STAMR3Deregister(pVM, &pCritSect->StatWriteLocked);
622#endif
623 }
624
625 return RT_SUCCESS(rc1) ? rc2 : rc1;
626}
627
628
629/**
630 * Deletes all critical sections with a give initializer key.
631 *
632 * @returns VBox status code.
633 * The entire list is processed on failure, so we'll only
634 * return the first error code. This shouldn't be a problem
635 * since errors really shouldn't happen here.
636 * @param pVM Pointer to the VM.
637 * @param pvKey The initializer key.
638 */
639static int pdmR3CritSectDeleteByKey(PVM pVM, void *pvKey)
640{
641 /*
642 * Iterate the list and match key.
643 */
644 PUVM pUVM = pVM->pUVM;
645 int rc = VINF_SUCCESS;
646 PPDMCRITSECTINT pPrev = NULL;
647 RTCritSectEnter(&pUVM->pdm.s.ListCritSect);
648 PPDMCRITSECTINT pCur = pUVM->pdm.s.pCritSects;
649 while (pCur)
650 {
651 if (pCur->pvKey == pvKey)
652 {
653 int rc2 = pdmR3CritSectDeleteOne(pVM, pUVM, pCur, pPrev, false /* not final */);
654 AssertRC(rc2);
655 if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
656 rc = rc2;
657 }
658
659 /* next */
660 pPrev = pCur;
661 pCur = pCur->pNext;
662 }
663 RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
664 return rc;
665}
666
667
668/**
669 * Deletes all read/write critical sections with a give initializer key.
670 *
671 * @returns VBox status code.
672 * The entire list is processed on failure, so we'll only
673 * return the first error code. This shouldn't be a problem
674 * since errors really shouldn't happen here.
675 * @param pVM Pointer to the VM.
676 * @param pvKey The initializer key.
677 */
678static int pdmR3CritSectRwDeleteByKey(PVM pVM, void *pvKey)
679{
680 /*
681 * Iterate the list and match key.
682 */
683 PUVM pUVM = pVM->pUVM;
684 int rc = VINF_SUCCESS;
685 PPDMCRITSECTRWINT pPrev = NULL;
686 RTCritSectEnter(&pUVM->pdm.s.ListCritSect);
687 PPDMCRITSECTRWINT pCur = pUVM->pdm.s.pRwCritSects;
688 while (pCur)
689 {
690 if (pCur->pvKey == pvKey)
691 {
692 int rc2 = pdmR3CritSectRwDeleteOne(pVM, pUVM, pCur, pPrev, false /* not final */);
693 AssertRC(rc2);
694 if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
695 rc = rc2;
696 }
697
698 /* next */
699 pPrev = pCur;
700 pCur = pCur->pNext;
701 }
702 RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
703 return rc;
704}
705
706
707/**
708 * Deletes all undeleted critical sections (both types) initialized by a given
709 * device.
710 *
711 * @returns VBox status code.
712 * @param pVM Pointer to the VM.
713 * @param pDevIns The device handle.
714 */
715int pdmR3CritSectBothDeleteDevice(PVM pVM, PPDMDEVINS pDevIns)
716{
717 int rc1 = pdmR3CritSectDeleteByKey(pVM, pDevIns);
718 int rc2 = pdmR3CritSectRwDeleteByKey(pVM, pDevIns);
719 return RT_SUCCESS(rc1) ? rc2 : rc1;
720}
721
722
723/**
724 * Deletes all undeleted critical sections (both types) initialized by a given
725 * driver.
726 *
727 * @returns VBox status code.
728 * @param pVM Pointer to the VM.
729 * @param pDrvIns The driver handle.
730 */
731int pdmR3CritSectBothDeleteDriver(PVM pVM, PPDMDRVINS pDrvIns)
732{
733 int rc1 = pdmR3CritSectDeleteByKey(pVM, pDrvIns);
734 int rc2 = pdmR3CritSectRwDeleteByKey(pVM, pDrvIns);
735 return RT_SUCCESS(rc1) ? rc2 : rc1;
736}
737
738
739/**
740 * Deletes the critical section.
741 *
742 * @returns VBox status code.
743 * @param pCritSect The PDM critical section to destroy.
744 */
745VMMR3DECL(int) PDMR3CritSectDelete(PPDMCRITSECT pCritSect)
746{
747 if (!RTCritSectIsInitialized(&pCritSect->s.Core))
748 return VINF_SUCCESS;
749
750 /*
751 * Find and unlink it.
752 */
753 PVM pVM = pCritSect->s.pVMR3;
754 PUVM pUVM = pVM->pUVM;
755 AssertReleaseReturn(pVM, VERR_PDM_CRITSECT_IPE);
756 PPDMCRITSECTINT pPrev = NULL;
757 RTCritSectEnter(&pUVM->pdm.s.ListCritSect);
758 PPDMCRITSECTINT pCur = pUVM->pdm.s.pCritSects;
759 while (pCur)
760 {
761 if (pCur == &pCritSect->s)
762 {
763 int rc = pdmR3CritSectDeleteOne(pVM, pUVM, pCur, pPrev, false /* not final */);
764 RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
765 return rc;
766 }
767
768 /* next */
769 pPrev = pCur;
770 pCur = pCur->pNext;
771 }
772 RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
773 AssertReleaseMsgFailed(("pCritSect=%p wasn't found!\n", pCritSect));
774 return VERR_PDM_CRITSECT_NOT_FOUND;
775}
776
777
778/**
779 * Deletes the read/write critical section.
780 *
781 * @returns VBox status code.
782 * @param pCritSect The PDM read/write critical section to destroy.
783 */
784VMMR3DECL(int) PDMR3CritSectRwDelete(PPDMCRITSECTRW pCritSect)
785{
786 if (!PDMCritSectRwIsInitialized(pCritSect))
787 return VINF_SUCCESS;
788
789 /*
790 * Find and unlink it.
791 */
792 PVM pVM = pCritSect->s.pVMR3;
793 PUVM pUVM = pVM->pUVM;
794 AssertReleaseReturn(pVM, VERR_PDM_CRITSECT_IPE);
795 PPDMCRITSECTRWINT pPrev = NULL;
796 RTCritSectEnter(&pUVM->pdm.s.ListCritSect);
797 PPDMCRITSECTRWINT pCur = pUVM->pdm.s.pRwCritSects;
798 while (pCur)
799 {
800 if (pCur == &pCritSect->s)
801 {
802 int rc = pdmR3CritSectRwDeleteOne(pVM, pUVM, pCur, pPrev, false /* not final */);
803 RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
804 return rc;
805 }
806
807 /* next */
808 pPrev = pCur;
809 pCur = pCur->pNext;
810 }
811 RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
812 AssertReleaseMsgFailed(("pCritSect=%p wasn't found!\n", pCritSect));
813 return VERR_PDM_CRITSECT_NOT_FOUND;
814}
815
816
817/**
818 * Gets the name of the critical section.
819 *
820 *
821 * @returns Pointer to the critical section name (read only) on success,
822 * NULL on failure (invalid critical section).
823 * @param pCritSect The critical section.
824 */
825VMMR3DECL(const char *) PDMR3CritSectName(PCPDMCRITSECT pCritSect)
826{
827 AssertPtrReturn(pCritSect, NULL);
828 AssertReturn(pCritSect->s.Core.u32Magic == RTCRITSECT_MAGIC, NULL);
829 return pCritSect->s.pszName;
830}
831
832
833/**
834 * Gets the name of the read/write critical section.
835 *
836 *
837 * @returns Pointer to the critical section name (read only) on success,
838 * NULL on failure (invalid critical section).
839 * @param pCritSect The read/write critical section.
840 */
841VMMR3DECL(const char *) PDMR3CritSectRwName(PCPDMCRITSECTRW pCritSect)
842{
843 AssertPtrReturn(pCritSect, NULL);
844 AssertReturn(pCritSect->s.Core.u32Magic == RTCRITSECTRW_MAGIC, NULL);
845 return pCritSect->s.pszName;
846}
847
848
849/**
850 * Yield the critical section if someone is waiting on it.
851 *
852 * When yielding, we'll leave the critical section and try to make sure the
853 * other waiting threads get a chance of entering before we reclaim it.
854 *
855 * @retval true if yielded.
856 * @retval false if not yielded.
857 * @param pCritSect The critical section.
858 */
859VMMR3DECL(bool) PDMR3CritSectYield(PPDMCRITSECT pCritSect)
860{
861 AssertPtrReturn(pCritSect, false);
862 AssertReturn(pCritSect->s.Core.u32Magic == RTCRITSECT_MAGIC, false);
863 Assert(pCritSect->s.Core.NativeThreadOwner == RTThreadNativeSelf());
864 Assert(!(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NOP));
865
866 /* No recursion allowed here. */
867 int32_t const cNestings = pCritSect->s.Core.cNestings;
868 AssertReturn(cNestings == 1, false);
869
870 int32_t const cLockers = ASMAtomicReadS32(&pCritSect->s.Core.cLockers);
871 if (cLockers < cNestings)
872 return false;
873
874#ifdef PDMCRITSECT_STRICT
875 RTLOCKVALSRCPOS const SrcPos = pCritSect->s.Core.pValidatorRec->SrcPos;
876#endif
877 PDMCritSectLeave(pCritSect);
878
879 /*
880 * If we're lucky, then one of the waiters has entered the lock already.
881 * We spin a little bit in hope for this to happen so we can avoid the
882 * yield detour.
883 */
884 if (ASMAtomicUoReadS32(&pCritSect->s.Core.cNestings) == 0)
885 {
886 int cLoops = 20;
887 while ( cLoops > 0
888 && ASMAtomicUoReadS32(&pCritSect->s.Core.cNestings) == 0
889 && ASMAtomicUoReadS32(&pCritSect->s.Core.cLockers) >= 0)
890 {
891 ASMNopPause();
892 cLoops--;
893 }
894 if (cLoops == 0)
895 RTThreadYield();
896 }
897
898#ifdef PDMCRITSECT_STRICT
899 int rc = PDMCritSectEnterDebug(pCritSect, VERR_IGNORED,
900 SrcPos.uId, SrcPos.pszFile, SrcPos.uLine, SrcPos.pszFunction);
901#else
902 int rc = PDMCritSectEnter(pCritSect, VERR_IGNORED);
903#endif
904 AssertLogRelRC(rc);
905 return true;
906}
907
908
909/**
910 * Schedule a event semaphore for signalling upon critsect exit.
911 *
912 * @returns VINF_SUCCESS on success.
913 * @returns VERR_TOO_MANY_SEMAPHORES if an event was already scheduled.
914 * @returns VERR_NOT_OWNER if we're not the critsect owner.
915 * @returns VERR_SEM_DESTROYED if RTCritSectDelete was called while waiting.
916 *
917 * @param pCritSect The critical section.
918 * @param EventToSignal The semaphore that should be signalled.
919 */
920VMMR3DECL(int) PDMR3CritSectScheduleExitEvent(PPDMCRITSECT pCritSect, RTSEMEVENT EventToSignal)
921{
922 AssertPtr(pCritSect);
923 Assert(!(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NOP));
924 Assert(EventToSignal != NIL_RTSEMEVENT);
925 if (RT_UNLIKELY(!RTCritSectIsOwner(&pCritSect->s.Core)))
926 return VERR_NOT_OWNER;
927 if (RT_LIKELY( pCritSect->s.EventToSignal == NIL_RTSEMEVENT
928 || pCritSect->s.EventToSignal == EventToSignal))
929 {
930 pCritSect->s.EventToSignal = EventToSignal;
931 return VINF_SUCCESS;
932 }
933 return VERR_TOO_MANY_SEMAPHORES;
934}
935
936
937/**
938 * PDMR3CritSectBothCountOwned worker.
939 *
940 * @param pszName The critical section name.
941 * @param ppszNames Pointer to the pszNames variable.
942 * @param pcchLeft Pointer to the cchLeft variable.
943 * @param fFirst Whether this is the first name or not.
944 */
945static void pdmR3CritSectAppendNameToList(char const *pszName, char **ppszNames, size_t *pcchLeft, bool fFirst)
946{
947 size_t cchLeft = *pcchLeft;
948 if (cchLeft)
949 {
950 char *pszNames = *ppszNames;
951
952 /* try add comma. */
953 if (fFirst)
954 {
955 *pszNames++ = ',';
956 if (--cchLeft)
957 {
958 *pszNames++ = ' ';
959 cchLeft--;
960 }
961 }
962
963 /* try copy the name. */
964 if (cchLeft)
965 {
966 size_t const cchName = strlen(pszName);
967 if (cchName < cchLeft)
968 {
969 memcpy(pszNames, pszName, cchName);
970 pszNames += cchName;
971 cchLeft -= cchName;
972 }
973 else
974 {
975 if (cchLeft > 2)
976 {
977 memcpy(pszNames, pszName, cchLeft - 2);
978 pszNames += cchLeft - 2;
979 cchLeft = 2;
980 }
981 while (cchLeft-- > 0)
982 *pszNames++ = '+';
983 }
984 }
985 *pszNames = '\0';
986
987 *pcchLeft = cchLeft;
988 *ppszNames = pszNames;
989 }
990}
991
992
993/**
994 * Counts the critical sections (both type) owned by the calling thread,
995 * optionally returning a comma separated list naming them.
996 *
997 * Read ownerships are not included in non-strict builds.
998 *
999 * This is for diagnostic purposes only.
1000 *
1001 * @returns Lock count.
1002 *
1003 * @param pVM Pointer to the VM.
1004 * @param pszNames Where to return the critical section names.
1005 * @param cbNames The size of the buffer.
1006 */
1007VMMR3DECL(uint32_t) PDMR3CritSectCountOwned(PVM pVM, char *pszNames, size_t cbNames)
1008{
1009 /*
1010 * Init the name buffer.
1011 */
1012 size_t cchLeft = cbNames;
1013 if (cchLeft)
1014 {
1015 cchLeft--;
1016 pszNames[0] = pszNames[cchLeft] = '\0';
1017 }
1018
1019 /*
1020 * Iterate the critical sections.
1021 */
1022 uint32_t cCritSects = 0;
1023 RTNATIVETHREAD const hNativeThread = RTThreadNativeSelf();
1024 /* This is unsafe, but wtf. */
1025 for (PPDMCRITSECTINT pCur = pVM->pUVM->pdm.s.pCritSects;
1026 pCur;
1027 pCur = pCur->pNext)
1028 {
1029 /* Same as RTCritSectIsOwner(). */
1030 if (pCur->Core.NativeThreadOwner == hNativeThread)
1031 {
1032 cCritSects++;
1033 pdmR3CritSectAppendNameToList(pCur->pszName, &pszNames, &cchLeft, cCritSects == 1);
1034 }
1035 }
1036
1037 /* This is unsafe, but wtf. */
1038 for (PPDMCRITSECTRWINT pCur = pVM->pUVM->pdm.s.pRwCritSects;
1039 pCur;
1040 pCur = pCur->pNext)
1041 {
1042 if ( pCur->Core.hNativeWriter == hNativeThread
1043 || PDMCritSectRwIsReadOwner((PPDMCRITSECTRW)pCur, false /*fWannaHear*/) )
1044 {
1045 cCritSects++;
1046 pdmR3CritSectAppendNameToList(pCur->pszName, &pszNames, &cchLeft, cCritSects == 1);
1047 }
1048 }
1049
1050 return cCritSects;
1051}
1052
1053
1054/**
1055 * Leave all critical sections the calling thread owns.
1056 *
1057 * This is only used when entering guru meditation in order to prevent other
1058 * EMTs and I/O threads from deadlocking.
1059 *
1060 * @param pVM Pointer to the VM.
1061 */
1062VMMR3_INT_DECL(void) PDMR3CritSectLeaveAll(PVM pVM)
1063{
1064 RTNATIVETHREAD const hNativeSelf = RTThreadNativeSelf();
1065 PUVM pUVM = pVM->pUVM;
1066
1067 RTCritSectEnter(&pUVM->pdm.s.ListCritSect);
1068 for (PPDMCRITSECTINT pCur = pUVM->pdm.s.pCritSects;
1069 pCur;
1070 pCur = pCur->pNext)
1071 {
1072 while ( pCur->Core.NativeThreadOwner == hNativeSelf
1073 && pCur->Core.cNestings > 0)
1074 PDMCritSectLeave((PPDMCRITSECT)pCur);
1075 }
1076 RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
1077}
1078
1079
1080/**
1081 * Gets the address of the NOP critical section.
1082 *
1083 * The NOP critical section will not perform any thread serialization but let
1084 * all enter immediately and concurrently.
1085 *
1086 * @returns The address of the NOP critical section.
1087 * @param pVM Pointer to the VM.
1088 */
1089VMMR3DECL(PPDMCRITSECT) PDMR3CritSectGetNop(PVM pVM)
1090{
1091 VM_ASSERT_VALID_EXT_RETURN(pVM, NULL);
1092 return &pVM->pdm.s.NopCritSect;
1093}
1094
1095
1096/**
1097 * Gets the ring-0 address of the NOP critical section.
1098 *
1099 * @returns The ring-0 address of the NOP critical section.
1100 * @param pVM Pointer to the VM.
1101 */
1102VMMR3DECL(R0PTRTYPE(PPDMCRITSECT)) PDMR3CritSectGetNopR0(PVM pVM)
1103{
1104 VM_ASSERT_VALID_EXT_RETURN(pVM, NIL_RTR0PTR);
1105 return MMHyperR3ToR0(pVM, &pVM->pdm.s.NopCritSect);
1106}
1107
1108
1109/**
1110 * Gets the raw-mode context address of the NOP critical section.
1111 *
1112 * @returns The raw-mode context address of the NOP critical section.
1113 * @param pVM Pointer to the VM.
1114 */
1115VMMR3DECL(RCPTRTYPE(PPDMCRITSECT)) PDMR3CritSectGetNopRC(PVM pVM)
1116{
1117 VM_ASSERT_VALID_EXT_RETURN(pVM, NIL_RTRCPTR);
1118 return MMHyperR3ToRC(pVM, &pVM->pdm.s.NopCritSect);
1119}
1120
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette