PATCH: adjust section alignment handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Checks using section alignment are pretty strict, which they don't need to be.

This is exposed when using "unusual" dlls, who have just 128 byte alignment.

Ciao, Marcus

Changelog:
	Check section sizes rounded up against the specified section alignment,
	not page size.

Index: dlls/ntdll/virtual.c
===================================================================
RCS file: /home/wine/wine/dlls/ntdll/virtual.c,v
retrieving revision 1.17
diff -u -r1.17 virtual.c
--- dlls/ntdll/virtual.c	4 Nov 2003 04:50:19 -0000	1.17
+++ dlls/ntdll/virtual.c	9 Nov 2003 20:34:43 -0000
@@ -132,6 +132,9 @@
 #define ROUND_SIZE(addr,size) \
    (((UINT)(size) + ((UINT_PTR)(addr) & page_mask) + page_mask) & ~page_mask)
 
+#define ROUND_SIZE_MASK(addr,size,mask) \
+   (((UINT)(size) + ((UINT_PTR)(addr) & (mask)) + (mask)) & ~(mask))
+
 #define VIRTUAL_DEBUG_DUMP_VIEW(view) \
    if (!TRACE_ON(virtual)); else VIRTUAL_DumpView(view)
 
@@ -621,10 +624,18 @@
 
     for (i = pos = 0; i < nt->FileHeader.NumberOfSections; i++, sec++)
     {
-        DWORD size;
+        DWORD size, secmask;
+
+	/* Be careful when accessing the optional header */
+	if ((nt->FileHeader.SizeOfOptionalHeader >= 0x24) &&
+	     nt->OptionalHeader.SectionAlignment
+        )
+	    secmask = nt->OptionalHeader.SectionAlignment-1;
+	else
+	    secmask = page_mask;
 
         /* a few sanity checks */
-        size = sec->VirtualAddress + ROUND_SIZE( sec->VirtualAddress, sec->Misc.VirtualSize );
+        size = sec->VirtualAddress + ROUND_SIZE_MASK( sec->VirtualAddress, sec->Misc.VirtualSize, secmask );
         if (sec->VirtualAddress > total_size || size > total_size || size < sec->VirtualAddress)
         {
             ERR_(module)( "Section %.8s too large (%lx+%lx/%lx)\n",
@@ -635,8 +646,8 @@
         if ((sec->Characteristics & IMAGE_SCN_MEM_SHARED) &&
             (sec->Characteristics & IMAGE_SCN_MEM_WRITE))
         {
-            size = ROUND_SIZE( 0, sec->Misc.VirtualSize );
-            TRACE_(module)( "mapping shared section %.8s at %p off %lx (%x) size %lx (%lx) flags %lx\n",
+            size = ROUND_SIZE_MASK( 0, sec->Misc.VirtualSize, secmask );
+            TRACE_(module)( "mapping shared section %.8s at %p off 0x%lx (%x) size 0x%lx (%lx) flags 0x%lx\n",
                           sec->Name, ptr + sec->VirtualAddress,
                           sec->PointerToRawData, pos, sec->SizeOfRawData,
                           size, sec->Characteristics );
@@ -653,7 +664,7 @@
                 imports->VirtualAddress < sec->VirtualAddress + size)
             {
                 UINT_PTR base = imports->VirtualAddress & ~page_mask;
-                UINT_PTR end = base + ROUND_SIZE( imports->VirtualAddress, imports->Size );
+                UINT_PTR end = base + ROUND_SIZE_MASK( imports->VirtualAddress, imports->Size, secmask );
                 if (end > sec->VirtualAddress + size) end = sec->VirtualAddress + size;
                 if (end > base) VIRTUAL_mmap( shared_fd, ptr + base, end - base,
                                               pos + (base - sec->VirtualAddress), 0,
@@ -686,7 +697,7 @@
 
         if ((sec->SizeOfRawData < sec->Misc.VirtualSize) && (sec->SizeOfRawData & page_mask))
         {
-            DWORD end = ROUND_SIZE( 0, sec->SizeOfRawData );
+            DWORD end = ROUND_SIZE_MASK( 0, sec->SizeOfRawData, secmask );
             if (end > sec->Misc.VirtualSize) end = sec->Misc.VirtualSize;
             TRACE_(module)("clearing %p - %p\n",
                            ptr + sec->VirtualAddress + sec->SizeOfRawData,


[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux