https://git.reactos.org/?p=reactos.git;a=commitdiff;h=148e137b421587abfa0ca…
commit 148e137b421587abfa0ca987cb12a51d267a62d7
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Nov 24 21:22:21 2019 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Mon Nov 25 00:41:51 2019 +0100
[WIN32K] Add some validity checks in PDEVOBJ_vReference() and use it instead of
explicitly manipulating ppdev->cPdevRefs.
---
win32ss/gdi/eng/pdevobj.c | 2 +-
win32ss/gdi/eng/pdevobj.h | 25 ++++++++++++++++++-------
win32ss/gdi/ntgdi/dclife.c | 2 +-
win32ss/gdi/ntgdi/dcstate.c | 2 +-
4 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/win32ss/gdi/eng/pdevobj.c b/win32ss/gdi/eng/pdevobj.c
index 450d37f6785..4147f0fa749 100644
--- a/win32ss/gdi/eng/pdevobj.c
+++ b/win32ss/gdi/eng/pdevobj.c
@@ -630,7 +630,7 @@ EngpGetPDEV(
if (ppdev)
{
/* Yes, reference the PDEV */
- InterlockedIncrement(&ppdev->cPdevRefs);
+ PDEVOBJ_vReference(ppdev);
}
else
{
diff --git a/win32ss/gdi/eng/pdevobj.h b/win32ss/gdi/eng/pdevobj.h
index 9b986acde13..a232a2e057c 100644
--- a/win32ss/gdi/eng/pdevobj.h
+++ b/win32ss/gdi/eng/pdevobj.h
@@ -162,6 +162,24 @@ NTAPI
EngpGetPDEV(
_In_opt_ PUNICODE_STRING pustrDevice);
+FORCEINLINE
+VOID
+PDEVOBJ_vReference(
+ _In_ PPDEVOBJ ppdev)
+{
+ ASSERT(ppdev);
+
+ /* Fail if the PDEV is being destroyed */
+ if (ppdev->cPdevRefs == 0)
+ {
+ ASSERT(FALSE);
+ return;
+ }
+ ASSERT(ppdev->cPdevRefs > 0);
+
+ InterlockedIncrement(&ppdev->cPdevRefs);
+}
+
VOID
NTAPI
PDEVOBJ_vRelease(
@@ -201,11 +219,4 @@ PDEVOBJ_pdmMatchDevMode(
PPDEVOBJ ppdev,
PDEVMODEW pdm);
-FORCEINLINE
-VOID
-PDEVOBJ_vReference(PPDEVOBJ ppdev)
-{
- InterlockedIncrement(&ppdev->cPdevRefs);
-}
-
#endif /* !__WIN32K_PDEVOBJ_H */
diff --git a/win32ss/gdi/ntgdi/dclife.c b/win32ss/gdi/ntgdi/dclife.c
index 99d872a9c2f..52236c037c3 100644
--- a/win32ss/gdi/ntgdi/dclife.c
+++ b/win32ss/gdi/ntgdi/dclife.c
@@ -836,7 +836,7 @@ GreCreateCompatibleDC(HDC hdc, BOOL bAltDc)
/* Get the pdev from the DC */
ppdev = pdc->ppdev;
- InterlockedIncrement(&ppdev->cPdevRefs);
+ PDEVOBJ_vReference(ppdev);
/* Unlock the source DC */
DC_UnlockDc(pdc);
diff --git a/win32ss/gdi/ntgdi/dcstate.c b/win32ss/gdi/ntgdi/dcstate.c
index ccf7c134e7f..314eaa6c380 100644
--- a/win32ss/gdi/ntgdi/dcstate.c
+++ b/win32ss/gdi/ntgdi/dcstate.c
@@ -282,7 +282,7 @@ NtGdiSaveDC(
}
hdcSave = pdcSave->BaseObject.hHmgr;
- InterlockedIncrement(&pdc->ppdev->cPdevRefs);
+ PDEVOBJ_vReference(pdc->ppdev);
DC_vInitDc(pdcSave, DCTYPE_MEMORY, pdc->ppdev);
/* Handle references here correctly */