Author: tkreuzer
Date: Tue Mar 10 00:13:04 2015
New Revision: 66647
URL:
http://svn.reactos.org/svn/reactos?rev=66647&view=rev
Log:
[WIN32K]
- Annotate eng/device.c and semaphor.c.
- Get rid of IntGdiAcquire/ReleaseSemaphore
- Move some prototypes where they belong
Modified:
trunk/reactos/include/psdk/winddi.h
trunk/reactos/win32ss/gdi/eng/device.c
trunk/reactos/win32ss/gdi/eng/device.h
trunk/reactos/win32ss/gdi/eng/eng.h
trunk/reactos/win32ss/gdi/eng/pdevobj.h
trunk/reactos/win32ss/gdi/eng/semaphor.c
trunk/reactos/win32ss/reactx/ntddraw/dxeng.c
Modified: trunk/reactos/include/psdk/winddi.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/winddi.h?rev=…
==============================================================================
--- trunk/reactos/include/psdk/winddi.h [iso-8859-1] (original)
+++ trunk/reactos/include/psdk/winddi.h [iso-8859-1] Tue Mar 10 00:13:04 2015
@@ -1581,10 +1581,13 @@
APIENTRY
EngCreatePath(VOID);
+__drv_allocatesMem(Mem)
+_Post_writable_byte_size_(sizeof(ERESOURCE))
ENGAPI
HSEMAPHORE
APIENTRY
-EngCreateSemaphore(VOID);
+EngCreateSemaphore(
+ VOID);
/* EngCreateWnd.fl constants */
#define WO_RGN_CLIENT_DELTA 0x00000001
@@ -1667,13 +1670,14 @@
VOID
APIENTRY
EngDeleteSafeSemaphore(
- _Inout_ ENGSAFESEMAPHORE *pssem);
-
+ _Inout_ _Post_invalid_ ENGSAFESEMAPHORE *pssem);
+
+_Requires_lock_not_held_(*hsem)
ENGAPI
VOID
APIENTRY
EngDeleteSemaphore(
- _In_ _Post_ptr_invalid_ HSEMAPHORE hsem);
+ _Inout_ __drv_freesMem(Mem) HSEMAPHORE hsem);
ENGAPI
BOOL
@@ -2302,11 +2306,14 @@
EngReadStateEvent(
_In_ PEVENT pEvent);
+_Requires_lock_held_(*hsem)
+_Releases_lock_(*hsem)
+_Releases_lock_(_Global_critical_region_)
ENGAPI
VOID
APIENTRY
EngReleaseSemaphore(
- _In_ HSEMAPHORE hsem);
+ _Inout_ HSEMAPHORE hsem);
#if defined(_M_AMD64) && (NTDDI_VERSION >= NTDDI_VISTA)
@@ -3303,11 +3310,14 @@
_In_ SIZE_T Length,
_In_reads_bytes_opt_(Length) PVOID Data);
-ENGAPI
-VOID
-APIENTRY
-EngAcquireSemaphoreShared(
- _In_ HSEMAPHORE hsem);
+_Requires_lock_not_held_(*hsem)
+_Acquires_exclusive_lock_(*hsem)
+_Acquires_lock_(_Global_critical_region_)
+ENGAPI
+VOID
+APIENTRY
+EngAcquireSemaphore(
+ _Inout_ HSEMAPHORE hsem);
ENGAPI
BOOL
@@ -3315,11 +3325,14 @@
EngAcquireSemaphoreNoWait(
_In_ HSEMAPHORE hsem);
-ENGAPI
-BOOL
-APIENTRY
-EngAcquireSemaphoreSharedNoWait(
- _In_ HSEMAPHORE hsem);
+_Acquires_lock_(_Global_critical_region_)
+_Requires_lock_not_held_(*hsem)
+_Acquires_shared_lock_(*hsem)
+ENGAPI
+VOID
+NTAPI
+EngAcquireSemaphoreShared(
+ _Inout_ HSEMAPHORE hsem);
ENGAPI
BOOL
Modified: trunk/reactos/win32ss/gdi/eng/device.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/eng/device.c?r…
==============================================================================
--- trunk/reactos/win32ss/gdi/eng/device.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/eng/device.c [iso-8859-1] Tue Mar 10 00:13:04 2015
@@ -21,7 +21,7 @@
INIT_FUNCTION
NTSTATUS
NTAPI
-InitDeviceImpl()
+InitDeviceImpl(VOID)
{
ghsemGraphicsDeviceList = EngCreateSemaphore();
if (!ghsemGraphicsDeviceList)
@@ -34,10 +34,10 @@
PGRAPHICS_DEVICE
NTAPI
EngpRegisterGraphicsDevice(
- PUNICODE_STRING pustrDeviceName,
- PUNICODE_STRING pustrDiplayDrivers,
- PUNICODE_STRING pustrDescription,
- PDEVMODEW pdmDefault)
+ _In_ PUNICODE_STRING pustrDeviceName,
+ _In_ PUNICODE_STRING pustrDiplayDrivers,
+ _In_ PUNICODE_STRING pustrDescription,
+ _In_ PDEVMODEW pdmDefault)
{
PGRAPHICS_DEVICE pGraphicsDevice;
PDEVICE_OBJECT pDeviceObject;
@@ -259,9 +259,9 @@
PGRAPHICS_DEVICE
NTAPI
EngpFindGraphicsDevice(
- PUNICODE_STRING pustrDevice,
- ULONG iDevNum,
- DWORD dwFlags)
+ _In_opt_ PUNICODE_STRING pustrDevice,
+ _In_ ULONG iDevNum,
+ _In_ DWORD dwFlags)
{
UNICODE_STRING ustrCurrent;
PGRAPHICS_DEVICE pGraphicsDevice;
@@ -305,12 +305,12 @@
static
NTSTATUS
EngpFileIoRequest(
- PFILE_OBJECT pFileObject,
- ULONG ulMajorFunction,
- LPVOID lpBuffer,
- SIZE_T nBufferSize,
- ULONGLONG ullStartOffset,
- OUT PULONG_PTR lpInformation)
+ _In_ PFILE_OBJECT pFileObject,
+ _In_ ULONG ulMajorFunction,
+ _In_reads_(nBufferSize) PVOID lpBuffer,
+ _In_ SIZE_T nBufferSize,
+ _In_ ULONGLONG ullStartOffset,
+ _Out_ PULONG_PTR lpInformation)
{
PDEVICE_OBJECT pDeviceObject;
KEVENT Event;
@@ -363,29 +363,36 @@
VOID
APIENTRY
EngFileWrite(
- IN PFILE_OBJECT pFileObject,
- IN PVOID lpBuffer,
- IN SIZE_T nLength,
- IN PSIZE_T lpBytesWritten)
-{
- EngpFileIoRequest(pFileObject,
- IRP_MJ_WRITE,
- lpBuffer,
- nLength,
- 0,
- lpBytesWritten);
-}
-
+ _In_ PFILE_OBJECT pFileObject,
+ _In_reads_(nLength) PVOID lpBuffer,
+ _In_ SIZE_T nLength,
+ _Out_ PSIZE_T lpBytesWritten)
+{
+ NTSTATUS status;
+
+ status = EngpFileIoRequest(pFileObject,
+ IRP_MJ_WRITE,
+ lpBuffer,
+ nLength,
+ 0,
+ lpBytesWritten);
+ if (!NT_SUCCESS(status))
+ {
+ *lpBytesWritten = 0;
+ }
+}
+
+_Success_(return>=0)
NTSTATUS
APIENTRY
EngFileIoControl(
- IN PFILE_OBJECT pFileObject,
- IN DWORD dwIoControlCode,
- IN PVOID lpInBuffer,
- IN SIZE_T nInBufferSize,
- OUT PVOID lpOutBuffer,
- IN SIZE_T nOutBufferSize,
- OUT PULONG_PTR lpInformation)
+ _In_ PFILE_OBJECT pFileObject,
+ _In_ DWORD dwIoControlCode,
+ _In_reads_(nInBufferSize) PVOID lpInBuffer,
+ _In_ SIZE_T nInBufferSize,
+ _Out_writes_(nOutBufferSize) PVOID lpOutBuffer,
+ _In_ SIZE_T nOutBufferSize,
+ _Out_ PULONG_PTR lpInformation)
{
PDEVICE_OBJECT pDeviceObject;
KEVENT Event;
Modified: trunk/reactos/win32ss/gdi/eng/device.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/eng/device.h?r…
==============================================================================
--- trunk/reactos/win32ss/gdi/eng/device.h [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/eng/device.h [iso-8859-1] Tue Mar 10 00:13:04 2015
@@ -1,48 +1,36 @@
+
+#pragma once
#define TAG_GDEV 'gdev'
+
+extern PGRAPHICS_DEVICE gpPrimaryGraphicsDevice;
+extern PGRAPHICS_DEVICE gpVgaGraphicsDevice;
VOID
APIENTRY
EngFileWrite(
- IN PFILE_OBJECT pFileObject,
- IN PVOID lpBuffer,
- IN SIZE_T nLength,
- IN PSIZE_T lpBytesWritten);
+ _In_ PFILE_OBJECT pFileObject,
+ _In_reads_(nLength) PVOID lpBuffer,
+ _In_ SIZE_T nLength,
+ _Out_ PSIZE_T lpBytesWritten);
PGRAPHICS_DEVICE
NTAPI
EngpFindGraphicsDevice(
- PUNICODE_STRING pustrDevice,
- DWORD iDevNum,
- DWORD dwFlags);
+ _In_opt_ PUNICODE_STRING pustrDevice,
+ _In_ ULONG iDevNum,
+ _In_ DWORD dwFlags);
PGRAPHICS_DEVICE
NTAPI
EngpRegisterGraphicsDevice(
- PUNICODE_STRING pustrDeviceName,
- PUNICODE_STRING pustrDiplayDrivers,
- PUNICODE_STRING pustrDescription,
- PDEVMODEW pdmDefault);
+ _In_ PUNICODE_STRING pustrDeviceName,
+ _In_ PUNICODE_STRING pustrDiplayDrivers,
+ _In_ PUNICODE_STRING pustrDescription,
+ _In_ PDEVMODEW pdmDefault);
INIT_FUNCTION
NTSTATUS
NTAPI
InitDeviceImpl(VOID);
-//#define KeRosDumpStackFrames(Frames, Count) KdSystemDebugControl(TAG('R',
'o', 's', 'D'), (PVOID)Frames, Count, NULL, 0, NULL, KernelMode)
-NTSYSAPI ULONG APIENTRY RtlWalkFrameChain(OUT PVOID *Callers, IN ULONG Count, IN ULONG
Flags);
-
-BOOL
-NTAPI
-PDEVOBJ_bSwitchMode(
- PPDEVOBJ ppdev,
- PDEVMODEW pdm);
-
-PDEVMODEW
-NTAPI
-PDEVOBJ_pdmMatchDevMode(
- PPDEVOBJ ppdev,
- PDEVMODEW pdm);
-
-extern PGRAPHICS_DEVICE gpPrimaryGraphicsDevice;
-extern PGRAPHICS_DEVICE gpVgaGraphicsDevice;
Modified: trunk/reactos/win32ss/gdi/eng/eng.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/eng/eng.h?rev=…
==============================================================================
--- trunk/reactos/win32ss/gdi/eng/eng.h [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/eng/eng.h [iso-8859-1] Tue Mar 10 00:13:04 2015
@@ -6,10 +6,15 @@
(((ULONG)gajRop2ToRop3[((mix) - 1) & 0xF]) | \
((ULONG)gajRop2ToRop3[(((mix) >> 8) - 1) & 0xF] << 8))
+/* Copied from winddi.h, where it is only for vista+ */
+_Acquires_lock_(_Global_critical_region_)
+_Requires_lock_not_held_(*hsem)
+_Acquires_shared_lock_(*hsem)
+ENGAPI
VOID
NTAPI
EngAcquireSemaphoreShared(
- IN HSEMAPHORE hsem);
+ _Inout_ HSEMAPHORE hsem);
BOOL
APIENTRY
@@ -24,17 +29,27 @@
_In_ BRUSHOBJ *pbo,
_In_ POINTL *pptlBrushOrg);
-VOID FASTCALL
+VOID
+FASTCALL
IntEngWindowChanged(
_In_ PWND Window,
_In_ FLONG flChanged);
-VOID FASTCALL IntGdiAcquireSemaphore ( HSEMAPHORE hsem );
-VOID FASTCALL IntGdiReleaseSemaphore ( HSEMAPHORE hsem );
-ULONGLONG APIENTRY EngGetTickCount(VOID);
-
-VOID DecompressBitmap(SIZEL Size, BYTE *CompressedBits, BYTE *UncompressedBits, LONG
Delta, ULONG iFormat);
+ULONGLONG
+APIENTRY
+EngGetTickCount(
+ VOID);
HANDLE
APIENTRY
-EngSecureMemForRead(PVOID Address, ULONG Length);
+EngSecureMemForRead(
+ PVOID Address,
+ ULONG Length);
+
+VOID
+DecompressBitmap(
+ SIZEL Size,
+ BYTE *CompressedBits,
+ BYTE *UncompressedBits,
+ LONG Delta,
+ ULONG iFormat);
Modified: trunk/reactos/win32ss/gdi/eng/pdevobj.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/eng/pdevobj.h?…
==============================================================================
--- trunk/reactos/win32ss/gdi/eng/pdevobj.h [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/eng/pdevobj.h [iso-8859-1] Tue Mar 10 00:13:04 2015
@@ -189,4 +189,16 @@
_In_ PPDEVOBJ ppdev,
_Out_ PSIZEL psizl);
+BOOL
+NTAPI
+PDEVOBJ_bSwitchMode(
+ PPDEVOBJ ppdev,
+ PDEVMODEW pdm);
+
+PDEVMODEW
+NTAPI
+PDEVOBJ_pdmMatchDevMode(
+ PPDEVOBJ ppdev,
+ PDEVMODEW pdm);
+
#endif /* !__WIN32K_PDEVOBJ_H */
Modified: trunk/reactos/win32ss/gdi/eng/semaphor.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/eng/semaphor.c…
==============================================================================
--- trunk/reactos/win32ss/gdi/eng/semaphor.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/eng/semaphor.c [iso-8859-1] Tue Mar 10 00:13:04 2015
@@ -6,12 +6,17 @@
/*
* @implemented
*/
+__drv_allocatesMem(Mem)
+_Post_writable_byte_size_(sizeof(ERESOURCE))
HSEMAPHORE
APIENTRY
-EngCreateSemaphore(VOID)
+EngCreateSemaphore(
+ VOID)
{
//
www.osr.com/ddk/graphics/gdifncs_95lz.htm
- PERESOURCE psem = ExAllocatePoolWithTag(NonPagedPool, sizeof(ERESOURCE),
GDITAG_SEMAPHORE);
+ PERESOURCE psem = ExAllocatePoolWithTag(NonPagedPool,
+ sizeof(ERESOURCE),
+ GDITAG_SEMAPHORE);
if (!psem)
return NULL;
@@ -24,57 +29,51 @@
return (HSEMAPHORE)psem;
}
+/*
+ * @implemented
+ */
+_Requires_lock_not_held_(*hsem)
+_Acquires_exclusive_lock_(*hsem)
+_Acquires_lock_(_Global_critical_region_)
VOID
-FASTCALL
-IntGdiAcquireSemaphore(HSEMAPHORE hsem)
+APIENTRY
+EngAcquireSemaphore(
+ _Inout_ HSEMAPHORE hsem)
{
- KeEnterCriticalRegion();
- ExAcquireResourceExclusiveLite ((PERESOURCE)hsem, TRUE);
+ //
www.osr.com/ddk/graphics/gdifncs_14br.htm
+ PTHREADINFO W32Thread;
+ ASSERT(hsem);
+ ExEnterCriticalRegionAndAcquireResourceExclusive((PERESOURCE)hsem);
+ W32Thread = PsGetThreadWin32Thread(PsGetCurrentThread());
+ if (W32Thread) W32Thread->dwEngAcquireCount++;
}
/*
* @implemented
*/
+_Requires_lock_held_(*hsem)
+_Releases_lock_(*hsem)
+_Releases_lock_(_Global_critical_region_)
VOID
APIENTRY
-EngAcquireSemaphore(IN HSEMAPHORE hsem)
-{
- //
www.osr.com/ddk/graphics/gdifncs_14br.htm
- PTHREADINFO W32Thread;
- ASSERT(hsem);
- IntGdiAcquireSemaphore(hsem);
- W32Thread = PsGetThreadWin32Thread(PsGetCurrentThread());
- if (W32Thread) W32Thread->dwEngAcquireCount++;
-}
-
-
-VOID
-FASTCALL
-IntGdiReleaseSemaphore ( HSEMAPHORE hsem )
-{
- ExReleaseResourceLite((PERESOURCE)hsem);
- KeLeaveCriticalRegion();
-}
-
-/*
- * @implemented
- */
-VOID
-APIENTRY
-EngReleaseSemaphore ( IN HSEMAPHORE hsem )
+EngReleaseSemaphore(
+ _Inout_ HSEMAPHORE hsem)
{
//
www.osr.com/ddk/graphics/gdifncs_5u3r.htm
PTHREADINFO W32Thread;
ASSERT(hsem);
W32Thread = PsGetThreadWin32Thread(PsGetCurrentThread());
if (W32Thread) --W32Thread->dwEngAcquireCount;
- IntGdiReleaseSemaphore(hsem);
+ ExReleaseResourceAndLeaveCriticalRegion((PERESOURCE)hsem);
}
+_Acquires_lock_(_Global_critical_region_)
+_Requires_lock_not_held_(*hsem)
+_Acquires_shared_lock_(*hsem)
VOID
NTAPI
EngAcquireSemaphoreShared(
- IN HSEMAPHORE hsem)
+ _Inout_ HSEMAPHORE hsem)
{
PTHREADINFO pti;
@@ -87,9 +86,11 @@
/*
* @implemented
*/
+_Requires_lock_not_held_(*hsem)
VOID
APIENTRY
-EngDeleteSemaphore ( IN HSEMAPHORE hsem )
+EngDeleteSemaphore(
+ _Inout_ __drv_freesMem(Mem) HSEMAPHORE hsem)
{
//
www.osr.com/ddk/graphics/gdifncs_13c7.htm
ASSERT(hsem);
@@ -103,7 +104,8 @@
*/
BOOL
APIENTRY
-EngIsSemaphoreOwned ( IN HSEMAPHORE hsem )
+EngIsSemaphoreOwned(
+ _In_ HSEMAPHORE hsem)
{
//
www.osr.com/ddk/graphics/gdifncs_6wmf.htm
ASSERT(hsem);
@@ -115,7 +117,8 @@
*/
BOOL
APIENTRY
-EngIsSemaphoreOwnedByCurrentThread ( IN HSEMAPHORE hsem )
+EngIsSemaphoreOwnedByCurrentThread(
+ _In_ HSEMAPHORE hsem)
{
//
www.osr.com/ddk/graphics/gdifncs_9yxz.htm
ASSERT(hsem);
@@ -125,9 +128,10 @@
/*
* @implemented
*/
-BOOL APIENTRY
+BOOL
+APIENTRY
EngInitializeSafeSemaphore(
- OUT ENGSAFESEMAPHORE *Semaphore)
+ _Out_ ENGSAFESEMAPHORE *Semaphore)
{
HSEMAPHORE hSem;
@@ -158,15 +162,16 @@
/*
* @implemented
*/
-VOID APIENTRY
+VOID
+APIENTRY
EngDeleteSafeSemaphore(
- IN OUT ENGSAFESEMAPHORE *Semaphore)
+ _Inout_ _Post_invalid_ ENGSAFESEMAPHORE *pssem)
{
- if (InterlockedDecrement(&Semaphore->lCount) == 0)
+ if (InterlockedDecrement(&pssem->lCount) == 0)
{
/* FIXME: Not thread-safe! Use result of InterlockedCompareExchangePointer! */
- EngDeleteSemaphore(Semaphore->hsem);
- (void)InterlockedExchangePointer((volatile PVOID *)&Semaphore->hsem,
NULL);
+ EngDeleteSemaphore(pssem->hsem);
+ (void)InterlockedExchangePointer((volatile PVOID *)&pssem->hsem, NULL);
}
}
Modified: trunk/reactos/win32ss/reactx/ntddraw/dxeng.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/reactx/ntddraw/dxe…
==============================================================================
--- trunk/reactos/win32ss/reactx/ntddraw/dxeng.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/reactx/ntddraw/dxeng.c [iso-8859-1] Tue Mar 10 00:13:04 2015
@@ -180,7 +180,7 @@
{
DPRINT1("ReactX Calling : DxEngLockShareSem\n");
if(!ghsemShareDevLock) ghsemShareDevLock = EngCreateSemaphore(); // Hax, should be in
dllmain.c
- IntGdiAcquireSemaphore(ghsemShareDevLock);
+ EngAcquireSemaphore(ghsemShareDevLock);
return TRUE;
}
@@ -202,7 +202,7 @@
DxEngUnlockShareSem()
{
DPRINT1("ReactX Calling : DxEngUnlockShareSem\n");
- IntGdiReleaseSemaphore(ghsemShareDevLock);
+ EngReleaseSemaphore(ghsemShareDevLock);
return TRUE;
}