CVS: winex/memory virtual.c,1.37,1.38

[email protected] 31 Jul 2007 19:49:18 -0000
Newsgroups gmane.comp.emulators.winex.cvs
Message-ID <[email protected]>
Subject: winex/memory virtual.c,1.37,1.38Update of /var/lib/cvsd/cvsroot/winex/memory
In directory agravaine:/tmp/cvs-serv837/memory

Modified Files:
	virtual.c 
Log Message:

- tell VMM about actual section permissions for mapped PE images


Index: virtual.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/memory/virtual.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- virtual.c	31 Jul 2007 19:43:46 -0000	1.37
+++ virtual.c	31 Jul 2007 19:49:15 -0000	1.38
@@ -804,7 +804,7 @@
     IMAGE_SECTION_HEADER *sec;
     int i, pos;
     DWORD err = GetLastError();
-    DWORD view_flags = VPROT_COMMITTED|VPROT_READ|VPROT_WRITE|VPROT_WRITECOPY;
+    DWORD view_flags = VPROT_COMMITTED|VPROT_READ|VPROT_WRITE|VPROT_WRITECOPY|VPROT_IMAGE;
     FILE_VIEW *view = NULL;
     char *ptr = NULL;
     int shared_fd = -1;
@@ -950,6 +950,27 @@
     /* Set the protection on the PE header READONLY rather than what we just set when we created the view */
     VIRTUAL_SetProt( view, ptr, header_size, VPROT_READ|VPROT_COMMITTED );
 
+    sec = (IMAGE_SECTION_HEADER *)((char *)&nt->OptionalHeader+nt->FileHeader.SizeOfOptionalHeader);
+    for (i = 0; i < nt->FileHeader.NumberOfSections; i++, sec++)
+    {
+        UINT size;
+        BYTE prot = VPROT_COMMITTED;
+
+        if (sec->Misc.VirtualSize)
+            size = ROUND_SIZE (sec->VirtualAddress, sec->Misc.VirtualSize);
+        else
+            size = ROUND_SIZE (sec->VirtualAddress, sec->SizeOfRawData);
+
+        if (sec->Characteristics & IMAGE_SCN_MEM_READ)
+           prot |= VPROT_READ;
+        if (sec->Characteristics & IMAGE_SCN_MEM_WRITE)
+           prot |= VPROT_READ | VPROT_WRITECOPY;
+        if (sec->Characteristics & IMAGE_SCN_MEM_EXECUTE)
+           prot |= VPROT_EXEC;
+
+        VIRTUAL_SetProt (view, ptr + sec->VirtualAddress, size, prot);
+    }
+
     SetLastError( err );  /* restore last error */
     close( fd );
     if (shared_fd != -1) close( shared_fd );
@@ -1744,6 +1765,7 @@
     else
     {
         BYTE vprot = view->prot[(base - alloc_base) >> page_shift];
+
         VIRTUAL_GetWin32Prot( vprot, &info->Protect, &info->State );
         for (size = base - alloc_base; size < view->size; size += page_mask+1)
             if (view->prot[size >> page_shift] != vprot) break;
@@ -1754,6 +1776,7 @@
     info->BaseAddress    = (LPVOID)base;
     info->AllocationBase = (LPVOID)alloc_base;
     info->RegionSize     = size - (base - alloc_base);
+
     return sizeof(*info);
 }