PATCH: handle non aligned mmaps of sections

Marcus Meissner marcus at jet.franken.de
Sun Nov 9 14:42:52 CST 2003


Hi,

Another patch in the league of non-pagesize aligned / sized sections in
WDMs.

If we have just 128 byte alignment, even for the start address, our
unaligned malloc fails.

The file itself is page aligned in these cases, so don't get bad
overlaps.

This is in a codepath which did not trigger before, this is just new
with WDM handling.

Ciao, Marcus

Changelog:
	Try harder to map/read sections with small alignment.

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
@@ -953,7 +964,28 @@
  fake_mmap:
     /* Reserve the memory with an anonymous mmap */
     ret = wine_anon_mmap( start, size, PROT_READ | PROT_WRITE, flags );
-    if (ret == (LPVOID)-1) return ret;
+    if (ret == (LPVOID)-1) {
+
+	/* This only happens for WDMs, where the sections are not page aligned.
+	 * The whole file however is. */
+	if (((unsigned int)start & page_mask)) {
+	    int xoff = (unsigned int)start & page_mask;
+
+	    offset_low -= xoff;
+	    start -= xoff;
+	    size += xoff;
+	    ret = wine_anon_mmap( start, size, PROT_READ | PROT_WRITE, flags );
+	    if (ret != (LPVOID)-1) {
+		    /* Now read in the file */
+		    offset = ((off_t)offset_high << 32) | offset_low;
+		    pread( fd, ret, size, offset );
+		    mprotect( ret, size, prot );  /* Set the right protection */
+		    return ret + xoff;
+	    }
+	}
+
+	return ret;
+    }
     /* Now read in the file */
     offset = ((off_t)offset_high << 32) | offset_low;
     pread( fd, ret, size, offset );



More information about the wine-patches mailing list