Jacek Caban : gdi32: Directly use ntdll in dib.c.

Alexandre Julliard julliard at winehq.org
Fri Sep 17 16:03:09 CDT 2021


Module: wine
Branch: master
Commit: ac6458844af6e7dc2b57761a544677899762d3b3
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=ac6458844af6e7dc2b57761a544677899762d3b3

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Sep 17 13:45:10 2021 +0200

gdi32: Directly use ntdll in dib.c.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/gdi32/dib.c | 49 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/dlls/gdi32/dib.c b/dlls/gdi32/dib.c
index c5f6a41cb77..4d70e99a3c5 100644
--- a/dlls/gdi32/dib.c
+++ b/dlls/gdi32/dib.c
@@ -1531,33 +1531,40 @@ HBITMAP WINAPI NtGdiCreateDIBSection( HDC hdc, HANDLE section, DWORD offset, con
 
     if (section)
     {
-        DWORD mapOffset;
-        INT mapSize;
+        LARGE_INTEGER map_offset;
+        SIZE_T map_size;
 
-        mapOffset = offset - (offset % system_info.AllocationGranularity);
-        mapSize = bmp->dib.dsBmih.biSizeImage + (offset - mapOffset);
-        mapBits = MapViewOfFile( section, FILE_MAP_ALL_ACCESS, 0, mapOffset, mapSize );
-        if (mapBits) bmp->dib.dsBm.bmBits = (char *)mapBits + (offset - mapOffset);
+        map_offset.QuadPart = offset - (offset % system_info.AllocationGranularity);
+        map_size = bmp->dib.dsBmih.biSizeImage + (offset - map_offset.QuadPart);
+        if (NtMapViewOfSection( section, GetCurrentProcess(), &mapBits, 0, 0, &map_offset,
+                                &map_size, ViewShare, 0, PAGE_READWRITE ))
+            goto error;
+        bmp->dib.dsBm.bmBits = (char *)mapBits + (offset - map_offset.QuadPart);
     }
     else
     {
+        SIZE_T size = bmp->dib.dsBmih.biSizeImage;
         offset = 0;
-        bmp->dib.dsBm.bmBits = VirtualAlloc( NULL, bmp->dib.dsBmih.biSizeImage,
-                                             MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE );
+        if (NtAllocateVirtualMemory( GetCurrentProcess(), &bmp->dib.dsBm.bmBits, 0, &size,
+                                     MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE ))
+            goto error;
     }
     bmp->dib.dshSection = section;
     bmp->dib.dsOffset = offset;
 
-    if (!bmp->dib.dsBm.bmBits) goto error;
-
-    if (!(ret = alloc_gdi_handle( &bmp->obj, NTGDI_OBJ_BITMAP, &dib_funcs ))) goto error;
-
-    if (bits) *bits = bmp->dib.dsBm.bmBits;
-    return ret;
+    if ((ret = alloc_gdi_handle( &bmp->obj, NTGDI_OBJ_BITMAP, &dib_funcs )))
+    {
+        if (bits) *bits = bmp->dib.dsBm.bmBits;
+        return ret;
+    }
 
+    if (section) NtUnmapViewOfSection( GetCurrentProcess(), mapBits );
+    else
+    {
+        SIZE_T size = 0;
+        NtFreeVirtualMemory( GetCurrentProcess(), &bmp->dib.dsBm.bmBits, &size, MEM_RELEASE );
+    }
 error:
-    if (section) UnmapViewOfFile( mapBits );
-    else VirtualFree( bmp->dib.dsBm.bmBits, 0, MEM_RELEASE );
     HeapFree( GetProcessHeap(), 0, bmp->color_table );
     HeapFree( GetProcessHeap(), 0, bmp );
     return 0;
@@ -1739,10 +1746,14 @@ static BOOL DIB_DeleteObject( HGDIOBJ handle )
 
     if (bmp->dib.dshSection)
     {
-        UnmapViewOfFile( (char *)bmp->dib.dsBm.bmBits -
-                         (bmp->dib.dsOffset % system_info.AllocationGranularity) );
+        NtUnmapViewOfSection( GetCurrentProcess(), (char *)bmp->dib.dsBm.bmBits -
+                              (bmp->dib.dsOffset % system_info.AllocationGranularity) );
+    }
+    else
+    {
+        SIZE_T size = 0;
+        NtFreeVirtualMemory( GetCurrentProcess(), &bmp->dib.dsBm.bmBits, &size, MEM_RELEASE );
     }
-    else VirtualFree( bmp->dib.dsBm.bmBits, 0, MEM_RELEASE );
 
     HeapFree(GetProcessHeap(), 0, bmp->color_table);
     HeapFree( GetProcessHeap(), 0, bmp );




More information about the wine-cvs mailing list