- Merge a couple of small bugfixes from 25461 (smss and csrss related)
authorAleksey Bragin <aleksey@reactos.org>
Wed, 24 Jan 2007 10:52:55 +0000 (10:52 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Wed, 24 Jan 2007 10:52:55 +0000 (10:52 +0000)
- Merge 25472

svn path=/branches/ros-branch-0_3_1/; revision=25612

reactos/base/system/smss/smapi.c
reactos/ntoskrnl/ex/handle.c
reactos/ntoskrnl/ex/rundown.c
reactos/ntoskrnl/include/internal/ex.h
reactos/subsystems/win32/csrss/api/wapi.c

index ecbf75a..aeafa51 100644 (file)
@@ -144,7 +144,7 @@ SmpApiConnectedThread(PVOID pConnectedPort)
                                break;
                        case LPC_PORT_CLOSED:
                              Reply = NULL;
                                break;
                        case LPC_PORT_CLOSED:
                              Reply = NULL;
-                             break;
+                             continue;
                        default:
                                if ((Request.SmHeader.ApiIndex) &&
                                        (Request.SmHeader.ApiIndex < (sizeof SmApi / sizeof SmApi[0])))
                        default:
                                if ((Request.SmHeader.ApiIndex) &&
                                        (Request.SmHeader.ApiIndex < (sizeof SmApi / sizeof SmApi[0])))
index 7cd9509..a595242 100644 (file)
@@ -866,8 +866,6 @@ ExDestroyHandleByEntry(IN PHANDLE_TABLE HandleTable,
 
   DPRINT("DestroyHandleByEntry HT:0x%p Entry:0x%p\n", HandleTable, Entry);
 
 
   DPRINT("DestroyHandleByEntry HT:0x%p Entry:0x%p\n", HandleTable, Entry);
 
-  if (!(HandleTable->Flags & EX_HANDLE_TABLE_CLOSING))
-  {
     KeEnterCriticalRegion();
     ExAcquireHandleLockExclusive(HandleTable);
 
     KeEnterCriticalRegion();
     ExAcquireHandleLockExclusive(HandleTable);
 
@@ -879,7 +877,6 @@ ExDestroyHandleByEntry(IN PHANDLE_TABLE HandleTable,
 
     ExReleaseHandleLock(HandleTable);
     KeLeaveCriticalRegion();
 
     ExReleaseHandleLock(HandleTable);
     KeLeaveCriticalRegion();
-  }
 }
 
 PHANDLE_TABLE_ENTRY
 }
 
 PHANDLE_TABLE_ENTRY
index 2fc1e5d..aa1ab24 100644 (file)
@@ -36,21 +36,21 @@ ExfAcquireRundownProtection(IN PEX_RUNDOWN_REF RunRef)
 {
     ULONG_PTR Value = RunRef->Count, NewValue;
 
 {
     ULONG_PTR Value = RunRef->Count, NewValue;
 
-    /* Make sure a rundown is not active */
-    if (Value & EX_RUNDOWN_ACTIVE) return FALSE;
-
     /* Loop until successfully incremented the counter */
     for (;;)
     {
     /* Loop until successfully incremented the counter */
     for (;;)
     {
+        /* Make sure a rundown is not active */
+        if (Value & EX_RUNDOWN_ACTIVE) return FALSE;
+
         /* Add a reference */
         NewValue = Value + EX_RUNDOWN_COUNT_INC;
 
         /* Change the value */
         /* Add a reference */
         NewValue = Value + EX_RUNDOWN_COUNT_INC;
 
         /* Change the value */
-        Value = ExpChangeRundown(RunRef, NewValue, Value);
-        if (Value == NewValue) return TRUE;
+        NewValue = ExpChangeRundown(RunRef, NewValue, Value);
+        if (NewValue == Value) return TRUE;
 
 
-        /* Make sure a rundown is not active */
-        if (Value & EX_RUNDOWN_ACTIVE) return FALSE;
+        /* Update it */
+        Value = NewValue;
     }
 }
 
     }
 }
 
@@ -79,24 +79,21 @@ ExfAcquireRundownProtectionEx(IN PEX_RUNDOWN_REF RunRef,
 {
     ULONG_PTR Value = RunRef->Count, NewValue;
 
 {
     ULONG_PTR Value = RunRef->Count, NewValue;
 
-    /* Make sure a rundown is not active */
-    if (Value & EX_RUNDOWN_ACTIVE) return FALSE;
-
-    /* Convert the count to our internal representation */
-    Count <<= EX_RUNDOWN_COUNT_SHIFT;
-
     /* Loop until successfully incremented the counter */
     for (;;)
     {
     /* Loop until successfully incremented the counter */
     for (;;)
     {
+        /* Make sure a rundown is not active */
+        if (Value & EX_RUNDOWN_ACTIVE) return FALSE;
+
         /* Add references */
         /* Add references */
-        NewValue = Value + Count;
+        NewValue = Value + EX_RUNDOWN_COUNT_INC * Count;
 
         /* Change the value */
 
         /* Change the value */
-        Value = ExpChangeRundown(RunRef, NewValue, Value);
-        if (Value == NewValue) return TRUE;
+        NewValue = ExpChangeRundown(RunRef, NewValue, Value);
+        if (NewValue == Value) return TRUE;
 
 
-        /* Make sure a rundown is not active */
-        if (Value & EX_RUNDOWN_ACTIVE) return FALSE;
+        /* Update the value */
+        Value = NewValue;
     }
 }
 
     }
 }
 
@@ -201,11 +198,11 @@ ExfReleaseRundownProtection(IN PEX_RUNDOWN_REF RunRef)
     ULONG_PTR Value = RunRef->Count, NewValue;
     PEX_RUNDOWN_WAIT_BLOCK WaitBlock;
 
     ULONG_PTR Value = RunRef->Count, NewValue;
     PEX_RUNDOWN_WAIT_BLOCK WaitBlock;
 
-    /* Check if rundown is not active */
-    if (!(Value & EX_RUNDOWN_ACTIVE))
+    /* Loop until successfully incremented the counter */
+    for (;;)
     {
     {
-        /* Loop until successfully incremented the counter */
-        for (;;)
+        /* Check if rundown is not active */
+        if (!(Value & EX_RUNDOWN_ACTIVE))
         {
             /* Sanity check */
             ASSERT((Value >= EX_RUNDOWN_COUNT_INC) || (KeNumberProcessors > 1));
         {
             /* Sanity check */
             ASSERT((Value >= EX_RUNDOWN_COUNT_INC) || (KeNumberProcessors > 1));
@@ -214,23 +211,28 @@ ExfReleaseRundownProtection(IN PEX_RUNDOWN_REF RunRef)
             NewValue = Value - EX_RUNDOWN_COUNT_INC;
 
             /* Change the value */
             NewValue = Value - EX_RUNDOWN_COUNT_INC;
 
             /* Change the value */
-            Value = ExpChangeRundown(RunRef, NewValue, Value);
-            if (Value == NewValue) return;
+            NewValue = ExpChangeRundown(RunRef, NewValue, Value);
+            if (NewValue == Value) break;
 
 
-            /* Loop again if we're still not active */
-            if (Value & EX_RUNDOWN_ACTIVE) break;
+            /* Update value */
+            Value = NewValue;
+        }
+        else
+        {
+            /* Get the wait block */
+            WaitBlock = (PEX_RUNDOWN_WAIT_BLOCK)(Value & ~EX_RUNDOWN_ACTIVE);
+            ASSERT((WaitBlock->Count > 0) || (KeNumberProcessors > 1));
+
+            /* Remove the one count */
+            if (!InterlockedDecrementSizeT(&WaitBlock->Count))
+            {
+                /* We're down to 0 now, so signal the event */
+                KeSetEvent(&WaitBlock->WakeEvent, IO_NO_INCREMENT, FALSE);
+            }
+
+            /* We're all done */
+            break;
         }
         }
-    }
-
-    /* Get the wait block */
-    WaitBlock = (PEX_RUNDOWN_WAIT_BLOCK)(Value & ~EX_RUNDOWN_ACTIVE);
-    ASSERT((WaitBlock->Count > 0) || (KeNumberProcessors > 1));
-
-    /* Remove the one count */
-    if (!InterlockedDecrementSizeT(&WaitBlock->Count))
-    {
-        /* We're down to 0 now, so signal the event */
-        KeSetEvent(&WaitBlock->WakeEvent, IO_NO_INCREMENT, FALSE);
     }
 }
 
     }
 }
 
@@ -260,37 +262,43 @@ ExfReleaseRundownProtectionEx(IN PEX_RUNDOWN_REF RunRef,
     ULONG_PTR Value = RunRef->Count, NewValue;
     PEX_RUNDOWN_WAIT_BLOCK WaitBlock;
 
     ULONG_PTR Value = RunRef->Count, NewValue;
     PEX_RUNDOWN_WAIT_BLOCK WaitBlock;
 
-    /* Check if rundown is not active */
-    if (!(Value & EX_RUNDOWN_ACTIVE))
+    /* Loop until successfully incremented the counter */
+    for (;;)
     {
     {
-        /* Loop until successfully incremented the counter */
-        for (;;)
+        /* Check if rundown is not active */
+        if (!(Value & EX_RUNDOWN_ACTIVE))
         {
             /* Sanity check */
         {
             /* Sanity check */
-            ASSERT((Value >= EX_RUNDOWN_COUNT_INC * Count) || (KeNumberProcessors > 1));
+            ASSERT((Value >= EX_RUNDOWN_COUNT_INC * Count) ||
+                   (KeNumberProcessors > 1));
 
             /* Get the new value */
 
             /* Get the new value */
-            NewValue = Value - (Count * EX_RUNDOWN_COUNT_INC);
+            NewValue = Value - EX_RUNDOWN_COUNT_INC * Count;
 
             /* Change the value */
 
             /* Change the value */
-            Value = ExpChangeRundown(RunRef, NewValue, Value);
-            if (Value == NewValue) return;
+            NewValue = ExpChangeRundown(RunRef, NewValue, Value);
+            if (NewValue == Value) break;
 
 
-            /* Loop again if we're still not active */
-            if (Value & EX_RUNDOWN_ACTIVE) break;
+            /* Update value */
+            Value = NewValue;
+        }
+        else
+        {
+            /* Get the wait block */
+            WaitBlock = (PEX_RUNDOWN_WAIT_BLOCK)(Value & ~EX_RUNDOWN_ACTIVE);
+            ASSERT((WaitBlock->Count >= Count) || (KeNumberProcessors > 1));
+
+            /* Remove the counts */
+            if (InterlockedExchangeAddSizeT(&WaitBlock->Count,
+                                            -(LONG)Count) == (LONG)Count)
+            {
+                /* We're down to 0 now, so signal the event */
+                KeSetEvent(&WaitBlock->WakeEvent, IO_NO_INCREMENT, FALSE);
+            }
+
+            /* We're all done */
+            break;
         }
         }
-    }
-
-    /* Get the wait block */
-    WaitBlock = (PEX_RUNDOWN_WAIT_BLOCK)(Value & ~EX_RUNDOWN_ACTIVE);
-    ASSERT((WaitBlock->Count >= Count) || (KeNumberProcessors > 1));
-
-    /* Remove the count */
-    if (InterlockedExchangeAddSizeT(&WaitBlock->Count, -(LONG)Count) ==
-        (LONG)Count)
-    {
-        /* We're down to 0 now, so signal the event */
-        KeSetEvent(&WaitBlock->WakeEvent, IO_NO_INCREMENT, FALSE);
     }
 }
 
     }
 }
 
@@ -330,17 +338,17 @@ ExfWaitForRundownProtectionRelease(IN PEX_RUNDOWN_REF RunRef)
                                                 EX_RUNDOWN_ACTIVE);
 
     /* Start waitblock set loop */
                                                 EX_RUNDOWN_ACTIVE);
 
     /* Start waitblock set loop */
-    for(;;)
+    for (;;)
     {
         /* Save the count */
         Count = Value >> EX_RUNDOWN_COUNT_SHIFT;
 
     {
         /* Save the count */
         Count = Value >> EX_RUNDOWN_COUNT_SHIFT;
 
-        /* If the count is over one or we don't have en event yet, create it */
-        if (Count || !Event)
+        /* If the count is over one and we don't have en event yet, create it */
+        if ((Count) && !(Event))
         {
             /* Initialize the event */
             KeInitializeEvent(&WaitBlock.WakeEvent,
         {
             /* Initialize the event */
             KeInitializeEvent(&WaitBlock.WakeEvent,
-                              NotificationEvent,
+                              SynchronizationEvent,
                               FALSE);
 
             /* Set the pointer */
                               FALSE);
 
             /* Set the pointer */
index 9869c18..a0ec15a 100644 (file)
@@ -351,7 +351,7 @@ BOOLEAN
 FORCEINLINE
 _ExAcquireRundownProtection(IN PEX_RUNDOWN_REF RunRef)
 {
 FORCEINLINE
 _ExAcquireRundownProtection(IN PEX_RUNDOWN_REF RunRef)
 {
-    ULONG_PTR Value, NewValue, OldValue;
+    ULONG_PTR Value, NewValue;
 
     /* Get the current value and mask the active bit */
     Value = RunRef->Count &~ EX_RUNDOWN_ACTIVE;
 
     /* Get the current value and mask the active bit */
     Value = RunRef->Count &~ EX_RUNDOWN_ACTIVE;
@@ -360,8 +360,8 @@ _ExAcquireRundownProtection(IN PEX_RUNDOWN_REF RunRef)
     NewValue = Value + EX_RUNDOWN_COUNT_INC;
 
     /* Change the value */
     NewValue = Value + EX_RUNDOWN_COUNT_INC;
 
     /* Change the value */
-    OldValue = ExpChangeRundown(RunRef, NewValue, Value);
-    if (OldValue != Value)
+    NewValue = ExpChangeRundown(RunRef, NewValue, Value);
+    if (NewValue != Value)
     {
         /* Rundown was active, use long path */
         return ExfAcquireRundownProtection(RunRef);
     {
         /* Rundown was active, use long path */
         return ExfAcquireRundownProtection(RunRef);
@@ -392,7 +392,7 @@ VOID
 FORCEINLINE
 _ExReleaseRundownProtection(IN PEX_RUNDOWN_REF RunRef)
 {
 FORCEINLINE
 _ExReleaseRundownProtection(IN PEX_RUNDOWN_REF RunRef)
 {
-    ULONG_PTR Value, NewValue, OldValue;
+    ULONG_PTR Value, NewValue;
 
     /* Get the current value and mask the active bit */
     Value = RunRef->Count &~ EX_RUNDOWN_ACTIVE;
 
     /* Get the current value and mask the active bit */
     Value = RunRef->Count &~ EX_RUNDOWN_ACTIVE;
@@ -401,10 +401,10 @@ _ExReleaseRundownProtection(IN PEX_RUNDOWN_REF RunRef)
     NewValue = Value - EX_RUNDOWN_COUNT_INC;
 
     /* Change the value */
     NewValue = Value - EX_RUNDOWN_COUNT_INC;
 
     /* Change the value */
-    OldValue = ExpChangeRundown(RunRef, NewValue, Value);
+    NewValue = ExpChangeRundown(RunRef, NewValue, Value);
 
     /* Check if the rundown was active */
 
     /* Check if the rundown was active */
-    if (OldValue != Value)
+    if (NewValue != Value)
     {
         /* Rundown was active, use long path */
         ExfReleaseRundownProtection(RunRef);
     {
         /* Rundown was active, use long path */
         ExfReleaseRundownProtection(RunRef);
@@ -463,7 +463,7 @@ _ExWaitForRundownProtectionRelease(IN PEX_RUNDOWN_REF RunRef)
 
     /* Set the active bit */
     Value = ExpChangeRundown(RunRef, EX_RUNDOWN_ACTIVE, 0);
 
     /* Set the active bit */
     Value = ExpChangeRundown(RunRef, EX_RUNDOWN_ACTIVE, 0);
-    if ((Value) || (Value != EX_RUNDOWN_ACTIVE))
+    if ((Value) && (Value != EX_RUNDOWN_ACTIVE))
     {
         /* If the the rundown wasn't already active, then take the long path */
         ExfWaitForRundownProtectionRelease(RunRef);
     {
         /* If the the rundown wasn't already active, then take the long path */
         ExfWaitForRundownProtectionRelease(RunRef);
index e725f16..582b971 100644 (file)
@@ -225,9 +225,12 @@ ClientConnectionThread(HANDLE ServerPort)
         /* If the connection was closed, handle that */
         if (Request->Header.u2.s2.Type == LPC_PORT_CLOSED)
         {
         /* If the connection was closed, handle that */
         if (Request->Header.u2.s2.Type == LPC_PORT_CLOSED)
         {
-            DPRINT1("Port died, oh well\n");
+            DPRINT("Port died, oh well\n");
             CsrFreeProcessData( Request->Header.ClientId.UniqueProcess );
             CsrFreeProcessData( Request->Header.ClientId.UniqueProcess );
-            break;
+            //NtClose();
+            Reply = NULL;
+            continue;
+            //break;
         }
 
         if (Request->Header.u2.s2.Type == LPC_CONNECTION_REQUEST)
         }
 
         if (Request->Header.u2.s2.Type == LPC_CONNECTION_REQUEST)
@@ -239,7 +242,7 @@ ClientConnectionThread(HANDLE ServerPort)
 
         if (Request->Header.u2.s2.Type == LPC_CLIENT_DIED)
         {
 
         if (Request->Header.u2.s2.Type == LPC_CLIENT_DIED)
         {
-            DPRINT1("Clietn died, oh well\n");
+            DPRINT("Client died, oh well\n");
             Reply = NULL;
             continue;
         }
             Reply = NULL;
             continue;
         }