VirtualProtect() fixup

Andreas Mohr a.mohr at mailto.de
Mon Jun 4 19:02:21 CDT 2001


Hi all,

VirtualProtect had two big problems:

- undocumented return value
- should return protection flags only instead of whole flag setting

Alexandre: PE file mapping has big problems with page protections.
We don't care about setting up proper page protections at *all* yet.
(the ones given at IMAGE_SECTION_HEADER.Characteristics)
I've tried implementing support for this, but when I modify the page
protections properly, I get a write fault in fixup_imports, of course.
This means that we'd either have to modify page protections *after*
fixup_imports (difficult, since I believe protection modification should
belong to MapViewOfFileEx, and thus to map_image()) or we'd have to
temporarily switch to writable pages inside fixup_imports.

What to do ?

(as I don't have a solution on this problem, this patch only includes
VirtualProtect() changes)

Andreas Mohr
-------------- next part --------------
Determining best CVS host...
Using CVSROOT :pserver:cvs at rhlx01.fht-esslingen.de:/home/wine
Index: memory/virtual.c
===================================================================
RCS file: /home/wine/wine/memory/virtual.c,v
retrieving revision 1.62
diff -u -r1.62 virtual.c
--- memory/virtual.c	2001/04/20 18:28:18	1.62
+++ memory/virtual.c	2001/06/04 21:53:53
@@ -956,8 +956,15 @@
  * Changes the access protection on a region of committed pages
  *
  * RETURNS
- *	TRUE: Success
  *	FALSE: Failure
+ *	!= FALSE: Success (old protection flags, UNDOCUMENTED !)
+ *
+ * So in fact the BOOL return type is wrong, but it's the parameter
+ * of the "official" prototype.
+ *
+ * Note that old_prot returns a value that does NOT directly correspond
+ * to new_prot. It only returns the page protection value instead
+ * (i.e. values <= 0x08, without giving PAGE_EXECUTE_xxx information).
  */
 BOOL WINAPI VirtualProtect(
               LPVOID addr,     /* [in] Address of region of committed pages */
@@ -998,9 +1005,16 @@
         }
     }
 
+    if (prot & 0xf0)
+	prot >>= 4; /* only return protection info (omit executable state !) */
+    
     if (old_prot) *old_prot = prot;
     vprot = VIRTUAL_GetProt( new_prot ) | VPROT_COMMITTED;
-    return VIRTUAL_SetProt( view, base, size, vprot );
+    if (!(VIRTUAL_SetProt( view, base, size, vprot )))
+	return FALSE;
+
+    /* UNDOC: returns old prot flags (even if old_prot == NULL) */
+    return prot;
 }
 
 


More information about the wine-patches mailing list