Author: ion
Date: Wed Jan 10 00:48:26 2007
New Revision: 25403
URL:
http://svn.reactos.org/svn/reactos?rev=25403&view=rev
Log:
- 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.
Modified:
trunk/reactos/ntoskrnl/include/internal/ob_x.h
trunk/reactos/ntoskrnl/ob/obhandle.c
trunk/reactos/ntoskrnl/ob/obinit.c
trunk/reactos/ntoskrnl/ob/oblife.c
trunk/reactos/ntoskrnl/ob/obname.c
trunk/reactos/ntoskrnl/ob/obref.c
Modified: trunk/reactos/ntoskrnl/include/internal/ob_x.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ob_x.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/ob_x.h Wed Jan 10 00:48:26 2007
@@ -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,36 +79,49 @@
VOID
FORCEINLINE
-_ObpCleanupDirectoryLookup(IN POBP_LOOKUP_CONTEXT Context,
- IN BOOLEAN DereferenceObject)
-{
- 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)
- {
- /* Get the object name information */
- ObjectHeader = OBJECT_TO_OBJECT_HEADER(Context->Object);
- HeaderNameInfo = OBJECT_HEADER_TO_NAME_INFO(ObjectHeader);
-
- /* Check if we do have name information */
- if (HeaderNameInfo) _ObpDecrementQueryReference(HeaderNameInfo);
-
- /* Check if we need to dereference it */
- if (DereferenceObject) ObDereferenceObject(Context->Object);
- }
+_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
@@ -199,7 +132,47 @@
Context->Object = NULL;
Context->Directory = NULL;
Context->DirectoryLocked = FALSE;
- Context->LockStateSignature = 0xFFFF1234;
+ 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 had found an object */
+ if (Context->Object)
+ {
+ /* Get the object name information */
+ ObjectHeader = OBJECT_TO_OBJECT_HEADER(Context->Object);
+ HeaderNameInfo = OBJECT_HEADER_TO_NAME_INFO(ObjectHeader);
+
+ /* Check if we do have name information */
+ if (HeaderNameInfo) _ObpDecrementQueryReference(HeaderNameInfo);
+
+ /* Dereference the object */
+ ObDereferenceObject(Context->Object);
+ Context->Object = NULL;
+ }
+}
+
+VOID
+FORCEINLINE
+_ObpCleanupDirectoryLookup(IN POBP_LOOKUP_CONTEXT Context)
+{
+ /* 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;
+ _ObpReleaseLookupContextObject(Context);
}
#if _OB_DEBUG_
@@ -365,5 +338,49 @@
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
Modified: trunk/reactos/ntoskrnl/ob/obhandle.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/obhandle.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/ob/obhandle.c (original)
+++ trunk/reactos/ntoskrnl/ob/obhandle.c Wed Jan 10 00:48:26 2007
@@ -1249,7 +1249,7 @@
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 @@
* 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 @@
}
/* 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 @@
if (!NT_SUCCESS(Status))
{
/* Cleanup after lookup */
- //ObpCleanupDirectoryLookup(&TempBuffer->LookupContext, TRUE);
+ //ObpCleanupDirectoryLookup(&TempBuffer->LookupContext);
TempBuffer->LookupContext.Object = NULL;
goto Cleanup;
}
@@ -2151,7 +2152,8 @@
Status = STATUS_INVALID_PARAMETER;
/* Cleanup after lookup */
- //ObpCleanupDirectoryLookup(&TempBuffer->LookupContext, TRUE);
+ //ObpCleanupDirectoryLookup(&TempBuffer->LookupContext);
+ TempBuffer->LookupContext.Object = NULL;
}
else
{
Modified: trunk/reactos/ntoskrnl/ob/obinit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/obinit.c?rev=2…
==============================================================================
--- trunk/reactos/ntoskrnl/ob/obinit.c (original)
+++ trunk/reactos/ntoskrnl/ob/obinit.c Wed Jan 10 00:48:26 2007
@@ -283,9 +283,6 @@
/* Lock it */
//ObpAcquireDirectoryLockExclusive(ObpTypeDirectoryObject, &Context);
-
- /* Setup directory */
- // FIXME: ObpSetLookupDirectory(Dir);?
Context.Directory = ObpTypeDirectoryObject;
Context.DirectoryLocked = TRUE;
Context.LockStateSignature = 0xCCCC1234;
@@ -326,7 +323,7 @@
}
/* Cleanup after lookup */
- //ObpCleanupDirectoryLookup(&Context, TRUE);
+ //ObpCleanupDirectoryLookup(&Context);
Context.Object = NULL;
/* Initialize DOS Devices Directory and related Symbolic Links */
Modified: trunk/reactos/ntoskrnl/ob/oblife.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/oblife.c?rev=2…
==============================================================================
--- trunk/reactos/ntoskrnl/ob/oblife.c (original)
+++ trunk/reactos/ntoskrnl/ob/oblife.c Wed Jan 10 00:48:26 2007
@@ -958,14 +958,19 @@
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,
Modified: trunk/reactos/ntoskrnl/ob/obname.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/obname.c?rev=2…
==============================================================================
--- trunk/reactos/ntoskrnl/ob/obname.c (original)
+++ trunk/reactos/ntoskrnl/ob/obname.c Wed Jan 10 00:48:26 2007
@@ -194,12 +194,10 @@
!(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 @@
}
/* 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 @@
InsertObject);
/* Initialize starting state */
- LookupContext->Object = NULL;
+ ObpInitializeDirectoryLookup(LookupContext);
*FoundObject = NULL;
Status = STATUS_SUCCESS;
Object = NULL;
@@ -575,10 +573,7 @@
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 @@
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 @@
if (!NT_SUCCESS(Status))
{
/* Cleanup after lookup */
- //ObpCleanupDirectoryLookup(LookupContext, TRUE);
+ //ObpCleanupDirectoryLookup(LookupContext);
LookupContext->Object = NULL;
}
Modified: trunk/reactos/ntoskrnl/ob/obref.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/obref.c?rev=25…
==============================================================================
--- trunk/reactos/ntoskrnl/ob/obref.c (original)
+++ trunk/reactos/ntoskrnl/ob/obref.c Wed Jan 10 00:48:26 2007
@@ -430,7 +430,7 @@
&Object);
/* Cleanup after lookup */
- //ObpCleanupDirectoryLookup(&Context, TRUE);
+ //ObpCleanupDirectoryLookup(&Context);
Context.Object = NULL;
/* Check if the lookup succeeded */