Author: tkreuzer Date: Mon Jul 25 21:06:44 2011 New Revision: 52875
URL: http://svn.reactos.org/svn/reactos?rev=52875&view=rev Log: [NTOSKRNL] Fix bugs in ExInterlocked functions.
Modified: trunk/reactos/ntoskrnl/ex/i386/interlocked.c
Modified: trunk/reactos/ntoskrnl/ex/i386/interlocked.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/i386/interlocke... ============================================================================== --- trunk/reactos/ntoskrnl/ex/i386/interlocked.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ex/i386/interlocked.c [iso-8859-1] Mon Jul 25 21:06:44 2011 @@ -85,7 +85,7 @@ /* Release the spinlock and restore interrupts */ _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle);
- /* return the old value */ + /* Return the old value */ return OldValue; }
@@ -111,7 +111,7 @@ /* Release the spinlock and restore interrupts */ _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle);
- /* return the old value */ + /* Return the old value */ return OldValue; }
@@ -137,8 +137,8 @@ /* Release the spinlock and restore interrupts */ _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle);
- /* return the first entry */ - return FirstEntry; + /* Return the old first entry or NULL for empty list */ + return (FirstEntry == ListHead) ? NULL : FirstEntry; }
PLIST_ENTRY @@ -163,202 +163,13 @@ /* Release the spinlock and restore interrupts */ _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle);
- /* return the last entry */ - return LastEntry; + /* Return the old last entry or NULL for empty list */ + return (LastEntry == ListHead) ? NULL : LastEntry; }
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList( - IN OUT PLIST_ENTRY ListHead, - IN OUT PKSPIN_LOCK Lock) -{ - ULONG_PTR LockHandle; - PLIST_ENTRY ListEntry; - - /* Disable interrupts and acquire the spinlock */ - LockHandle = _ExiDisableInteruptsAndAcquireSpinlock(Lock); - - /* Remove the first entry from the list head */ - ListEntry = RemoveHeadList(ListHead); - - /* Release the spinlock and restore interrupts */ - _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle); - - /* return the entry */ - return ListEntry; -} - -PSINGLE_LIST_ENTRY -NTAPI -ExInterlockedPopEntryList( - IN OUT PSINGLE_LIST_ENTRY ListHead, - IN OUT PKSPIN_LOCK Lock) -{ - ULONG_PTR LockHandle; - PSINGLE_LIST_ENTRY ListEntry; - - /* Disable interrupts and acquire the spinlock */ - LockHandle = _ExiDisableInteruptsAndAcquireSpinlock(Lock); - - /* Pop the first entry from the list */ - ListEntry = PopEntryList(ListHead); - - /* Release the spinlock and restore interrupts */ - _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle); - - /* return the entry */ - return ListEntry; -} - -PSINGLE_LIST_ENTRY -NTAPI -ExInterlockedPushEntryList( - IN OUT PSINGLE_LIST_ENTRY ListHead, - IN OUT PSINGLE_LIST_ENTRY ListEntry, - IN OUT PKSPIN_LOCK Lock) -{ - ULONG_PTR LockHandle; - PSINGLE_LIST_ENTRY OldListEntry; - - /* Disable interrupts and acquire the spinlock */ - LockHandle = _ExiDisableInteruptsAndAcquireSpinlock(Lock); - - /* Save the old top entry */ - OldListEntry = ListHead->Next; - - /* Push a new entry on the list */ - PushEntryList(ListHead, ListEntry); - - /* Release the spinlock and restore interrupts */ - _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle); - - /* return the entry */ - return OldListEntry; -} - -INTERLOCKED_RESULT -NTAPI -ExInterlockedIncrementLong( - IN PLONG Addend, - IN PKSPIN_LOCK Lock) -{ - LONG Result; - - Result = _InterlockedIncrement(Addend); - return (Result < 0) ? ResultNegative : - (Result > 0) ? ResultPositive : - ResultZero; -} - -INTERLOCKED_RESULT -NTAPI -ExInterlockedDecrementLong( - IN PLONG Addend, - IN PKSPIN_LOCK Lock) -{ - LONG Result; - - Result = _InterlockedDecrement(Addend); - return (Result < 0) ? ResultNegative : - (Result > 0) ? ResultPositive : - ResultZero; -} - -ULONG -NTAPI -ExInterlockedExchangeUlong( - IN PULONG Target, - IN ULONG Value, - IN PKSPIN_LOCK Lock) -{ - return (ULONG)_InterlockedExchange((PLONG)Target, (LONG)Value); -} - -#ifdef _M_IX86 - -ULONG -FASTCALL -ExfInterlockedAddUlong( - IN OUT PULONG Addend, - IN ULONG Increment, - IN OUT PKSPIN_LOCK Lock) -{ - ULONG_PTR LockHandle; - ULONG OldValue; - - /* Disable interrupts and acquire the spinlock */ - LockHandle = _ExiDisableInteruptsAndAcquireSpinlock(Lock); - - /* Save the old value */ - OldValue = *Addend; - - /* Do the operation */ - *Addend += Increment; - - /* Release the spinlock and restore interrupts */ - _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle); - - /* return the old value */ - return OldValue; -} - -PLIST_ENTRY -FASTCALL -ExfInterlockedInsertHeadList( - IN OUT PLIST_ENTRY ListHead, - IN PLIST_ENTRY ListEntry, - IN OUT PKSPIN_LOCK Lock) -{ - ULONG_PTR LockHandle; - PLIST_ENTRY FirstEntry; - - /* Disable interrupts and acquire the spinlock */ - LockHandle = _ExiDisableInteruptsAndAcquireSpinlock(Lock); - - /* Save the first entry */ - FirstEntry = ListHead->Flink; - - /* Insert the new entry */ - InsertHeadList(ListHead, ListEntry); - - /* Release the spinlock and restore interrupts */ - _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle); - - /* return the first entry */ - return FirstEntry; -} - -PLIST_ENTRY -FASTCALL -ExfInterlockedInsertTailList( - IN OUT PLIST_ENTRY ListHead, - IN PLIST_ENTRY ListEntry, - IN OUT PKSPIN_LOCK Lock) -{ - ULONG_PTR LockHandle; - PLIST_ENTRY LastEntry; - - /* Disable interrupts and acquire the spinlock */ - LockHandle = _ExiDisableInteruptsAndAcquireSpinlock(Lock); - - /* Save the last entry */ - LastEntry = ListHead->Blink; - - /* Insert the new entry */ - InsertTailList(ListHead, ListEntry); - - /* Release the spinlock and restore interrupts */ - _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle); - - /* return the last entry */ - return LastEntry; -} - - -PLIST_ENTRY -FASTCALL -ExfInterlockedRemoveHeadList( IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock) { @@ -383,6 +194,204 @@ /* Release the spinlock and restore interrupts */ _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle);
+ /* Return the entry */ + return ListEntry; +} + +PSINGLE_LIST_ENTRY +NTAPI +ExInterlockedPopEntryList( + IN OUT PSINGLE_LIST_ENTRY ListHead, + IN OUT PKSPIN_LOCK Lock) +{ + ULONG_PTR LockHandle; + PSINGLE_LIST_ENTRY ListEntry; + + /* Disable interrupts and acquire the spinlock */ + LockHandle = _ExiDisableInteruptsAndAcquireSpinlock(Lock); + + /* Pop the first entry from the list */ + ListEntry = PopEntryList(ListHead); + + /* Release the spinlock and restore interrupts */ + _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle); + + /* Return the entry */ + return ListEntry; +} + +PSINGLE_LIST_ENTRY +NTAPI +ExInterlockedPushEntryList( + IN OUT PSINGLE_LIST_ENTRY ListHead, + IN OUT PSINGLE_LIST_ENTRY ListEntry, + IN OUT PKSPIN_LOCK Lock) +{ + ULONG_PTR LockHandle; + PSINGLE_LIST_ENTRY OldListEntry; + + /* Disable interrupts and acquire the spinlock */ + LockHandle = _ExiDisableInteruptsAndAcquireSpinlock(Lock); + + /* Save the old top entry */ + OldListEntry = ListHead->Next; + + /* Push a new entry on the list */ + PushEntryList(ListHead, ListEntry); + + /* Release the spinlock and restore interrupts */ + _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle); + + /* Return the entry */ + return OldListEntry; +} + +INTERLOCKED_RESULT +NTAPI +ExInterlockedIncrementLong( + IN PLONG Addend, + IN PKSPIN_LOCK Lock) +{ + LONG Result; + + Result = _InterlockedIncrement(Addend); + return (Result < 0) ? ResultNegative : + (Result > 0) ? ResultPositive : + ResultZero; +} + +INTERLOCKED_RESULT +NTAPI +ExInterlockedDecrementLong( + IN PLONG Addend, + IN PKSPIN_LOCK Lock) +{ + LONG Result; + + Result = _InterlockedDecrement(Addend); + return (Result < 0) ? ResultNegative : + (Result > 0) ? ResultPositive : + ResultZero; +} + +ULONG +NTAPI +ExInterlockedExchangeUlong( + IN PULONG Target, + IN ULONG Value, + IN PKSPIN_LOCK Lock) +{ + return (ULONG)_InterlockedExchange((PLONG)Target, (LONG)Value); +} + +#ifdef _M_IX86 + +ULONG +FASTCALL +ExfInterlockedAddUlong( + IN OUT PULONG Addend, + IN ULONG Increment, + IN OUT PKSPIN_LOCK Lock) +{ + ULONG_PTR LockHandle; + ULONG OldValue; + + /* Disable interrupts and acquire the spinlock */ + LockHandle = _ExiDisableInteruptsAndAcquireSpinlock(Lock); + + /* Save the old value */ + OldValue = *Addend; + + /* Do the operation */ + *Addend += Increment; + + /* Release the spinlock and restore interrupts */ + _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle); + + /* Return the old value */ + return OldValue; +} + +PLIST_ENTRY +FASTCALL +ExfInterlockedInsertHeadList( + IN OUT PLIST_ENTRY ListHead, + IN PLIST_ENTRY ListEntry, + IN OUT PKSPIN_LOCK Lock) +{ + ULONG_PTR LockHandle; + PLIST_ENTRY FirstEntry; + + /* Disable interrupts and acquire the spinlock */ + LockHandle = _ExiDisableInteruptsAndAcquireSpinlock(Lock); + + /* Save the first entry */ + FirstEntry = ListHead->Flink; + + /* Insert the new entry */ + InsertHeadList(ListHead, ListEntry); + + /* Release the spinlock and restore interrupts */ + _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle); + + /* Return the old first entry or NULL for empty list */ + return (FirstEntry == ListHead) ? NULL : FirstEntry; +} + +PLIST_ENTRY +FASTCALL +ExfInterlockedInsertTailList( + IN OUT PLIST_ENTRY ListHead, + IN PLIST_ENTRY ListEntry, + IN OUT PKSPIN_LOCK Lock) +{ + ULONG_PTR LockHandle; + PLIST_ENTRY LastEntry; + + /* Disable interrupts and acquire the spinlock */ + LockHandle = _ExiDisableInteruptsAndAcquireSpinlock(Lock); + + /* Save the last entry */ + LastEntry = ListHead->Blink; + + /* Insert the new entry */ + InsertTailList(ListHead, ListEntry); + + /* Release the spinlock and restore interrupts */ + _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle); + + /* Return the old last entry or NULL for empty list */ + return (LastEntry == ListHead) ? NULL : LastEntry; +} + + +PLIST_ENTRY +FASTCALL +ExfInterlockedRemoveHeadList( + IN OUT PLIST_ENTRY ListHead, + IN OUT PKSPIN_LOCK Lock) +{ + ULONG_PTR LockHandle; + PLIST_ENTRY ListEntry; + + /* Disable interrupts and acquire the spinlock */ + LockHandle = _ExiDisableInteruptsAndAcquireSpinlock(Lock); + + /* Check if the list is empty */ + if (IsListEmpty(ListHead)) + { + /* Return NULL */ + ListEntry = NULL; + } + else + { + /* Remove the first entry from the list head */ + ListEntry = RemoveHeadList(ListHead); + } + + /* Release the spinlock and restore interrupts */ + _ExiReleaseSpinLockAndRestoreInterupts(Lock, LockHandle); + /* return the entry */ return ListEntry; }