[Wine-patches] ntoskrnl.exe: Use page_mask and page_size defines.

Alexander Morozov =?iso-8859-1?q?amorozov_=CE=C1_etersoft=2Eru?=
Пн Ноя 17 13:06:27 MSK 2008


----------- следующая часть -----------
From 5824aef55cad44c54addcc8af48a8533d48214a3 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Mon, 17 Nov 2008 12:57:52 +0300
Subject: [PATCH] ntoskrnl.exe: Use page_mask and page_size defines.

---
 dlls/ntoskrnl.exe/ntoskrnl.c |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c
index 1dcc909..39dd354 100644
--- a/dlls/ntoskrnl.exe/ntoskrnl.c
+++ b/dlls/ntoskrnl.exe/ntoskrnl.c
@@ -73,6 +73,11 @@ struct MemoryRegion
     int release;
 };
 
+#ifdef __i386__
+#define page_mask 0xfff
+#define page_size 0x1000
+#endif
+
 static DWORD pid; /* ID of the process which calls IOCTL */
 
 #ifdef __i386__
@@ -142,6 +147,7 @@ static LONG CALLBACK vectored_handler( EXCEPTION_POINTERS *ptrs )
     return EXCEPTION_CONTINUE_SEARCH;
 }
 
+#ifdef __i386__
 static int map_memory( void *addr )
 {
     struct MemoryRegion *mr;
@@ -150,12 +156,12 @@ static int map_memory( void *addr )
     mr = ExAllocatePool( NonPagedPool, sizeof(struct MemoryRegion) );
     if (mr == NULL)
         return 1;
-    addr = (void *)((unsigned int)addr & ~0xfff);
-    mr->ptr = VirtualAlloc( addr, 0x1000, MEM_COMMIT | MEM_RESERVE,
+    addr = (void *)((unsigned int)addr & ~page_mask);
+    mr->ptr = VirtualAlloc( addr, page_size, MEM_COMMIT | MEM_RESERVE,
             PAGE_EXECUTE_READWRITE );
     if (mr->ptr == NULL)
     {
-        mr->ptr = VirtualAlloc( addr, 0x1000, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
+        mr->ptr = VirtualAlloc( addr, page_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
         if (mr->ptr == NULL)
         {
             ExFreePool( mr );
@@ -168,11 +174,11 @@ static int map_memory( void *addr )
     process = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid );
     if (process == NULL)
     {
-        VirtualFree( mr->ptr, 0x1000, mr->release ? MEM_RELEASE : MEM_DECOMMIT );
+        VirtualFree( mr->ptr, page_size, mr->release ? MEM_RELEASE : MEM_DECOMMIT );
         ExFreePool( mr );
         return 1;
     }
-    NtReadVirtualMemory( process, mr->ptr, mr->ptr, 0x1000, NULL );
+    NtReadVirtualMemory( process, mr->ptr, mr->ptr, page_size, NULL );
     CloseHandle( process );
     list_add_tail( &MemoryList, &mr->entry );
     return 0;
@@ -188,10 +194,10 @@ static void unmap_memory(void)
         process = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid );
         if (process != NULL)
         {
-            NtWriteVirtualMemory( process, mr->ptr, mr->ptr, 0x1000, NULL );
+            NtWriteVirtualMemory( process, mr->ptr, mr->ptr, page_size, NULL );
             CloseHandle( process );
         }
-        VirtualFree( mr->ptr, 0x1000, mr->release ? MEM_RELEASE : MEM_DECOMMIT );
+        VirtualFree( mr->ptr, page_size, mr->release ? MEM_RELEASE : MEM_DECOMMIT );
         list_remove( &mr->entry );
         ExFreePool( mr );
     }
@@ -207,6 +213,7 @@ static LONG WINAPI memory_handler( EXCEPTION_POINTERS* except )
     }
     return EXCEPTION_CONTINUE_SEARCH;
 }
+#endif  /* __i386__ */
 
 /* process an ioctl request for a given device */
 static NTSTATUS process_ioctl( DEVICE_OBJECT *device, ULONG code, void *in_buff, ULONG in_size,
@@ -219,11 +226,15 @@ static NTSTATUS process_ioctl( DEVICE_OBJECT *device, ULONG code, void *in_buff,
     NTSTATUS status;
     LARGE_INTEGER count;
     CHAR *buf = NULL;
+#ifdef __i386__
     PVOID mem_handler;
+#endif
 
     TRACE( "ioctl %x device %p in_size %u out_size %u\n", code, device, in_size, *out_size );
 
+#ifdef __i386__
     mem_handler = RtlAddVectoredExceptionHandler( FALSE, memory_handler );
+#endif
 
     irp = IoAllocateIrp( device->StackSize, FALSE );
     if (irp == NULL)
@@ -288,8 +299,10 @@ static NTSTATUS process_ioctl( DEVICE_OBJECT *device, ULONG code, void *in_buff,
         memcpy( out_buff, buf, *out_size );
         ExFreePool( buf );
     }
+#ifdef __i386__
     RtlRemoveVectoredExceptionHandler( mem_handler );
     unmap_memory();
+#endif
 
     return status;
 }
-- 
1.6.0.2.GIT



Подробная информация о списке рассылки Wine-patches