mirror of
https://github.com/reactos/reactos.git
synced 2025-06-22 10:10:16 +00:00
[NTOSKRNL]
Make definitions of ExpChangeRundown, ExpChangePushlock and ExpSetRundown 64 bit safe (have one portable definition and use it accordingly) svn path=/trunk/; revision=50152
This commit is contained in:
parent
0093430c81
commit
e8fc5482a0
2 changed files with 46 additions and 52 deletions
|
@ -145,7 +145,7 @@ ExfReInitializeRundownProtection(IN PEX_RUNDOWN_REF RunRef)
|
||||||
ASSERT((RunRef->Count & EX_RUNDOWN_ACTIVE) != 0);
|
ASSERT((RunRef->Count & EX_RUNDOWN_ACTIVE) != 0);
|
||||||
|
|
||||||
/* Reset the count */
|
/* Reset the count */
|
||||||
ExpSetRundown(&RunRef->Count, 0);
|
ExpSetRundown(RunRef, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*++
|
/*++
|
||||||
|
@ -173,7 +173,7 @@ ExfRundownCompleted(IN PEX_RUNDOWN_REF RunRef)
|
||||||
ASSERT((RunRef->Count & EX_RUNDOWN_ACTIVE) != 0);
|
ASSERT((RunRef->Count & EX_RUNDOWN_ACTIVE) != 0);
|
||||||
|
|
||||||
/* Mark the counter as active */
|
/* Mark the counter as active */
|
||||||
ExpSetRundown(&RunRef->Count, EX_RUNDOWN_ACTIVE);
|
ExpSetRundown(RunRef, EX_RUNDOWN_ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*++
|
/*++
|
||||||
|
@ -359,7 +359,7 @@ ExfWaitForRundownProtectionRelease(IN PEX_RUNDOWN_REF RunRef)
|
||||||
WaitBlock.Count = Count;
|
WaitBlock.Count = Count;
|
||||||
|
|
||||||
/* Now set the pointer */
|
/* Now set the pointer */
|
||||||
NewValue = ExpChangeRundown(RunRef, PtrToUlong(WaitBlockPointer), Value);
|
NewValue = ExpChangeRundown(RunRef, (ULONG_PTR)WaitBlockPointer, Value);
|
||||||
if (NewValue == Value) break;
|
if (NewValue == Value) break;
|
||||||
|
|
||||||
/* Loop again */
|
/* Loop again */
|
||||||
|
|
|
@ -95,7 +95,7 @@ typedef struct
|
||||||
// Detect old GCC
|
// Detect old GCC
|
||||||
//
|
//
|
||||||
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40300) || \
|
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40300) || \
|
||||||
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ == 40303)
|
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ == 40303)
|
||||||
|
|
||||||
#define DEFINE_WAIT_BLOCK(x) \
|
#define DEFINE_WAIT_BLOCK(x) \
|
||||||
struct _AlignHack \
|
struct _AlignHack \
|
||||||
|
@ -119,15 +119,9 @@ typedef struct
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN64
|
#define ExpChangeRundown(x, y, z) (ULONG_PTR)InterlockedCompareExchangePointer(&x->Ptr, (PVOID)y, (PVOID)z)
|
||||||
#define ExpChangeRundown(x, y, z) InterlockedCompareExchange64((PLONGLONG)x, y, z)
|
|
||||||
#define ExpChangePushlock(x, y, z) InterlockedCompareExchangePointer((PVOID*)x, (PVOID)y, (PVOID)z)
|
#define ExpChangePushlock(x, y, z) InterlockedCompareExchangePointer((PVOID*)x, (PVOID)y, (PVOID)z)
|
||||||
#define ExpSetRundown(x, y) InterlockedExchange64((PLONGLONG)x, y)
|
#define ExpSetRundown(x, y) InterlockedExchangePointer(&x->Ptr, (PVOID)y)
|
||||||
#else
|
|
||||||
#define ExpChangeRundown(x, y, z) PtrToUlong(InterlockedCompareExchange((PLONG)x, PtrToLong(y), PtrToLong(z)))
|
|
||||||
#define ExpChangePushlock(x, y, z) LongToPtr(InterlockedCompareExchange((PLONG)x, PtrToLong(y), PtrToLong(z)))
|
|
||||||
#define ExpSetRundown(x, y) InterlockedExchange((PLONG)x, y)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* INITIALIZATION FUNCTIONS *************************************************/
|
/* INITIALIZATION FUNCTIONS *************************************************/
|
||||||
|
|
||||||
|
@ -496,7 +490,7 @@ ExInitializeFastReference(OUT PEX_FAST_REF FastRef,
|
||||||
{
|
{
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
ASSERT((((ULONG_PTR)Object) & MAX_FAST_REFS) == 0);
|
ASSERT((((ULONG_PTR)Object) & MAX_FAST_REFS) == 0);
|
||||||
|
|
||||||
/* Check if an object is being set */
|
/* Check if an object is being set */
|
||||||
if (!Object)
|
if (!Object)
|
||||||
{
|
{
|
||||||
|
@ -515,7 +509,7 @@ EX_FAST_REF
|
||||||
ExAcquireFastReference(IN OUT PEX_FAST_REF FastRef)
|
ExAcquireFastReference(IN OUT PEX_FAST_REF FastRef)
|
||||||
{
|
{
|
||||||
EX_FAST_REF OldValue, NewValue;
|
EX_FAST_REF OldValue, NewValue;
|
||||||
|
|
||||||
/* Start reference loop */
|
/* Start reference loop */
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
@ -530,11 +524,11 @@ ExAcquireFastReference(IN OUT PEX_FAST_REF FastRef)
|
||||||
OldValue.Object);
|
OldValue.Object);
|
||||||
if (NewValue.Object != OldValue.Object) continue;
|
if (NewValue.Object != OldValue.Object) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We are done */
|
/* We are done */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the old value */
|
/* Return the old value */
|
||||||
return OldValue;
|
return OldValue;
|
||||||
}
|
}
|
||||||
|
@ -545,16 +539,16 @@ ExInsertFastReference(IN OUT PEX_FAST_REF FastRef,
|
||||||
IN PVOID Object)
|
IN PVOID Object)
|
||||||
{
|
{
|
||||||
EX_FAST_REF OldValue, NewValue;
|
EX_FAST_REF OldValue, NewValue;
|
||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
ASSERT(!(((ULONG_PTR)Object) & MAX_FAST_REFS));
|
ASSERT(!(((ULONG_PTR)Object) & MAX_FAST_REFS));
|
||||||
|
|
||||||
/* Start update loop */
|
/* Start update loop */
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
/* Get the current reference count */
|
/* Get the current reference count */
|
||||||
OldValue = *FastRef;
|
OldValue = *FastRef;
|
||||||
|
|
||||||
/* Check if the current count is too high or if the pointer changed */
|
/* Check if the current count is too high or if the pointer changed */
|
||||||
if (((OldValue.RefCnt + MAX_FAST_REFS) > MAX_FAST_REFS) ||
|
if (((OldValue.RefCnt + MAX_FAST_REFS) > MAX_FAST_REFS) ||
|
||||||
((OldValue.Value &~ MAX_FAST_REFS) != (ULONG_PTR)Object))
|
((OldValue.Value &~ MAX_FAST_REFS) != (ULONG_PTR)Object))
|
||||||
|
@ -562,20 +556,20 @@ ExInsertFastReference(IN OUT PEX_FAST_REF FastRef,
|
||||||
/* Fail */
|
/* Fail */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the reference count */
|
/* Update the reference count */
|
||||||
NewValue.Value = OldValue.Value + MAX_FAST_REFS;
|
NewValue.Value = OldValue.Value + MAX_FAST_REFS;
|
||||||
NewValue.Object = ExpChangePushlock(&FastRef->Object,
|
NewValue.Object = ExpChangePushlock(&FastRef->Object,
|
||||||
NewValue.Object,
|
NewValue.Object,
|
||||||
OldValue.Object);
|
OldValue.Object);
|
||||||
if (NewValue.Object != OldValue.Object) continue;
|
if (NewValue.Object != OldValue.Object) continue;
|
||||||
|
|
||||||
/* We are done */
|
/* We are done */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return success */
|
/* Return success */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCEINLINE
|
FORCEINLINE
|
||||||
|
@ -584,31 +578,31 @@ ExReleaseFastReference(IN PEX_FAST_REF FastRef,
|
||||||
IN PVOID Object)
|
IN PVOID Object)
|
||||||
{
|
{
|
||||||
EX_FAST_REF OldValue, NewValue;
|
EX_FAST_REF OldValue, NewValue;
|
||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
ASSERT(Object != NULL);
|
ASSERT(Object != NULL);
|
||||||
ASSERT(!(((ULONG_PTR)Object) & MAX_FAST_REFS));
|
ASSERT(!(((ULONG_PTR)Object) & MAX_FAST_REFS));
|
||||||
|
|
||||||
/* Start reference loop */
|
/* Start reference loop */
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
/* Get the current reference count */
|
/* Get the current reference count */
|
||||||
OldValue = *FastRef;
|
OldValue = *FastRef;
|
||||||
|
|
||||||
/* Check if we're full if if the pointer changed */
|
/* Check if we're full if if the pointer changed */
|
||||||
if ((OldValue.Value ^ (ULONG_PTR)Object) >= MAX_FAST_REFS) return FALSE;
|
if ((OldValue.Value ^ (ULONG_PTR)Object) >= MAX_FAST_REFS) return FALSE;
|
||||||
|
|
||||||
/* Decrease the reference count */
|
/* Decrease the reference count */
|
||||||
NewValue.Value = OldValue.Value + 1;
|
NewValue.Value = OldValue.Value + 1;
|
||||||
NewValue.Object = ExpChangePushlock(&FastRef->Object,
|
NewValue.Object = ExpChangePushlock(&FastRef->Object,
|
||||||
NewValue.Object,
|
NewValue.Object,
|
||||||
OldValue.Object);
|
OldValue.Object);
|
||||||
if (NewValue.Object != OldValue.Object) continue;
|
if (NewValue.Object != OldValue.Object) continue;
|
||||||
|
|
||||||
/* We are done */
|
/* We are done */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return success */
|
/* Return success */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -619,10 +613,10 @@ ExSwapFastReference(IN PEX_FAST_REF FastRef,
|
||||||
IN PVOID Object)
|
IN PVOID Object)
|
||||||
{
|
{
|
||||||
EX_FAST_REF NewValue, OldValue;
|
EX_FAST_REF NewValue, OldValue;
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
ASSERT((((ULONG_PTR)Object) & MAX_FAST_REFS) == 0);
|
ASSERT((((ULONG_PTR)Object) & MAX_FAST_REFS) == 0);
|
||||||
|
|
||||||
/* Check if an object is being set */
|
/* Check if an object is being set */
|
||||||
if (!Object)
|
if (!Object)
|
||||||
{
|
{
|
||||||
|
@ -634,7 +628,7 @@ ExSwapFastReference(IN PEX_FAST_REF FastRef,
|
||||||
/* Otherwise, we assume the object was referenced and is ready */
|
/* Otherwise, we assume the object was referenced and is ready */
|
||||||
NewValue.Value = (ULONG_PTR)Object | MAX_FAST_REFS;
|
NewValue.Value = (ULONG_PTR)Object | MAX_FAST_REFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the object */
|
/* Update the object */
|
||||||
OldValue.Object = InterlockedExchangePointer(&FastRef->Object, NewValue.Object);
|
OldValue.Object = InterlockedExchangePointer(&FastRef->Object, NewValue.Object);
|
||||||
return OldValue;
|
return OldValue;
|
||||||
|
@ -647,17 +641,17 @@ ExCompareSwapFastReference(IN PEX_FAST_REF FastRef,
|
||||||
IN PVOID OldObject)
|
IN PVOID OldObject)
|
||||||
{
|
{
|
||||||
EX_FAST_REF OldValue, NewValue;
|
EX_FAST_REF OldValue, NewValue;
|
||||||
|
|
||||||
/* Sanity check and start swap loop */
|
/* Sanity check and start swap loop */
|
||||||
ASSERT(!(((ULONG_PTR)Object) & MAX_FAST_REFS));
|
ASSERT(!(((ULONG_PTR)Object) & MAX_FAST_REFS));
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
/* Get the current value */
|
/* Get the current value */
|
||||||
OldValue = *FastRef;
|
OldValue = *FastRef;
|
||||||
|
|
||||||
/* Make sure there's enough references to swap */
|
/* Make sure there's enough references to swap */
|
||||||
if (!((OldValue.Value ^ (ULONG_PTR)OldObject) <= MAX_FAST_REFS)) break;
|
if (!((OldValue.Value ^ (ULONG_PTR)OldObject) <= MAX_FAST_REFS)) break;
|
||||||
|
|
||||||
/* Check if we have an object to swap */
|
/* Check if we have an object to swap */
|
||||||
if (Object)
|
if (Object)
|
||||||
{
|
{
|
||||||
|
@ -669,17 +663,17 @@ ExCompareSwapFastReference(IN PEX_FAST_REF FastRef,
|
||||||
/* Write the object address itself (which is empty) */
|
/* Write the object address itself (which is empty) */
|
||||||
NewValue.Value = (ULONG_PTR)Object;
|
NewValue.Value = (ULONG_PTR)Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do the actual compare exchange */
|
/* Do the actual compare exchange */
|
||||||
NewValue.Object = ExpChangePushlock(&FastRef->Object,
|
NewValue.Object = ExpChangePushlock(&FastRef->Object,
|
||||||
NewValue.Object,
|
NewValue.Object,
|
||||||
OldValue.Object);
|
OldValue.Object);
|
||||||
if (NewValue.Object != OldValue.Object) continue;
|
if (NewValue.Object != OldValue.Object) continue;
|
||||||
|
|
||||||
/* All done */
|
/* All done */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the old value */
|
/* Return the old value */
|
||||||
return OldValue;
|
return OldValue;
|
||||||
}
|
}
|
||||||
|
@ -849,7 +843,7 @@ _ExRundownCompleted(IN PEX_RUNDOWN_REF RunRef)
|
||||||
ASSERT((RunRef->Count & EX_RUNDOWN_ACTIVE) != 0);
|
ASSERT((RunRef->Count & EX_RUNDOWN_ACTIVE) != 0);
|
||||||
|
|
||||||
/* Mark the counter as active */
|
/* Mark the counter as active */
|
||||||
ExpSetRundown(&RunRef->Count, EX_RUNDOWN_ACTIVE);
|
ExpSetRundown(RunRef, EX_RUNDOWN_ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PUSHLOCKS *****************************************************************/
|
/* PUSHLOCKS *****************************************************************/
|
||||||
|
@ -1221,21 +1215,21 @@ VOID
|
||||||
_ExAcquireFastMutexUnsafe(IN PFAST_MUTEX FastMutex)
|
_ExAcquireFastMutexUnsafe(IN PFAST_MUTEX FastMutex)
|
||||||
{
|
{
|
||||||
PKTHREAD Thread = KeGetCurrentThread();
|
PKTHREAD Thread = KeGetCurrentThread();
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
ASSERT((KeGetCurrentIrql() == APC_LEVEL) ||
|
ASSERT((KeGetCurrentIrql() == APC_LEVEL) ||
|
||||||
(Thread->CombinedApcDisable != 0) ||
|
(Thread->CombinedApcDisable != 0) ||
|
||||||
(Thread->Teb == NULL) ||
|
(Thread->Teb == NULL) ||
|
||||||
(Thread->Teb >= (PTEB)MM_SYSTEM_RANGE_START));
|
(Thread->Teb >= (PTEB)MM_SYSTEM_RANGE_START));
|
||||||
ASSERT(FastMutex->Owner != Thread);
|
ASSERT(FastMutex->Owner != Thread);
|
||||||
|
|
||||||
/* Decrease the count */
|
/* Decrease the count */
|
||||||
if (InterlockedDecrement(&FastMutex->Count))
|
if (InterlockedDecrement(&FastMutex->Count))
|
||||||
{
|
{
|
||||||
/* Someone is still holding it, use slow path */
|
/* Someone is still holding it, use slow path */
|
||||||
KiAcquireFastMutex(FastMutex);
|
KiAcquireFastMutex(FastMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the owner */
|
/* Set the owner */
|
||||||
FastMutex->Owner = Thread;
|
FastMutex->Owner = Thread;
|
||||||
}
|
}
|
||||||
|
@ -1249,10 +1243,10 @@ _ExReleaseFastMutexUnsafe(IN OUT PFAST_MUTEX FastMutex)
|
||||||
(KeGetCurrentThread()->Teb == NULL) ||
|
(KeGetCurrentThread()->Teb == NULL) ||
|
||||||
(KeGetCurrentThread()->Teb >= (PTEB)MM_SYSTEM_RANGE_START));
|
(KeGetCurrentThread()->Teb >= (PTEB)MM_SYSTEM_RANGE_START));
|
||||||
ASSERT(FastMutex->Owner == KeGetCurrentThread());
|
ASSERT(FastMutex->Owner == KeGetCurrentThread());
|
||||||
|
|
||||||
/* Erase the owner */
|
/* Erase the owner */
|
||||||
FastMutex->Owner = NULL;
|
FastMutex->Owner = NULL;
|
||||||
|
|
||||||
/* Increase the count */
|
/* Increase the count */
|
||||||
if (InterlockedIncrement(&FastMutex->Count) <= 0)
|
if (InterlockedIncrement(&FastMutex->Count) <= 0)
|
||||||
{
|
{
|
||||||
|
@ -1267,17 +1261,17 @@ _ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
|
||||||
{
|
{
|
||||||
KIRQL OldIrql;
|
KIRQL OldIrql;
|
||||||
ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
|
ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
|
||||||
|
|
||||||
/* Raise IRQL to APC */
|
/* Raise IRQL to APC */
|
||||||
KeRaiseIrql(APC_LEVEL, &OldIrql);
|
KeRaiseIrql(APC_LEVEL, &OldIrql);
|
||||||
|
|
||||||
/* Decrease the count */
|
/* Decrease the count */
|
||||||
if (InterlockedDecrement(&FastMutex->Count))
|
if (InterlockedDecrement(&FastMutex->Count))
|
||||||
{
|
{
|
||||||
/* Someone is still holding it, use slow path */
|
/* Someone is still holding it, use slow path */
|
||||||
KiAcquireFastMutex(FastMutex);
|
KiAcquireFastMutex(FastMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the owner and IRQL */
|
/* Set the owner and IRQL */
|
||||||
FastMutex->Owner = KeGetCurrentThread();
|
FastMutex->Owner = KeGetCurrentThread();
|
||||||
FastMutex->OldIrql = OldIrql;
|
FastMutex->OldIrql = OldIrql;
|
||||||
|
@ -1289,18 +1283,18 @@ _ExReleaseFastMutex(IN OUT PFAST_MUTEX FastMutex)
|
||||||
{
|
{
|
||||||
KIRQL OldIrql;
|
KIRQL OldIrql;
|
||||||
ASSERT(KeGetCurrentIrql() == APC_LEVEL);
|
ASSERT(KeGetCurrentIrql() == APC_LEVEL);
|
||||||
|
|
||||||
/* Erase the owner */
|
/* Erase the owner */
|
||||||
FastMutex->Owner = NULL;
|
FastMutex->Owner = NULL;
|
||||||
OldIrql = (KIRQL)FastMutex->OldIrql;
|
OldIrql = (KIRQL)FastMutex->OldIrql;
|
||||||
|
|
||||||
/* Increase the count */
|
/* Increase the count */
|
||||||
if (InterlockedIncrement(&FastMutex->Count) <= 0)
|
if (InterlockedIncrement(&FastMutex->Count) <= 0)
|
||||||
{
|
{
|
||||||
/* Someone was waiting for it, signal the waiter */
|
/* Someone was waiting for it, signal the waiter */
|
||||||
KeSetEventBoostPriority(&FastMutex->Event, NULL);
|
KeSetEventBoostPriority(&FastMutex->Event, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lower IRQL back */
|
/* Lower IRQL back */
|
||||||
KeLowerIrql(OldIrql);
|
KeLowerIrql(OldIrql);
|
||||||
}
|
}
|
||||||
|
@ -1311,10 +1305,10 @@ _ExTryToAcquireFastMutex(IN OUT PFAST_MUTEX FastMutex)
|
||||||
{
|
{
|
||||||
KIRQL OldIrql;
|
KIRQL OldIrql;
|
||||||
ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
|
ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
|
||||||
|
|
||||||
/* Raise to APC_LEVEL */
|
/* Raise to APC_LEVEL */
|
||||||
KeRaiseIrql(APC_LEVEL, &OldIrql);
|
KeRaiseIrql(APC_LEVEL, &OldIrql);
|
||||||
|
|
||||||
/* Check if we can quickly acquire it */
|
/* Check if we can quickly acquire it */
|
||||||
if (InterlockedCompareExchange(&FastMutex->Count, 0, 1) == 1)
|
if (InterlockedCompareExchange(&FastMutex->Count, 0, 1) == 1)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue