[Wine-patches] [8/23] ntoskrnl.exe: Save process ID separately for every driver.

Alexander Morozov =?iso-8859-1?q?amorozov_=CE=C1_etersoft=2Eru?=
Пн Янв 19 18:23:42 MSK 2009


For eterhack branch
----------- следующая часть -----------
From 01d3795a4671b479f3326fd2a15ad56b17ca58cf Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Mon, 12 Jan 2009 11:15:48 +0300
Subject: [PATCH] ntoskrnl.exe: Save process ID separately for every driver.

---
 dlls/ntoskrnl.exe/ntoskrnl.c |   48 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c
index 94bb508..81c0679 100644
--- a/dlls/ntoskrnl.exe/ntoskrnl.c
+++ b/dlls/ntoskrnl.exe/ntoskrnl.c
@@ -114,6 +114,8 @@ struct DriverInstance
     struct list entry;
     DRIVER_OBJECT *driver;
     const WCHAR *service;
+    DWORD driver_thread_id;
+    DWORD process_id;
 };
 
 static struct list Interfaces = LIST_INIT(Interfaces);
@@ -132,8 +134,6 @@ struct InterfaceInstance
 #endif
 #endif
 
-static DWORD pid; /* ID of the process which calls IOCTL */
-
 #ifdef __i386__
 #define DEFINE_FASTCALL1_ENTRYPOINT( name ) \
     __ASM_GLOBAL_FUNC( name, \
@@ -205,6 +205,41 @@ static LONG CALLBACK vectored_handler( EXCEPTION_POINTERS *ptrs )
     return EXCEPTION_CONTINUE_SEARCH;
 }
 
+/* get id of the process whose request is being handled */
+static DWORD get_pid(void)
+{
+    DWORD ret = 0, thread_id = GetCurrentThreadId();
+    struct DriverInstance *drv;
+
+    LIST_FOR_EACH_ENTRY( drv, &Drivers, struct DriverInstance, entry )
+    {
+        if (drv->driver_thread_id == thread_id)
+        {
+            ret = drv->process_id;
+            break;
+        }
+    }
+    return ret;
+}
+
+/* save id of the process whose request is being handled */
+static void save_pid( DWORD pid )
+{
+    DWORD thread_id = GetCurrentThreadId();
+    struct DriverInstance *drv;
+
+    EnterCriticalSection( &cs );
+    LIST_FOR_EACH_ENTRY( drv, &Drivers, struct DriverInstance, entry )
+    {
+        if (drv->driver_thread_id == thread_id)
+        {
+            drv->process_id = pid;
+            break;
+        }
+    }
+    LeaveCriticalSection( &cs );
+}
+
 #if 0
 #ifdef __i386__
 static int map_memory( void *addr )
@@ -334,6 +369,7 @@ NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event )
     DEVICE_OBJECT *device = NULL;
     ULONG in_size = 4096, out_size = 0;
     HANDLE handles[2];
+    DWORD pid = 0;
 
     if (!(in_buff = HeapAlloc( GetProcessHeap(), 0, in_size )))
     {
@@ -371,6 +407,8 @@ NTSTATUS CDECL wine_ntoskrnl_main_loop( HANDLE stop_event )
         }
         SERVER_END_REQ;
 
+        save_pid( pid );
+
         switch(status)
         {
         case STATUS_SUCCESS:
@@ -410,6 +448,8 @@ BOOL CDECL __wine_add_driver_object( DRIVER_OBJECT *driver, const WCHAR *service
     if (drv == NULL) return FALSE;
     drv->driver = driver;
     drv->service = service;
+    drv->driver_thread_id = GetCurrentThreadId();
+    drv->process_id = 0;
     list_add_tail( &Drivers, &drv->entry );
     return TRUE;
 }
@@ -623,7 +663,7 @@ PMDL WINAPI IoAllocateMdl( PVOID VirtualAddress, ULONG Length, BOOLEAN Secondary
     mdl->MappedSystemVa = ptr;
     mdl->StartVa = VirtualAddress;
 
-    process = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid );
+    process = OpenProcess( PROCESS_ALL_ACCESS, FALSE, get_pid() );
     if (NULL == process)
     {
         ExFreePool( mdl );
@@ -649,7 +689,7 @@ void WINAPI IoFreeMdl( MDL *mdl )
 
     TRACE( "%p\n", mdl );
 
-    process = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid );
+    process = OpenProcess( PROCESS_ALL_ACCESS, FALSE, get_pid() );
     if (NULL != process)
     {
         NtWriteVirtualMemory( process, mdl->StartVa, mdl->MappedSystemVa,
-- 
1.6.0.2.GIT



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