- Implement EngMapSectionView and EngUnmapSectionView. Use EngUnmapSectionView in SURFACE_Cleanup.

svn path=/trunk/; revision=56536
This commit is contained in:
Timo Kreuzer 2012-05-07 22:41:10 +00:00
parent c0a4db6701
commit b1305c8589
5 changed files with 160 additions and 66 deletions

View file

@ -25,18 +25,4 @@ VOID FASTCALL IntGdiAcquireSemaphore ( HSEMAPHORE hsem );
VOID FASTCALL IntGdiReleaseSemaphore ( HSEMAPHORE hsem );
ULONGLONG APIENTRY EngGetTickCount(VOID);
BOOL
APIENTRY
EngFreeSectionMem(
IN PVOID pvSection OPTIONAL,
IN PVOID pvMappedBase OPTIONAL);
PVOID
APIENTRY
EngAllocSectionMem(
OUT PVOID *ppvSection,
IN ULONG fl,
IN SIZE_T cjSize,
IN ULONG ulTag);
VOID DecompressBitmap(SIZEL Size, BYTE *CompressedBits, BYTE *UncompressedBits, LONG Delta, ULONG iFormat);

View file

@ -15,45 +15,77 @@
#define MmMapViewInSessionSpace MmMapViewInSystemSpace
#define MmUnmapViewInSessionSpace MmUnmapViewInSystemSpace
typedef struct _ENGSECTION
{
PVOID pvSectionObject;
PVOID pvMappedBase;
SIZE_T cjViewSize;
ULONG ulTag;
} ENGSECTION, *PENGSECTION;
typedef struct _FILEVIEW
{
LARGE_INTEGER LastWriteTime;
PVOID pvKView;
PVOID pvViewFD;
SIZE_T cjView;
PVOID pSection;
} FILEVIEW, *PFILEVIEW;
typedef struct _FONTFILEVIEW
{
FILEVIEW;
DWORD reserved[2];
PWSTR pwszPath;
SIZE_T ulRegionSize;
ULONG cKRefCount;
ULONG cRefCountFD;
PVOID pvSpoolerBase;
DWORD dwSpoolerPid;
} FONTFILEVIEW, *PFONTFILEVIEW;
enum
{
FVF_SYSTEMROOT = 1,
FVF_READONLY = 2,
FVF_FONTFILE = 4,
};
HANDLE ghSystem32Directory;
HANDLE ghRootDirectory;
PVOID
NTAPI
EngMapSectionView(
_In_ HANDLE hSection,
_In_ SIZE_T cjSize,
_In_ ULONG cjOffset,
_Out_ PHANDLE phSecure)
{
LARGE_INTEGER liSectionOffset;
PVOID pvBaseAddress;
NTSTATUS Status;
/* Align the offset at allocation granularity and compensate for the size */
liSectionOffset.QuadPart = cjOffset & ~(MM_ALLOCATION_GRANULARITY - 1);
cjSize += cjOffset & (MM_ALLOCATION_GRANULARITY - 1);
/* Map the section */
Status = ZwMapViewOfSection(hSection,
NtCurrentProcess(),
&pvBaseAddress,
0,
cjSize,
&liSectionOffset,
&cjSize,
ViewShare,
0,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DPRINT1("ZwMapViewOfSection failed (0x%lx)\n", Status);
return NULL;
}
/* Secure the section memory */
*phSecure = EngSecureMem(pvBaseAddress, cjSize);
if (!*phSecure)
{
ZwUnmapViewOfSection(NtCurrentProcess(), pvBaseAddress);
return NULL;
}
/* Return the address where the requested data starts */
return (PUCHAR)pvBaseAddress + (cjOffset & (MM_ALLOCATION_GRANULARITY - 1));
}
VOID
NTAPI
EngUnmapSectionView(
_In_ PVOID pvBits,
_In_ ULONG cjOffset,
_In_ HANDLE hSecure)
{
NTSTATUS Status;
/* Unsecure the memory */
EngUnsecureMem(hSecure);
/* Calculate the real start of the section view */
pvBits = (PUCHAR)pvBits - (cjOffset & (MM_ALLOCATION_GRANULARITY - 1));
/* Unmap the section view */
Status = MmUnmapViewOfSection(PsGetCurrentProcess(), pvBits);
if (!NT_SUCCESS(Status))
{
DPRINT1("Could not unmap section view!\n");
}
}
PVOID
NTAPI
@ -156,7 +188,7 @@ EngMapSection(
}
else
{
DPRINT1("Failed to unmap a section @ &p Status=0x%x\n",
DPRINT1("Failed to unmap a section @ &p Status=0x%x\n",
pSection->pvMappedBase, Status);
}
}

View file

@ -0,0 +1,88 @@
typedef struct _ENGSECTION
{
PVOID pvSectionObject;
PVOID pvMappedBase;
SIZE_T cjViewSize;
ULONG ulTag;
} ENGSECTION, *PENGSECTION;
typedef struct _FILEVIEW
{
LARGE_INTEGER LastWriteTime;
PVOID pvKView;
PVOID pvViewFD;
SIZE_T cjView;
PVOID pSection;
} FILEVIEW, *PFILEVIEW;
typedef struct _FONTFILEVIEW
{
FILEVIEW;
DWORD reserved[2];
PWSTR pwszPath;
SIZE_T ulRegionSize;
ULONG cKRefCount;
ULONG cRefCountFD;
PVOID pvSpoolerBase;
DWORD dwSpoolerPid;
} FONTFILEVIEW, *PFONTFILEVIEW;
enum
{
FVF_SYSTEMROOT = 1,
FVF_READONLY = 2,
FVF_FONTFILE = 4,
};
PVOID
NTAPI
EngMapSectionView(
_In_ HANDLE hSection,
_In_ SIZE_T cjSize,
_In_ ULONG cjOffset,
_Out_ PHANDLE phSecure);
VOID
NTAPI
EngUnmapSectionView(
_In_ PVOID pvBits,
_In_ ULONG cjOffset,
_In_ HANDLE hSecure);
PVOID
NTAPI
EngCreateSection(
IN ULONG fl,
IN SIZE_T cjSize,
IN ULONG ulTag);
BOOL
APIENTRY
EngMapSection(
IN PVOID pvSection,
IN BOOL bMap,
IN HANDLE hProcess,
OUT PVOID* pvBaseAddress);
PVOID
APIENTRY
EngAllocSectionMem(
OUT PVOID *ppvSection,
IN ULONG fl,
IN SIZE_T cjSize,
IN ULONG ulTag);
BOOL
APIENTRY
EngFreeSectionMem(
IN PVOID pvSection OPTIONAL,
IN PVOID pvMappedBase OPTIONAL);
PFILEVIEW
NTAPI
EngLoadModuleEx(
LPWSTR pwsz,
ULONG cjSizeOfModule,
FLONG fl);

View file

@ -68,7 +68,6 @@ SURFACE_Cleanup(PVOID ObjectBody)
{
PSURFACE psurf = (PSURFACE)ObjectBody;
PVOID pvBits = psurf->SurfObj.pvBits;
NTSTATUS Status;
/* Check if the surface has bits */
if (pvBits)
@ -79,20 +78,8 @@ SURFACE_Cleanup(PVOID ObjectBody)
/* Check if it is a DIB section */
if (psurf->hDIBSection)
{
/* Unsecure the memory */
EngUnsecureMem(psurf->hSecure);
/* Calculate the real start of the section */
pvBits = (PVOID)((ULONG_PTR)pvBits - psurf->dwOffset);
/* Unmap the section */
Status = MmUnmapViewOfSection(PsGetCurrentProcess(), pvBits);
if (!NT_SUCCESS(Status))
{
DPRINT1("Could not unmap section view!\n");
// Should we BugCheck here?
ASSERT(FALSE);
}
/* Unmap the section view */
EngUnmapSectionView(pvBits, psurf->dwOffset, psurf->hSecure);
}
else if (psurf->SurfObj.fjBitmap & BMF_USERMEM)
{

View file

@ -49,6 +49,7 @@ typedef struct _PALETTE *PPALETTE;
#include "gdi/eng/xlateobj.h"
#include "gdi/eng/floatobj.h"
#include "gdi/eng/mouse.h"
#include "gdi/eng/mapping.h"
#include "gdi/ntgdi/xformobj.h"
#include "gdi/ntgdi/brush.h"
#include "gdi/ntgdi/color.h"