diff --git a/reactos/win32ss/gdi/eng/eng.h b/reactos/win32ss/gdi/eng/eng.h index 0dce0cbbe49..a17583284f4 100644 --- a/reactos/win32ss/gdi/eng/eng.h +++ b/reactos/win32ss/gdi/eng/eng.h @@ -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); diff --git a/reactos/win32ss/gdi/eng/mapping.c b/reactos/win32ss/gdi/eng/mapping.c index 0da46dfca29..0b163cee4c7 100644 --- a/reactos/win32ss/gdi/eng/mapping.c +++ b/reactos/win32ss/gdi/eng/mapping.c @@ -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); } } diff --git a/reactos/win32ss/gdi/eng/mapping.h b/reactos/win32ss/gdi/eng/mapping.h new file mode 100644 index 00000000000..5156b2a3c9a --- /dev/null +++ b/reactos/win32ss/gdi/eng/mapping.h @@ -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); + diff --git a/reactos/win32ss/gdi/eng/surface.c b/reactos/win32ss/gdi/eng/surface.c index 959c519787e..de9b79770af 100644 --- a/reactos/win32ss/gdi/eng/surface.c +++ b/reactos/win32ss/gdi/eng/surface.c @@ -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) { diff --git a/reactos/win32ss/win32kp.h b/reactos/win32ss/win32kp.h index c0ad5b44987..b553e5c992b 100644 --- a/reactos/win32ss/win32kp.h +++ b/reactos/win32ss/win32kp.h @@ -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"