From f2f466977a0e8a56ea8b5fd1d82eab929629646e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 28 Dec 2014 20:50:35 +0000 Subject: [PATCH] [WIN32K] A bit of code reorganization: - move a maximum of typedefs into their corresponding headers, - move user heap functionality into a dedicated header, - add a note in some functions that the first heap mapping entry in the W32 process info structure is dedicated for the global user heap mapping, - remove extra-parenthesis in casts. svn path=/trunk/; revision=65863 --- reactos/win32ss/gdi/ntgdi/dc.h | 1 + reactos/win32ss/gdi/ntgdi/palette.h | 2 +- reactos/win32ss/user/ntuser/desktop.c | 12 ++-- reactos/win32ss/user/ntuser/desktop.h | 13 +++- reactos/win32ss/user/ntuser/main.c | 3 - reactos/win32ss/user/ntuser/ntuser.h | 74 --------------------- reactos/win32ss/user/ntuser/usrheap.c | 12 ++-- reactos/win32ss/user/ntuser/usrheap.h | 93 +++++++++++++++++++++++++++ reactos/win32ss/user/ntuser/win32.h | 2 +- reactos/win32ss/win32kp.h | 5 +- 10 files changed, 125 insertions(+), 92 deletions(-) create mode 100644 reactos/win32ss/user/ntuser/usrheap.h diff --git a/reactos/win32ss/gdi/ntgdi/dc.h b/reactos/win32ss/gdi/ntgdi/dc.h index d9d0c64ccfd..d1000fcac2a 100644 --- a/reactos/win32ss/gdi/ntgdi/dc.h +++ b/reactos/win32ss/gdi/ntgdi/dc.h @@ -132,6 +132,7 @@ typedef struct _DC PVOID pSurfInfo; POINTL ptlDoBanding; } DC; +// typedef struct _DC *PDC; extern PDC defaultDCstate; diff --git a/reactos/win32ss/gdi/ntgdi/palette.h b/reactos/win32ss/gdi/ntgdi/palette.h index 6f500b66737..b0dd72c2c6d 100644 --- a/reactos/win32ss/gdi/ntgdi/palette.h +++ b/reactos/win32ss/gdi/ntgdi/palette.h @@ -44,7 +44,7 @@ typedef struct _PALETTE ULONG ulBlueShift; HDEV hPDev; PALETTEENTRY apalColors[0]; -} PALETTE; +} PALETTE, *PPALETTE; extern PALETTE gpalRGB, gpalBGR, gpalRGB555, gpalRGB565, *gppalMono, *gppalDefault; extern PPALETTE appalSurfaceDefault[]; diff --git a/reactos/win32ss/user/ntuser/desktop.c b/reactos/win32ss/user/ntuser/desktop.c index 4e253e8530b..99d8ee93006 100644 --- a/reactos/win32ss/user/ntuser/desktop.c +++ b/reactos/win32ss/user/ntuser/desktop.c @@ -1893,8 +1893,12 @@ IntMapDesktopView(IN PDESKTOP pdesk) ppi = PsGetCurrentProcessWin32Process(); - /* Find out if another thread already mapped the desktop heap */ - PrevLink = &ppi->HeapMappings.Next; + /* + * Find out if another thread already mapped the desktop heap. + * Start the search at the next mapping: skip the first entry + * as it must be the global user heap mapping. + */ + PrevLink = &ppi->HeapMappings.Next; HeapMapping = *PrevLink; while (HeapMapping != NULL) { @@ -1904,7 +1908,7 @@ IntMapDesktopView(IN PDESKTOP pdesk) return STATUS_SUCCESS; } - PrevLink = &HeapMapping->Next; + PrevLink = &HeapMapping->Next; HeapMapping = HeapMapping->Next; } @@ -1929,7 +1933,7 @@ IntMapDesktopView(IN PDESKTOP pdesk) TRACE("ppi 0x%p mapped heap of desktop 0x%p\n", ppi, pdesk); /* Add the mapping */ - HeapMapping = UserHeapAlloc(sizeof(W32HEAP_USER_MAPPING)); + HeapMapping = UserHeapAlloc(sizeof(*HeapMapping)); if (HeapMapping == NULL) { MmUnmapViewOfSection(PsGetCurrentProcess(), UserBase); diff --git a/reactos/win32ss/user/ntuser/desktop.h b/reactos/win32ss/user/ntuser/desktop.h index cdf160fc0ab..9b0156ee6db 100644 --- a/reactos/win32ss/user/ntuser/desktop.h +++ b/reactos/win32ss/user/ntuser/desktop.h @@ -37,7 +37,7 @@ typedef struct _DESKTOP /* Thread blocking input */ PVOID BlockInputThread; LIST_ENTRY ShellHookWindows; -} DESKTOP; +} DESKTOP, *PDESKTOP; // Desktop flags #define DF_TME_HOVER 0x00000400 @@ -259,6 +259,11 @@ DesktopHeapGetUserDelta(VOID) pheapDesktop = pti->rpdesk->pheapDesktop; W32Process = PsGetCurrentProcessWin32Process(); + + /* + * Start the search at the next mapping: skip the first entry + * as it must be the global user heap mapping. + */ Mapping = W32Process->HeapMappings.Next; while (Mapping != NULL) { @@ -281,6 +286,11 @@ DesktopHeapAddressToUser(PVOID lpMem) PPROCESSINFO W32Process; W32Process = PsGetCurrentProcessWin32Process(); + + /* + * Start the search at the next mapping: skip the first entry + * as it must be the global user heap mapping. + */ Mapping = W32Process->HeapMappings.Next; while (Mapping != NULL) { @@ -303,4 +313,5 @@ BOOL FASTCALL IntPaintDesktop(HDC); BOOL FASTCALL DesktopWindowProc(PWND, UINT, WPARAM, LPARAM, LRESULT *); BOOL FASTCALL UserMessageWindowProc(PWND pwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); VOID NTAPI DesktopThreadMain(); + /* EOF */ diff --git a/reactos/win32ss/user/ntuser/main.c b/reactos/win32ss/user/ntuser/main.c index 9f04f9d50a3..716fab8900b 100644 --- a/reactos/win32ss/user/ntuser/main.c +++ b/reactos/win32ss/user/ntuser/main.c @@ -24,9 +24,6 @@ NTSTATUS GdiProcessDestroy(PEPROCESS Process); NTSTATUS GdiThreadCreate(PETHREAD Thread); NTSTATUS GdiThreadDestroy(PETHREAD Thread); -HANDLE GlobalUserHeap = NULL; -PVOID GlobalUserHeapSection = NULL; - PSERVERINFO gpsi = NULL; // Global User Server Information. SHORT gusLanguageID; diff --git a/reactos/win32ss/user/ntuser/ntuser.h b/reactos/win32ss/user/ntuser/ntuser.h index 799318af50f..88203c2f6eb 100644 --- a/reactos/win32ss/user/ntuser/ntuser.h +++ b/reactos/win32ss/user/ntuser/ntuser.h @@ -24,78 +24,4 @@ VOID FASTCALL UserLeave(VOID); BOOL FASTCALL UserIsEntered(VOID); BOOL FASTCALL UserIsEnteredExclusive(VOID); -/* User heap */ -extern HANDLE GlobalUserHeap; - -PWIN32HEAP -UserCreateHeap(OUT PVOID *SectionObject, - IN OUT PVOID *SystemBase, - IN SIZE_T HeapSize); - -static __inline PVOID -UserHeapAlloc(SIZE_T Bytes) -{ - return RtlAllocateHeap(GlobalUserHeap, - HEAP_NO_SERIALIZE, - Bytes); -} - -static __inline BOOL -UserHeapFree(PVOID lpMem) -{ - return RtlFreeHeap(GlobalUserHeap, - HEAP_NO_SERIALIZE, - lpMem); -} - -static __inline PVOID -UserHeapReAlloc(PVOID lpMem, - SIZE_T Bytes) -{ -#if 0 - /* NOTE: ntoskrnl doesn't export RtlReAllocateHeap... */ - return RtlReAllocateHeap(GlobalUserHeap, - HEAP_NO_SERIALIZE, - lpMem, - Bytes); -#else - SIZE_T PrevSize; - PVOID pNew; - - PrevSize = RtlSizeHeap(GlobalUserHeap, - HEAP_NO_SERIALIZE, - lpMem); - - if (PrevSize == Bytes) - return lpMem; - - pNew = RtlAllocateHeap(GlobalUserHeap, - HEAP_NO_SERIALIZE, - Bytes); - if (pNew != NULL) - { - if (PrevSize < Bytes) - Bytes = PrevSize; - - RtlCopyMemory(pNew, - lpMem, - Bytes); - - RtlFreeHeap(GlobalUserHeap, - HEAP_NO_SERIALIZE, - lpMem); - } - - return pNew; -#endif -} - -static __inline PVOID -UserHeapAddressToUser(PVOID lpMem) -{ - PPROCESSINFO W32Process = PsGetCurrentProcessWin32Process(); - return (PVOID)(((ULONG_PTR)lpMem - (ULONG_PTR)GlobalUserHeap) + - (ULONG_PTR)W32Process->HeapMappings.UserMapping); -} - /* EOF */ diff --git a/reactos/win32ss/user/ntuser/usrheap.c b/reactos/win32ss/user/ntuser/usrheap.c index 482484ad908..73c8ce93f4c 100644 --- a/reactos/win32ss/user/ntuser/usrheap.c +++ b/reactos/win32ss/user/ntuser/usrheap.c @@ -22,6 +22,9 @@ #define NDEBUG #include +HANDLE GlobalUserHeap = NULL; +PVOID GlobalUserHeapSection = NULL; + _Function_class_(RTL_HEAP_COMMIT_ROUTINE) _IRQL_requires_same_ @@ -63,7 +66,6 @@ IntUserHeapCommitRoutine( { SIZE_T ViewSize = 0; LARGE_INTEGER Offset; - extern PVOID GlobalUserHeapSection; /* HACK: This needs to be handled during startup only... */ ASSERT(Base == (PVOID)GlobalUserHeap); @@ -86,8 +88,8 @@ IntUserHeapCommitRoutine( } /* Apply the commit address offset to the user base address */ - Delta = (SIZE_T) ((ULONG_PTR) (*CommitAddress) - (ULONG_PTR) (Base)); - UserCommitAddress = (PVOID) ((ULONG_PTR) (UserBase) + Delta); + Delta = (SIZE_T)((ULONG_PTR)(*CommitAddress) - (ULONG_PTR)Base); + UserCommitAddress = (PVOID)((ULONG_PTR)UserBase + Delta); /* Perform the actual commit */ Status = ZwAllocateVirtualMemory(NtCurrentProcess(), @@ -100,8 +102,8 @@ IntUserHeapCommitRoutine( if (NT_SUCCESS(Status)) { /* Determine the address to return */ - Delta = (SIZE_T) ((ULONG_PTR) (UserCommitAddress) - (ULONG_PTR) (UserBase)); - *CommitAddress = (PVOID) ((ULONG_PTR) (Base) + Delta); + Delta = (SIZE_T)((ULONG_PTR)UserCommitAddress - (ULONG_PTR)UserBase); + *CommitAddress = (PVOID)((ULONG_PTR)Base + Delta); } if (W32Process == NULL) diff --git a/reactos/win32ss/user/ntuser/usrheap.h b/reactos/win32ss/user/ntuser/usrheap.h new file mode 100644 index 00000000000..71c6c4e6a1b --- /dev/null +++ b/reactos/win32ss/user/ntuser/usrheap.h @@ -0,0 +1,93 @@ +#pragma once + +typedef struct _WIN32HEAP WIN32HEAP, *PWIN32HEAP; + +/* +typedef struct _W32HEAP_USER_MAPPING +{ + struct _W32HEAP_USER_MAPPING* Next; + PVOID KernelMapping; + PVOID UserMapping; + ULONG_PTR Limit; + ULONG Count; +} W32HEAP_USER_MAPPING, *PW32HEAP_USER_MAPPING; +*/ + +/* User heap */ +extern HANDLE GlobalUserHeap; +extern PVOID GlobalUserHeapSection; + +PWIN32HEAP +UserCreateHeap(OUT PVOID *SectionObject, + IN OUT PVOID *SystemBase, + IN SIZE_T HeapSize); + +static __inline PVOID +UserHeapAlloc(SIZE_T Bytes) +{ + return RtlAllocateHeap(GlobalUserHeap, + HEAP_NO_SERIALIZE, + Bytes); +} + +static __inline BOOL +UserHeapFree(PVOID lpMem) +{ + return RtlFreeHeap(GlobalUserHeap, + HEAP_NO_SERIALIZE, + lpMem); +} + +static __inline PVOID +UserHeapReAlloc(PVOID lpMem, + SIZE_T Bytes) +{ +#if 0 + /* NOTE: ntoskrnl doesn't export RtlReAllocateHeap... */ + return RtlReAllocateHeap(GlobalUserHeap, + HEAP_NO_SERIALIZE, + lpMem, + Bytes); +#else + SIZE_T PrevSize; + PVOID pNew; + + PrevSize = RtlSizeHeap(GlobalUserHeap, + HEAP_NO_SERIALIZE, + lpMem); + + if (PrevSize == Bytes) + return lpMem; + + pNew = RtlAllocateHeap(GlobalUserHeap, + HEAP_NO_SERIALIZE, + Bytes); + if (pNew != NULL) + { + if (PrevSize < Bytes) + Bytes = PrevSize; + + RtlCopyMemory(pNew, + lpMem, + Bytes); + + RtlFreeHeap(GlobalUserHeap, + HEAP_NO_SERIALIZE, + lpMem); + } + + return pNew; +#endif +} + +static __inline PVOID +UserHeapAddressToUser(PVOID lpMem) +{ + PPROCESSINFO W32Process = PsGetCurrentProcessWin32Process(); + + /* The first mapping entry is the global user heap mapping */ + return (PVOID)(((ULONG_PTR)lpMem - (ULONG_PTR)GlobalUserHeap) + + (ULONG_PTR)W32Process->HeapMappings.UserMapping); +} + +/* EOF */ diff --git a/reactos/win32ss/user/ntuser/win32.h b/reactos/win32ss/user/ntuser/win32.h index 608c2edc394..25215ce2dec 100644 --- a/reactos/win32ss/user/ntuser/win32.h +++ b/reactos/win32ss/user/ntuser/win32.h @@ -52,7 +52,6 @@ extern HANDLE hModuleWin; // This Win32k Instance. extern PCLS SystemClassList; extern BOOL RegisteredSysClasses; -typedef struct _WIN32HEAP WIN32HEAP, *PWIN32HEAP; typedef struct tagMENUSTATE MENUSTATE, *PMENUSTATE; #include @@ -172,6 +171,7 @@ do { \ } \ } while(0) + #define IntReferenceProcessInfo(ppi) \ InterlockedIncrement((volatile LONG*)(&(ppi)->RefCount)) diff --git a/reactos/win32ss/win32kp.h b/reactos/win32ss/win32kp.h index ce5e7ec3eea..f008722fbff 100644 --- a/reactos/win32ss/win32kp.h +++ b/reactos/win32ss/win32kp.h @@ -38,8 +38,8 @@ /* Internal NtGdi Headers */ typedef struct _DC *PDC; -typedef struct _PALETTE *PPALETTE; #include "gdi/ntgdi/gdiobj.h" +#include "gdi/ntgdi/palette.h" #include "gdi/eng/surface.h" #include "gdi/eng/pdevobj.h" #include "gdi/eng/ldevobj.h" @@ -57,7 +57,6 @@ typedef struct _PALETTE *PPALETTE; #include "gdi/ntgdi/brush.h" #include "gdi/ntgdi/color.h" #include "gdi/ntgdi/bitmaps.h" -#include "gdi/ntgdi/palette.h" #include "gdi/ntgdi/region.h" #include "gdi/ntgdi/dc.h" #include "gdi/ntgdi/dib.h" @@ -74,8 +73,8 @@ typedef struct _PALETTE *PPALETTE; #include "reactx/ntddraw/intddraw.h" /* Internal NtUser Headers */ -typedef struct _DESKTOP *PDESKTOP; #include "user/ntuser/win32.h" +#include "user/ntuser/usrheap.h" #include "user/ntuser/object.h" #include "user/ntuser/ntuser.h" #include "user/ntuser/shutdown.h"