[Wine-patches] [9/23] ntoskrnl.exe: Use critical section when static variables are accessed.

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


For eterhack branch
----------- следующая часть -----------
From 2a32b80f1dc505e8804bb69259d3e319f2fa73c1 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Mon, 12 Jan 2009 11:17:04 +0300
Subject: [PATCH] ntoskrnl.exe: Use critical section when static variables are accessed.

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

diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c
index 81c0679..6439c3b 100644
--- a/dlls/ntoskrnl.exe/ntoskrnl.c
+++ b/dlls/ntoskrnl.exe/ntoskrnl.c
@@ -78,6 +78,8 @@ struct PdoExtension
     struct DeviceInstance *instance;
 };
 
+static CRITICAL_SECTION cs;
+
 static struct list Irps = LIST_INIT(Irps);
 
 struct IrpInstance
@@ -211,6 +213,7 @@ static DWORD get_pid(void)
     DWORD ret = 0, thread_id = GetCurrentThreadId();
     struct DriverInstance *drv;
 
+    EnterCriticalSection( &cs );
     LIST_FOR_EACH_ENTRY( drv, &Drivers, struct DriverInstance, entry )
     {
         if (drv->driver_thread_id == thread_id)
@@ -219,6 +222,7 @@ static DWORD get_pid(void)
             break;
         }
     }
+    LeaveCriticalSection( &cs );
     return ret;
 }
 
@@ -450,7 +454,9 @@ BOOL CDECL __wine_add_driver_object( DRIVER_OBJECT *driver, const WCHAR *service
     drv->service = service;
     drv->driver_thread_id = GetCurrentThreadId();
     drv->process_id = 0;
+    EnterCriticalSection( &cs );
     list_add_tail( &Drivers, &drv->entry );
+    LeaveCriticalSection( &cs );
     return TRUE;
 }
 
@@ -462,15 +468,17 @@ void CDECL __wine_del_driver_object( const DRIVER_OBJECT *driver )
 {
     struct DriverInstance *drv;
 
+    EnterCriticalSection( &cs );
     LIST_FOR_EACH_ENTRY( drv, &Drivers, struct DriverInstance, entry )
     {
         if (drv->driver == driver)
         {
             list_remove( &drv->entry );
             HeapFree( GetProcessHeap(), 0, drv );
-            return;
+            break;
         }
     }
+    LeaveCriticalSection( &cs );
 }
 
 
@@ -480,13 +488,19 @@ void CDECL __wine_del_driver_object( const DRIVER_OBJECT *driver )
 DRIVER_OBJECT * CDECL __wine_get_driver_object( const WCHAR *service )
 {
     struct DriverInstance *drv;
+    DRIVER_OBJECT *driver_obj = NULL;
 
+    EnterCriticalSection( &cs );
     LIST_FOR_EACH_ENTRY( drv, &Drivers, struct DriverInstance, entry )
     {
         if (!strcmpW( drv->service, service ))
-            return drv->driver;
+        {
+            driver_obj = drv->driver;
+            break;
+        }
     }
-    return NULL;
+    LeaveCriticalSection( &cs );
+    return driver_obj;
 }
 
 
@@ -561,7 +575,9 @@ NTSTATUS WINAPI IoAllocateDriverObjectExtension( PDRIVER_OBJECT DriverObject,
     }
     ext->driver = DriverObject;
     ext->id_addr = ClientIdentificationAddress;
+    EnterCriticalSection( &cs );
     list_add_tail( &DriverObjExtensions, &ext->entry );
+    LeaveCriticalSection( &cs );
     *DriverObjectExtension = ext->ptr;
     return STATUS_SUCCESS;
 }
