- Heavy cleanup of locking and lookup macros in ob_x.h.

- Add calls to ObpInitializeDirectoryLookup where required.
- Fixup calls to ObpAcquireDirectoryLockExclusive, but still keep them stubbed out for now.

svn path=/trunk/; revision=25403
This commit is contained in:
Alex Ionescu 2007-01-09 21:48:26 +00:00
parent 9b6f258861
commit f9c3ffa9d1
6 changed files with 144 additions and 128 deletions

View file

@ -8,92 +8,12 @@
#include "ex.h"
#if DBG
VOID
FORCEINLINE
ObpCalloutStart(IN PKIRQL CalloutIrql)
{
/* Save the callout IRQL */
*CalloutIrql = KeGetCurrentIrql();
}
VOID
FORCEINLINE
ObpCalloutEnd(IN KIRQL CalloutIrql,
IN PCHAR Procedure,
IN POBJECT_TYPE ObjectType,
IN PVOID Object)
{
/* Detect IRQL change */
if (CalloutIrql != KeGetCurrentIrql())
{
/* Print error */
DbgPrint("OB: ObjectType: %wZ Procedure: %s Object: %08x\n",
&ObjectType->Name, Procedure, Object);
DbgPrint(" Returned at %x IRQL, but was called at %x IRQL\n",
KeGetCurrentIrql(), CalloutIrql);
DbgBreakPoint();
}
}
#else
VOID
FORCEINLINE
ObpCalloutStart(IN PKIRQL CalloutIrql)
{
/* No-op */
UNREFERENCED_PARAMETER(CalloutIrql);
}
VOID
FORCEINLINE
ObpCalloutEnd(IN KIRQL CalloutIrql,
IN PCHAR Procedure,
IN POBJECT_TYPE ObjectType,
IN PVOID Object)
{
UNREFERENCED_PARAMETER(CalloutIrql);
}
#endif
VOID
FORCEINLINE
_ObpAcquireDirectoryLockShared(IN POBJECT_DIRECTORY Directory,
IN POBP_LOOKUP_CONTEXT Context)
{
/* It's not, set lock flag */
Context->LockStateSignature = 0xBBBB1234;
/* Lock it */
KeEnterCriticalRegion();
ExAcquirePushLockShared(&Directory->Lock);
/* Update lock flag */
Context->LockStateSignature = 0xDDDD1234;
}
VOID
FORCEINLINE
_ObpAcquireDirectoryLockExclusive(IN POBJECT_DIRECTORY Directory,
IN POBP_LOOKUP_CONTEXT Context)
{
/* Update lock flag */
Context->LockStateSignature = 0xAAAA1234;
/* Lock it */
KeEnterCriticalRegion();
ExAcquirePushLockExclusive(&Directory->Lock);
}
VOID
FORCEINLINE
_ObpReleaseDirectoryLock(IN POBJECT_DIRECTORY Directory,
IN POBP_LOOKUP_CONTEXT Context)
{
/* Release the lock */
ExReleasePushLock(&Directory->Lock);
Context->LockStateSignature = 0xEEEE1234;
KeLeaveCriticalRegion();
}
#define OBP_LOCK_STATE_PRE_ACQUISITION_EXCLUSIVE 0xAAAA1234
#define OBP_LOCK_STATE_PRE_ACQUISITION_SHARED 0xBBBB1234
#define OBP_LOCK_STATE_POST_ACQUISITION_EXCLUSIVE 0xCCCC1234
#define OBP_LOCK_STATE_POST_ACQUISITION_SHARED 0xDDDD1234
#define OBP_LOCK_STATE_RELEASED 0xEEEE1234
#define OBP_LOCK_STATE_INITIALIZED 0xFFFF1234
ULONG
FORCEINLINE
@ -159,23 +79,69 @@ _ObpDecrementQueryReference(IN POBJECT_HEADER_NAME_INFO HeaderNameInfo)
VOID
FORCEINLINE
_ObpCleanupDirectoryLookup(IN POBP_LOOKUP_CONTEXT Context,
IN BOOLEAN DereferenceObject)
_ObpAcquireDirectoryLockShared(IN POBJECT_DIRECTORY Directory,
IN POBP_LOOKUP_CONTEXT Context)
{
/* It's not, set lock flag */
Context->LockStateSignature = OBP_LOCK_STATE_PRE_ACQUISITION_SHARED;
/* Lock it */
KeEnterCriticalRegion();
ExAcquirePushLockShared(&Directory->Lock);
/* Update lock flag */
Context->LockStateSignature = OBP_LOCK_STATE_POST_ACQUISITION_SHARED;
}
VOID
FORCEINLINE
_ObpAcquireDirectoryLockExclusive(IN POBJECT_DIRECTORY Directory,
IN POBP_LOOKUP_CONTEXT Context)
{
/* Update lock flag */
Context->LockStateSignature = OBP_LOCK_STATE_PRE_ACQUISITION_EXCLUSIVE;
/* Acquire an exclusive directory lock */
KeEnterCriticalRegion();
ExAcquirePushLockExclusive(&Directory->Lock);
/* Set the directory */
Context->Directory = Directory;
/* Update lock settings */
Context->LockStateSignature = OBP_LOCK_STATE_POST_ACQUISITION_EXCLUSIVE;
Context->DirectoryLocked = TRUE;
}
VOID
FORCEINLINE
_ObpReleaseDirectoryLock(IN POBJECT_DIRECTORY Directory,
IN POBP_LOOKUP_CONTEXT Context)
{
/* Release the lock */
ExReleasePushLock(&Directory->Lock);
Context->LockStateSignature = OBP_LOCK_STATE_RELEASED;
KeLeaveCriticalRegion();
}
VOID
FORCEINLINE
_ObpInitializeDirectoryLookup(IN POBP_LOOKUP_CONTEXT Context)
{
/* Initialize a null context */
Context->Object = NULL;
Context->Directory = NULL;
Context->DirectoryLocked = FALSE;
Context->LockStateSignature = OBP_LOCK_STATE_INITIALIZED;
}
VOID
FORCEINLINE
_ObpReleaseLookupContextObject(IN POBP_LOOKUP_CONTEXT Context)
{
POBJECT_HEADER ObjectHeader;
POBJECT_HEADER_NAME_INFO HeaderNameInfo;
/* Check if we came back with the directory locked */
if (Context->DirectoryLocked)
{
/* Release the lock */
_ObpReleaseDirectoryLock(Context->Directory, Context);
}
/* Clear the context */
Context->Directory = NULL;
Context->DirectoryLocked = FALSE;
/* Check if we had found an object */
if (Context->Object)
{
@ -186,20 +152,27 @@ _ObpCleanupDirectoryLookup(IN POBP_LOOKUP_CONTEXT Context,
/* Check if we do have name information */
if (HeaderNameInfo) _ObpDecrementQueryReference(HeaderNameInfo);
/* Check if we need to dereference it */
if (DereferenceObject) ObDereferenceObject(Context->Object);
/* Dereference the object */
ObDereferenceObject(Context->Object);
Context->Object = NULL;
}
}
VOID
FORCEINLINE
_ObpInitializeDirectoryLookup(IN POBP_LOOKUP_CONTEXT Context)
_ObpCleanupDirectoryLookup(IN POBP_LOOKUP_CONTEXT Context)
{
/* Initialize a null context */
Context->Object = NULL;
/* Check if we came back with the directory locked */
if (Context->DirectoryLocked)
{
/* Release the lock */
_ObpReleaseDirectoryLock(Context->Directory, Context);
}
/* Clear the context */
Context->Directory = NULL;
Context->DirectoryLocked = FALSE;
Context->LockStateSignature = 0xFFFF1234;
_ObpReleaseLookupContextObject(Context);
}
#if _OB_DEBUG_
@ -365,5 +338,49 @@ ObpFreeAndReleaseCapturedAttributes(IN POBJECT_CREATE_INFORMATION ObjectCreateIn
ObpFreeCapturedAttributes(ObjectCreateInfo, LookasideCreateInfoList);
}
#if DBG
VOID
FORCEINLINE
ObpCalloutStart(IN PKIRQL CalloutIrql)
{
/* Save the callout IRQL */
*CalloutIrql = KeGetCurrentIrql();
}
VOID
FORCEINLINE
ObpCalloutEnd(IN KIRQL CalloutIrql,
IN PCHAR Procedure,
IN POBJECT_TYPE ObjectType,
IN PVOID Object)
{
/* Detect IRQL change */
if (CalloutIrql != KeGetCurrentIrql())
{
/* Print error */
DbgPrint("OB: ObjectType: %wZ Procedure: %s Object: %08x\n",
&ObjectType->Name, Procedure, Object);
DbgPrint(" Returned at %x IRQL, but was called at %x IRQL\n",
KeGetCurrentIrql(), CalloutIrql);
DbgBreakPoint();
}
}
#else
VOID
FORCEINLINE
ObpCalloutStart(IN PKIRQL CalloutIrql)
{
/* No-op */
UNREFERENCED_PARAMETER(CalloutIrql);
}
VOID
FORCEINLINE
ObpCalloutEnd(IN KIRQL CalloutIrql,
IN PCHAR Procedure,
IN POBJECT_TYPE ObjectType,
IN PVOID Object)
{
UNREFERENCED_PARAMETER(CalloutIrql);
}
#endif

View file

@ -1249,7 +1249,7 @@ ObpCreateHandle(IN OB_OPEN_REASON OpenReason,
if ((Type) && (ObjectType != Type))
{
/* They don't, cleanup */
//if (Context) ObpCleanupDirectoryLookup(Object, Context);
//if (Context) ObpCleanupDirectoryLookup(Context);
return STATUS_OBJECT_TYPE_MISMATCH;
}
@ -1287,7 +1287,7 @@ ObpCreateHandle(IN OB_OPEN_REASON OpenReason,
* We failed (meaning security failure, according to NT Internals)
* detach and return
*/
//if (Context) ObpCleanupDirectoryLookup(Object, Context);
//if (Context) ObpCleanupDirectoryLookup(Context);
if (AttachedToProcess) KeUnstackDetachProcess(&ApcState);
return Status;
}
@ -1327,7 +1327,8 @@ ObpCreateHandle(IN OB_OPEN_REASON OpenReason,
}
/* Now we can release the object */
//if (Context) ObpCleanupDirectoryLookup(Object, Context);
//if (Context) ObpCleanupDirectoryLookup(Context);
if (Context) Context->Object = NULL;
/* Save the object header */
NewEntry.Object = ObjectHeader;
@ -2116,7 +2117,7 @@ ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes,
if (!NT_SUCCESS(Status))
{
/* Cleanup after lookup */
//ObpCleanupDirectoryLookup(&TempBuffer->LookupContext, TRUE);
//ObpCleanupDirectoryLookup(&TempBuffer->LookupContext);
TempBuffer->LookupContext.Object = NULL;
goto Cleanup;
}
@ -2151,7 +2152,8 @@ ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes,
Status = STATUS_INVALID_PARAMETER;
/* Cleanup after lookup */
//ObpCleanupDirectoryLookup(&TempBuffer->LookupContext, TRUE);
//ObpCleanupDirectoryLookup(&TempBuffer->LookupContext);
TempBuffer->LookupContext.Object = NULL;
}
else
{

View file

@ -283,9 +283,6 @@ ObPostPhase0:
/* Lock it */
//ObpAcquireDirectoryLockExclusive(ObpTypeDirectoryObject, &Context);
/* Setup directory */
// FIXME: ObpSetLookupDirectory(Dir);?
Context.Directory = ObpTypeDirectoryObject;
Context.DirectoryLocked = TRUE;
Context.LockStateSignature = 0xCCCC1234;
@ -326,7 +323,7 @@ ObPostPhase0:
}
/* Cleanup after lookup */
//ObpCleanupDirectoryLookup(&Context, TRUE);
//ObpCleanupDirectoryLookup(&Context);
Context.Object = NULL;
/* Initialize DOS Devices Directory and related Symbolic Links */

View file

@ -958,14 +958,19 @@ ObCreateObjectType(IN PUNICODE_STRING TypeName,
if (*p++ == OBJ_NAME_PATH_SEPARATOR) return STATUS_OBJECT_NAME_INVALID;
}
Context.Object = NULL;
/* Setup a lookup context */
ObpInitializeDirectoryLookup(&Context);
/* Check if we've already created the directory of types */
if (ObpTypeDirectoryObject)
{
/* Then scan it to figure out if we've already created this type */
/* Acquire the directory lock */
//ObpAcquireDirectoryLockExclusive(ObpTypeDirectoryObject, &Context);
Context.Directory = ObpTypeDirectoryObject;
Context.DirectoryLocked = TRUE;
Context.LockStateSignature = 0xCCCC1234;
/* Do the lookup */
if (ObpLookupEntryDirectory(ObpTypeDirectoryObject,
TypeName,
OBJ_CASE_INSENSITIVE,

View file

@ -194,12 +194,10 @@ ObpDeleteNameCheck(IN PVOID Object)
!(ObjectHeader->Flags & OB_FLAG_PERMANENT))
{
/* Setup a lookup context */
Context.Object = NULL;
ObpInitializeDirectoryLookup(&Context);
/* Lock the directory */
//ObpAcquireDirectoryLockExclusive(ObjectNameInfo->Directory, &Context);
/* Set the lookup parameters */
Context.Directory = ObjectNameInfo->Directory;
Context.DirectoryLocked = TRUE;
Context.LockStateSignature = 0xCCCC1234;
@ -255,7 +253,7 @@ ObpDeleteNameCheck(IN PVOID Object)
}
/* Cleanup after lookup */
//ObpCleanupDirectoryLookup(&Context, TRUE);
//ObpCleanupDirectoryLookup(&Context);
Context.Object = NULL;
/* Remove another query reference since we added one on top */
@ -313,7 +311,7 @@ ObpLookupObjectName(IN HANDLE RootHandle,
InsertObject);
/* Initialize starting state */
LookupContext->Object = NULL;
ObpInitializeDirectoryLookup(LookupContext);
*FoundObject = NULL;
Status = STATUS_SUCCESS;
Object = NULL;
@ -575,10 +573,7 @@ ReparseNewDir:
if (InsertObject)
{
/* Lock the directory */
//ObpAcquireDirectoryLockExclusive(LookupContext, Directory);
/* Setup the context */
// FIXME: ObpSetLookupDirectory(Dir);?
//ObpAcquireDirectoryLockExclusive(Directory, LookupContext);
LookupContext->Directory = Directory;
LookupContext->DirectoryLocked = TRUE;
LookupContext->LockStateSignature = 0xCCCC1234;
@ -701,7 +696,7 @@ Reparse:
InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1);
/* Cleanup from the first lookup */
//ObpCleanupDirectoryLookup(LookupContext, TRUE);
//ObpCleanupDirectoryLookup(LookupContext);
LookupContext->Object = NULL;
/* Check if we have a referenced directory */
@ -868,7 +863,7 @@ Reparse:
if (!NT_SUCCESS(Status))
{
/* Cleanup after lookup */
//ObpCleanupDirectoryLookup(LookupContext, TRUE);
//ObpCleanupDirectoryLookup(LookupContext);
LookupContext->Object = NULL;
}

View file

@ -430,7 +430,7 @@ ObReferenceObjectByName(IN PUNICODE_STRING ObjectPath,
&Object);
/* Cleanup after lookup */
//ObpCleanupDirectoryLookup(&Context, TRUE);
//ObpCleanupDirectoryLookup(&Context);
Context.Object = NULL;
/* Check if the lookup succeeded */