- Fix trace macro to print line number in decimal, not hex.

- Implement PspSetCrossThreadFlag and PspClearCrossThreadFlag and use them. Thanks to Thomas for the idea.
- Fix a bug in Fast Referencing, thanks to Thomas.

svn path=/trunk/; revision=23260
This commit is contained in:
Alex Ionescu 2006-07-23 21:38:31 +00:00
parent 5cfb6a6d48
commit 9b5a87cdac
7 changed files with 24 additions and 21 deletions

View file

@ -49,7 +49,7 @@
#endif
#define PSREFTRACE(x) \
PSTRACE(PS_REF_DEBUG, \
"Pointer Count [%p] @%lx: %lx\n", \
"Pointer Count [%p] @%d: %lx\n", \
x, \
__LINE__, \
OBJECT_TO_OBJECT_HEADER(x)->PointerCount);

View file

@ -19,6 +19,14 @@
#define PspQuantumLengthFromMask(Mask) \
((Mask) & 48)
//
// Cross Thread Flag routines
//
#define PspSetCrossThreadFlag(Thread, Flag) \
InterlockedOr((PLONG)&Thread->CrossThreadFlags, Flag)
#define PspClearCrossThreadFlag(Thread, Flag) \
InterlockedAnd((PLONG)&Thread->CrossThreadFlags, ~Flag)
VOID
FORCEINLINE
PspRunCreateThreadNotifyRoutines(IN PETHREAD CurrentThread,

View file

@ -150,7 +150,7 @@ ObFastReferenceObject(IN PEX_FAST_REF FastRef)
{
/* Get the current count */
Value = FastRef->Value;
if (!Value & MAX_FAST_REFS) break;
if (!(Value & MAX_FAST_REFS)) break;
/* Increase the reference count */
NewValue = Value - 1;

View file

@ -905,7 +905,7 @@ PspTerminateThreadByPointer(IN PETHREAD Thread,
ASSERT_IRQL(PASSIVE_LEVEL);
/* Mark it as terminated */
InterlockedOr((PLONG)&Thread->CrossThreadFlags, CT_TERMINATED_BIT);
PspSetCrossThreadFlag(Thread, CT_TERMINATED_BIT);
/* Directly terminate the thread */
PspExitThread(ExitStatus);

View file

@ -17,7 +17,7 @@
#include "internal/ps_i.h"
/* Debugging Level */
ULONG PspTraceLevel = 0; //PS_KILL_DEBUG | PS_REF_DEBUG;
ULONG PspTraceLevel = PS_KILL_DEBUG | PS_REF_DEBUG;
/* PRIVATE FUNCTIONS *********************************************************/

View file

@ -51,8 +51,7 @@ PspDeleteThreadSecurity(IN PETHREAD Thread)
{
/* Free it */
ExFreePool(Thread->ImpersonationInfo);
InterlockedAnd((PLONG)&Thread->CrossThreadFlags,
~CT_ACTIVE_IMPERSONATION_INFO_BIT);
PspClearCrossThreadFlag(Thread, CT_ACTIVE_IMPERSONATION_INFO_BIT);
Thread->ImpersonationInfo = NULL;
}
}
@ -537,8 +536,7 @@ PsRevertThreadToSelf(IN PETHREAD Thread)
if (Thread->ActiveImpersonationInfo)
{
/* Disable impersonation */
InterlockedAnd((PLONG)&Thread->CrossThreadFlags,
~CT_ACTIVE_IMPERSONATION_INFO_BIT);
PspClearCrossThreadFlag(Thread, CT_ACTIVE_IMPERSONATION_INFO_BIT);
/* Get the token */
Token = Thread->ImpersonationInfo->Token;
@ -584,8 +582,8 @@ PsImpersonateClient(IN PETHREAD Thread,
if (Thread->ActiveImpersonationInfo)
{
/* Disable impersonation */
InterlockedAnd((PLONG)&Thread->CrossThreadFlags,
~CT_ACTIVE_IMPERSONATION_INFO_BIT);
PspClearCrossThreadFlag(Thread,
CT_ACTIVE_IMPERSONATION_INFO_BIT);
/* Get the token */
OldToken = Thread->ImpersonationInfo->Token;
@ -632,8 +630,7 @@ PsImpersonateClient(IN PETHREAD Thread,
else
{
/* Otherwise, enable impersonation */
InterlockedOr((PLONG)&Thread->CrossThreadFlags,
CT_ACTIVE_IMPERSONATION_INFO_BIT);
PspSetCrossThreadFlag(Thread, CT_ACTIVE_IMPERSONATION_INFO_BIT);
}
/* Now fill it out */
@ -880,14 +877,12 @@ PsRestoreImpersonation(IN PETHREAD Thread,
Impersonation->Token = ImpersonationState->Token;
/* Enable impersonation */
InterlockedOr((PLONG)&Thread->CrossThreadFlags,
CT_ACTIVE_IMPERSONATION_INFO_BIT);
PspSetCrossThreadFlag(Thread, CT_ACTIVE_IMPERSONATION_INFO_BIT);
}
else
{
/* Disable impersonation */
InterlockedAnd((PLONG)&Thread->CrossThreadFlags,
~CT_ACTIVE_IMPERSONATION_INFO_BIT);
PspClearCrossThreadFlag(Thread, CT_ACTIVE_IMPERSONATION_INFO_BIT);
}
/* Unlock the thread */

View file

@ -293,7 +293,7 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
{
/* System Thread */
Thread->StartAddress = StartRoutine;
InterlockedOr((PLONG)&Thread->CrossThreadFlags, CT_SYSTEM_THREAD_BIT);
PspSetCrossThreadFlag(Thread, CT_SYSTEM_THREAD_BIT);
/* Let the kernel intialize the Thread */
Status = KeInitThread(&Thread->Tcb,
@ -380,7 +380,7 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
if (!NT_SUCCESS(Status))
{
/* Access state failed, thread is dead */
InterlockedOr((PLONG)&Thread->CrossThreadFlags, CT_DEAD_THREAD_BIT);
PspSetCrossThreadFlag(Thread, CT_DEAD_THREAD_BIT);
/* If we were suspended, wake it up */
if (CreateSuspended) KeResumeThread(&Thread->Tcb);
@ -422,7 +422,7 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
Status = _SEH_GetExceptionCode();
/* Thread insertion failed, thread is dead */
InterlockedOr((PLONG)&Thread->CrossThreadFlags, CT_DEAD_THREAD_BIT);
PspSetCrossThreadFlag(Thread, CT_DEAD_THREAD_BIT);
/* If we were suspended, wake it up */
if (CreateSuspended) KeResumeThread(&Thread->Tcb);
@ -444,7 +444,7 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
else
{
/* Thread insertion failed, thread is dead */
InterlockedOr((PLONG)&Thread->CrossThreadFlags, CT_DEAD_THREAD_BIT);
PspSetCrossThreadFlag(Thread, CT_DEAD_THREAD_BIT);
/* If we were suspended, wake it up */
if (CreateSuspended) KeResumeThread(&Thread->Tcb);
@ -465,7 +465,7 @@ PspCreateThread(OUT PHANDLE ThreadHandle,
if (!NT_SUCCESS(Status))
{
/* Thread insertion failed, thread is dead */
InterlockedOr((PLONG)&Thread->CrossThreadFlags, CT_DEAD_THREAD_BIT);
PspSetCrossThreadFlag(Thread, CT_DEAD_THREAD_BIT);
/* If we were suspended, wake it up */
if (CreateSuspended) KeResumeThread(&Thread->Tcb);