@@ -573,16 +589,22 @@ PVOID WINAPI IoGetDriverObjectExtension( PDRIVER_OBJECT DriverObject,
                                          PVOID ClientIdentificationAddress )
 {
     struct DriverObjExtension *ext;
+    void *ext_ptr = NULL;
 
     TRACE( "%p, %p\n", DriverObject, ClientIdentificationAddress );
 
+    EnterCriticalSection( &cs );
     LIST_FOR_EACH_ENTRY( ext, &DriverObjExtensions, struct DriverObjExtension, entry )
     {
         if (DriverObject == ext->driver &&
             ClientIdentificationAddress == ext->id_addr)
-            return ext->ptr;
+        {
+            ext_ptr = ext->ptr;
+            break;
+        }
     }
-    return NULL;
+    LeaveCriticalSection( &cs );
+    return ext_ptr;
 }
 
 /***********************************************************************
@@ -798,7 +820,9 @@ PIRP WINAPI IoBuildDeviceIoControlRequest( ULONG IoControlCode,
     if (instance == NULL)
         goto err;
     instance->irp = irp;
+    EnterCriticalSection( &cs );
     list_add_tail( &Irps, &instance->entry );
+    LeaveCriticalSection( &cs );
 
     return irp;
 err:
@@ -1085,7 +1109,9 @@ NTSTATUS WINAPI IoRegisterDeviceInterface( PDEVICE_OBJECT PhysicalDeviceObject,
                     if (SetupDiCreateDeviceInterfaceW( set, &devInfo,
                             InterfaceClassGuid, NULL, 0, NULL ))
                     {
+                        EnterCriticalSection( &cs );
                         list_add_tail( &Interfaces, &interf->entry );
+                        LeaveCriticalSection( &cs );
                         status = STATUS_SUCCESS;
                     }
                     else
@@ -1151,14 +1177,20 @@ NTSTATUS WINAPI IoSetDeviceInterfaceState( PUNICODE_STRING SymbolicLinkName,
     if (Enable)
     {
         struct InterfaceInstance *interf;
+        NTSTATUS status = STATUS_OBJECT_NAME_NOT_FOUND;
 
+        EnterCriticalSection( &cs );
         LIST_FOR_EACH_ENTRY( interf, &Interfaces, struct InterfaceInstance, entry )
         {
             if (!strncmpW( SymbolicLinkName->Buffer, interf->link,
                 SymbolicLinkName->Length ))
-                return IoCreateSymbolicLink( SymbolicLinkName, interf->target );
+            {
+                status = IoCreateSymbolicLink( SymbolicLinkName, interf->target );
+                break;
+            }
         }
-        return STATUS_OBJECT_NAME_NOT_FOUND;
+        LeaveCriticalSection( &cs );
+        return status;
     }
     else
     {
@@ -1307,6 +1339,7 @@ void CDECL wine_complete_request( IRP *irp, UCHAR priority_boost )
         iosb->u.Status = irp->IoStatus.u.Status;
         iosb->Information = irp->IoStatus.Information;
     }
+    EnterCriticalSection( &cs );
     LIST_FOR_EACH_ENTRY( instance, &Irps, struct IrpInstance, entry )
     {
         if (instance->irp == irp)
@@ -1327,6 +1360,7 @@ void CDECL wine_complete_request( IRP *irp, UCHAR priority_boost )
             break;
         }
     }
+    LeaveCriticalSection( &cs );
 }
 
 
@@ -1954,8 +1988,10 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
         DisableThreadLibraryCalls( inst );
         vectored_handler_added = RtlAddVectoredExceptionHandler( TRUE, vectored_handler );
         KeQueryTickCount( &count );  /* initialize the global KeTickCount */
+        InitializeCriticalSection( &cs );
         break;
     case DLL_PROCESS_DETACH:
+        DeleteCriticalSection( &cs );
         RtlRemoveVectoredExceptionHandler(vectored_handler_added);
         LIST_FOR_EACH_ENTRY_SAFE( ext, ext2, &DriverObjExtensions,
                 struct DriverObjExtension, entry )
-- 
1.6.0.2.GIT



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