[WIN32K] Add some validity checks in PDEVOBJ_vReference() and use it instead of explicitly manipulating ppdev->cPdevRefs.

This commit is contained in:
Hermès Bélusca-Maïto 2019-11-24 21:22:21 +01:00
parent acf689a973
commit 148e137b42
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 21 additions and 10 deletions

View file

@ -630,7 +630,7 @@ EngpGetPDEV(
if (ppdev)
{
/* Yes, reference the PDEV */
InterlockedIncrement(&ppdev->cPdevRefs);
PDEVOBJ_vReference(ppdev);
}
else
{

View file

@ -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 */

View file

@ -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);

View file

@ -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 */