Revert "ntdll: Fix possible deadlock in vectored exception handling."
authorAlexandre Julliard <julliard@winehq.org>
Wed, 10 Nov 2010 18:17:41 +0000 (19:17 +0100)
committerAlexandre Julliard <julliard@winehq.org>
Wed, 10 Nov 2010 18:17:41 +0000 (19:17 +0100)
This reverts commit eb0e82a75568db095df5f78be703987147f00f66.
It's causing different deadlocks, notably when a thread tries to
remove a handler inside a handler.

dlls/ntdll/exception.c
dlls/ntdll/ntdll_misc.h
dlls/ntdll/thread.c

index 4d2f759c5e14bd99cec4d55874d2d268d2b726f1..63fd281b4b578b71a53bdc63524b1e18dea0c7e7 100644 (file)
@@ -48,17 +48,14 @@ typedef struct
 
 static struct list vectored_handlers = LIST_INIT(vectored_handlers);
 
-static RTL_RWLOCK vectored_handlers_lock;
-
-/**********************************************************************
- *           exceptions_init
- *
- * Initialize read/write lock used by the vectored exception handling.
- */
-void exceptions_init(void)
+static RTL_CRITICAL_SECTION vectored_handlers_section;
+static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
 {
-    RtlInitializeResource(&vectored_handlers_lock);
-}
+    0, 0, &vectored_handlers_section,
+    { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
+      0, 0, { (DWORD_PTR)(__FILE__ ": vectored_handlers_section") }
+};
+static RTL_CRITICAL_SECTION vectored_handlers_section = { &critsect_debug, -1, 0, 0, 0, 0 };
 
 /**********************************************************************
  *           wait_suspend
@@ -165,7 +162,7 @@ LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
     except_ptrs.ExceptionRecord = rec;
     except_ptrs.ContextRecord = context;
 
-    RtlAcquireResourceShared( &vectored_handlers_lock, TRUE );
+    RtlEnterCriticalSection( &vectored_handlers_section );
     LIST_FOR_EACH( ptr, &vectored_handlers )
     {
         VECTORED_HANDLER *handler = LIST_ENTRY( ptr, VECTORED_HANDLER, entry );
@@ -175,7 +172,7 @@ LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
         TRACE( "handler at %p returned %x\n", handler->func, ret );
         if (ret == EXCEPTION_CONTINUE_EXECUTION) break;
     }
-    RtlReleaseResource( &vectored_handlers_lock );
+    RtlLeaveCriticalSection( &vectored_handlers_section );
     return ret;
 }
 
@@ -217,10 +214,10 @@ PVOID WINAPI RtlAddVectoredExceptionHandler( ULONG first, PVECTORED_EXCEPTION_HA
     if (handler)
     {
         handler->func = func;
-        RtlAcquireResourceExclusive( &vectored_handlers_lock, TRUE );
+        RtlEnterCriticalSection( &vectored_handlers_section );
         if (first) list_add_head( &vectored_handlers, &handler->entry );
         else list_add_tail( &vectored_handlers, &handler->entry );
-        RtlReleaseResource( &vectored_handlers_lock );
+        RtlLeaveCriticalSection( &vectored_handlers_section );
     }
     return handler;
 }
@@ -234,7 +231,7 @@ ULONG WINAPI RtlRemoveVectoredExceptionHandler( PVOID handler )
     struct list *ptr;
     ULONG ret = FALSE;
 
-    RtlAcquireResourceExclusive( &vectored_handlers_lock, TRUE );
+    RtlEnterCriticalSection( &vectored_handlers_section );
     LIST_FOR_EACH( ptr, &vectored_handlers )
     {
         VECTORED_HANDLER *curr_handler = LIST_ENTRY( ptr, VECTORED_HANDLER, entry );
@@ -245,7 +242,7 @@ ULONG WINAPI RtlRemoveVectoredExceptionHandler( PVOID handler )
             break;
         }
     }
-    RtlReleaseResource( &vectored_handlers_lock );
+    RtlLeaveCriticalSection( &vectored_handlers_section );
     if (ret) RtlFreeHeap( GetProcessHeap(), 0, handler );
     return ret;
 }
index 3c35251977dea8b7dbb5e36b9c6ded80562a5c3b..212edf5b30e31738d21d63a3b60ae9263cbb438e 100644 (file)
@@ -71,7 +71,6 @@ extern void virtual_init(void);
 extern void virtual_init_threading(void);
 extern void fill_cpu_info(void);
 extern void heap_set_debug_flags( HANDLE handle );
-extern void exceptions_init(void);
 
 /* server support */
 extern timeout_t server_start_time;
index fb6b2d20c388bfa06566300816ea644270293f15..56eca23c8af87093266e55b5340b6b5aa60df53c 100644 (file)
@@ -296,7 +296,6 @@ HANDLE thread_init(void)
     user_shared_data->TickCountMultiplier = 1 << 24;
 
     fill_cpu_info();
-    exceptions_init();
 
     return exe_file;
 }