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
This commit is contained in:
Hermès Bélusca-Maïto 2014-12-28 20:50:35 +00:00
parent 1c36df367b
commit f2f466977a
10 changed files with 125 additions and 92 deletions

View file

@ -132,6 +132,7 @@ typedef struct _DC
PVOID pSurfInfo; PVOID pSurfInfo;
POINTL ptlDoBanding; POINTL ptlDoBanding;
} DC; } DC;
// typedef struct _DC *PDC;
extern PDC defaultDCstate; extern PDC defaultDCstate;

View file

@ -44,7 +44,7 @@ typedef struct _PALETTE
ULONG ulBlueShift; ULONG ulBlueShift;
HDEV hPDev; HDEV hPDev;
PALETTEENTRY apalColors[0]; PALETTEENTRY apalColors[0];
} PALETTE; } PALETTE, *PPALETTE;
extern PALETTE gpalRGB, gpalBGR, gpalRGB555, gpalRGB565, *gppalMono, *gppalDefault; extern PALETTE gpalRGB, gpalBGR, gpalRGB555, gpalRGB565, *gppalMono, *gppalDefault;
extern PPALETTE appalSurfaceDefault[]; extern PPALETTE appalSurfaceDefault[];

View file

@ -1893,8 +1893,12 @@ IntMapDesktopView(IN PDESKTOP pdesk)
ppi = PsGetCurrentProcessWin32Process(); 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; HeapMapping = *PrevLink;
while (HeapMapping != NULL) while (HeapMapping != NULL)
{ {
@ -1904,7 +1908,7 @@ IntMapDesktopView(IN PDESKTOP pdesk)
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
PrevLink = &HeapMapping->Next; PrevLink = &HeapMapping->Next;
HeapMapping = 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); TRACE("ppi 0x%p mapped heap of desktop 0x%p\n", ppi, pdesk);
/* Add the mapping */ /* Add the mapping */
HeapMapping = UserHeapAlloc(sizeof(W32HEAP_USER_MAPPING)); HeapMapping = UserHeapAlloc(sizeof(*HeapMapping));
if (HeapMapping == NULL) if (HeapMapping == NULL)
{ {
MmUnmapViewOfSection(PsGetCurrentProcess(), UserBase); MmUnmapViewOfSection(PsGetCurrentProcess(), UserBase);

View file

@ -37,7 +37,7 @@ typedef struct _DESKTOP
/* Thread blocking input */ /* Thread blocking input */
PVOID BlockInputThread; PVOID BlockInputThread;
LIST_ENTRY ShellHookWindows; LIST_ENTRY ShellHookWindows;
} DESKTOP; } DESKTOP, *PDESKTOP;
// Desktop flags // Desktop flags
#define DF_TME_HOVER 0x00000400 #define DF_TME_HOVER 0x00000400
@ -259,6 +259,11 @@ DesktopHeapGetUserDelta(VOID)
pheapDesktop = pti->rpdesk->pheapDesktop; pheapDesktop = pti->rpdesk->pheapDesktop;
W32Process = PsGetCurrentProcessWin32Process(); 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; Mapping = W32Process->HeapMappings.Next;
while (Mapping != NULL) while (Mapping != NULL)
{ {
@ -281,6 +286,11 @@ DesktopHeapAddressToUser(PVOID lpMem)
PPROCESSINFO W32Process; PPROCESSINFO W32Process;
W32Process = PsGetCurrentProcessWin32Process(); 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; Mapping = W32Process->HeapMappings.Next;
while (Mapping != NULL) while (Mapping != NULL)
{ {
@ -303,4 +313,5 @@ BOOL FASTCALL IntPaintDesktop(HDC);
BOOL FASTCALL DesktopWindowProc(PWND, UINT, WPARAM, LPARAM, LRESULT *); BOOL FASTCALL DesktopWindowProc(PWND, UINT, WPARAM, LPARAM, LRESULT *);
BOOL FASTCALL UserMessageWindowProc(PWND pwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); BOOL FASTCALL UserMessageWindowProc(PWND pwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lResult);
VOID NTAPI DesktopThreadMain(); VOID NTAPI DesktopThreadMain();
/* EOF */ /* EOF */

View file

@ -24,9 +24,6 @@ NTSTATUS GdiProcessDestroy(PEPROCESS Process);
NTSTATUS GdiThreadCreate(PETHREAD Thread); NTSTATUS GdiThreadCreate(PETHREAD Thread);
NTSTATUS GdiThreadDestroy(PETHREAD Thread); NTSTATUS GdiThreadDestroy(PETHREAD Thread);
HANDLE GlobalUserHeap = NULL;
PVOID GlobalUserHeapSection = NULL;
PSERVERINFO gpsi = NULL; // Global User Server Information. PSERVERINFO gpsi = NULL; // Global User Server Information.
SHORT gusLanguageID; SHORT gusLanguageID;

View file

@ -24,78 +24,4 @@ VOID FASTCALL UserLeave(VOID);
BOOL FASTCALL UserIsEntered(VOID); BOOL FASTCALL UserIsEntered(VOID);
BOOL FASTCALL UserIsEnteredExclusive(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 */ /* EOF */

View file

@ -22,6 +22,9 @@
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
HANDLE GlobalUserHeap = NULL;
PVOID GlobalUserHeapSection = NULL;
_Function_class_(RTL_HEAP_COMMIT_ROUTINE) _Function_class_(RTL_HEAP_COMMIT_ROUTINE)
_IRQL_requires_same_ _IRQL_requires_same_
@ -63,7 +66,6 @@ IntUserHeapCommitRoutine(
{ {
SIZE_T ViewSize = 0; SIZE_T ViewSize = 0;
LARGE_INTEGER Offset; LARGE_INTEGER Offset;
extern PVOID GlobalUserHeapSection;
/* HACK: This needs to be handled during startup only... */ /* HACK: This needs to be handled during startup only... */
ASSERT(Base == (PVOID)GlobalUserHeap); ASSERT(Base == (PVOID)GlobalUserHeap);
@ -86,8 +88,8 @@ IntUserHeapCommitRoutine(
} }
/* Apply the commit address offset to the user base address */ /* Apply the commit address offset to the user base address */
Delta = (SIZE_T) ((ULONG_PTR) (*CommitAddress) - (ULONG_PTR) (Base)); Delta = (SIZE_T)((ULONG_PTR)(*CommitAddress) - (ULONG_PTR)Base);
UserCommitAddress = (PVOID) ((ULONG_PTR) (UserBase) + Delta); UserCommitAddress = (PVOID)((ULONG_PTR)UserBase + Delta);
/* Perform the actual commit */ /* Perform the actual commit */
Status = ZwAllocateVirtualMemory(NtCurrentProcess(), Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
@ -100,8 +102,8 @@ IntUserHeapCommitRoutine(
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* Determine the address to return */ /* Determine the address to return */
Delta = (SIZE_T) ((ULONG_PTR) (UserCommitAddress) - (ULONG_PTR) (UserBase)); Delta = (SIZE_T)((ULONG_PTR)UserCommitAddress - (ULONG_PTR)UserBase);
*CommitAddress = (PVOID) ((ULONG_PTR) (Base) + Delta); *CommitAddress = (PVOID)((ULONG_PTR)Base + Delta);
} }
if (W32Process == NULL) if (W32Process == NULL)

View file

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

View file

@ -52,7 +52,6 @@ extern HANDLE hModuleWin; // This Win32k Instance.
extern PCLS SystemClassList; extern PCLS SystemClassList;
extern BOOL RegisteredSysClasses; extern BOOL RegisteredSysClasses;
typedef struct _WIN32HEAP WIN32HEAP, *PWIN32HEAP;
typedef struct tagMENUSTATE MENUSTATE, *PMENUSTATE; typedef struct tagMENUSTATE MENUSTATE, *PMENUSTATE;
#include <pshpack1.h> #include <pshpack1.h>
@ -172,6 +171,7 @@ do { \
} \ } \
} while(0) } while(0)
#define IntReferenceProcessInfo(ppi) \ #define IntReferenceProcessInfo(ppi) \
InterlockedIncrement((volatile LONG*)(&(ppi)->RefCount)) InterlockedIncrement((volatile LONG*)(&(ppi)->RefCount))

View file

@ -38,8 +38,8 @@
/* Internal NtGdi Headers */ /* Internal NtGdi Headers */
typedef struct _DC *PDC; typedef struct _DC *PDC;
typedef struct _PALETTE *PPALETTE;
#include "gdi/ntgdi/gdiobj.h" #include "gdi/ntgdi/gdiobj.h"
#include "gdi/ntgdi/palette.h"
#include "gdi/eng/surface.h" #include "gdi/eng/surface.h"
#include "gdi/eng/pdevobj.h" #include "gdi/eng/pdevobj.h"
#include "gdi/eng/ldevobj.h" #include "gdi/eng/ldevobj.h"
@ -57,7 +57,6 @@ typedef struct _PALETTE *PPALETTE;
#include "gdi/ntgdi/brush.h" #include "gdi/ntgdi/brush.h"
#include "gdi/ntgdi/color.h" #include "gdi/ntgdi/color.h"
#include "gdi/ntgdi/bitmaps.h" #include "gdi/ntgdi/bitmaps.h"
#include "gdi/ntgdi/palette.h"
#include "gdi/ntgdi/region.h" #include "gdi/ntgdi/region.h"
#include "gdi/ntgdi/dc.h" #include "gdi/ntgdi/dc.h"
#include "gdi/ntgdi/dib.h" #include "gdi/ntgdi/dib.h"
@ -74,8 +73,8 @@ typedef struct _PALETTE *PPALETTE;
#include "reactx/ntddraw/intddraw.h" #include "reactx/ntddraw/intddraw.h"
/* Internal NtUser Headers */ /* Internal NtUser Headers */
typedef struct _DESKTOP *PDESKTOP;
#include "user/ntuser/win32.h" #include "user/ntuser/win32.h"
#include "user/ntuser/usrheap.h"
#include "user/ntuser/object.h" #include "user/ntuser/object.h"
#include "user/ntuser/ntuser.h" #include "user/ntuser/ntuser.h"
#include "user/ntuser/shutdown.h" #include "user/ntuser/shutdown.h"