Author: ion
Date: Fri Jul 14 19:26:19 2006
New Revision: 23060
URL:
http://svn.reactos.org/svn/reactos?rev=23060&view=rev
Log:
- Implement Safe Referencing (an internal method for referencing objects when race
conditions are possible)
- Implement two Vista APIs and export them: ObIsKernelHandle and
ObDeleteObjectDeferDelete. ZOMG! Vista APIs in the kernel!
Modified:
trunk/reactos/ntoskrnl/ntoskrnl.def
trunk/reactos/ntoskrnl/ob/obhandle.c
trunk/reactos/ntoskrnl/ob/obref.c
Modified: trunk/reactos/ntoskrnl/ntoskrnl.def
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ntoskrnl.def?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/ntoskrnl.def (original)
+++ trunk/reactos/ntoskrnl/ntoskrnl.def Fri Jul 14 19:26:19 2006
@@ -841,12 +841,14 @@
ObCreateObject@36
ObCreateObjectType@16
ObDereferenceObject@4
+ObDereferenceObjectDeferDelete@4
ObDereferenceSecurityDescriptor@8
@ObfDereferenceObject@4
ObFindHandleForObject@20
@ObfReferenceObject@4
ObGetObjectSecurity@12
ObInsertObject@24
+ObIsKernelHandle@4
ObLogSecurityDescriptor@12
ObMakeTemporaryObject@4
ObOpenObjectByName@28
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 Fri Jul 14 19:26:19 2006
@@ -2155,4 +2155,14 @@
ObDereferenceObject(SourceProcess);
return Status;
}
+
+#undef ObIsKernelHandle
+BOOLEAN
+NTAPI
+ObIsKernelHandle(IN HANDLE Handle)
+{
+ /* We know we're kernel mode, so just check for the kernel handle flag */
+ return (BOOLEAN)((ULONG_PTR)Handle & KERNEL_HANDLE_FLAG);
+}
+
/* EOF */
Modified: trunk/reactos/ntoskrnl/ob/obref.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/obref.c?rev=23…
==============================================================================
--- trunk/reactos/ntoskrnl/ob/obref.c (original)
+++ trunk/reactos/ntoskrnl/ob/obref.c Fri Jul 14 19:26:19 2006
@@ -17,6 +17,37 @@
/* PRIVATE FUNCTIONS *********************************************************/
+BOOLEAN
+FASTCALL
+ObReferenceObjectSafe(IN PVOID Object)
+{
+ POBJECT_HEADER ObjectHeader;
+ LONG OldValue, NewValue;
+
+ /* Get the object header */
+ ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
+
+ /* Get the current reference count and fail if it's zero */
+ OldValue = ObjectHeader->PointerCount;
+ if (!OldValue) return FALSE;
+
+ /* Start reference loop */
+ do
+ {
+ /* Increase the reference count */
+ NewValue = InterlockedCompareExchange(&ObjectHeader->PointerCount,
+ OldValue + 1,
+ OldValue);
+ if (OldValue == NewValue) return TRUE;
+
+ /* Keep looping */
+ OldValue = NewValue;
+ } while (OldValue);
+
+ /* If we got here, then the reference count is now 0 */
+ return FALSE;
+}
+
VOID
NTAPI
ObpDeferObjectDeletion(IN PVOID Object)
@@ -129,7 +160,6 @@
/* Get the object and count */
Object = (PVOID)(Value &~ MAX_FAST_REFS);
Count = Value & MAX_FAST_REFS;
- DPRINT("Ref: %p\n", Object);
/* Check if the reference count is over 1 */
if (Count > 1) return Object;
@@ -172,7 +202,6 @@
ULONG_PTR Value, NewValue;
/* Sanity checks */
- DPRINT("DeRef: %p\n", Object);
ASSERT(Object);
ASSERT(!(((ULONG_PTR)Object) & MAX_FAST_REFS));
@@ -287,10 +316,19 @@
}
}
-#ifdef ObDereferenceObject
+VOID
+NTAPI
+ObDereferenceObjectDeferDelete(IN PVOID Object)
+{
+ /* Check whether the object can now be deleted. */
+ if (!(InterlockedDecrement(&OBJECT_TO_OBJECT_HEADER(Object)->PointerCount)))
+ {
+ /* Add us to the deferred deletion list */
+ ObpDeferObjectDeletion(Object);
+ }
+}
+
#undef ObDereferenceObject
-#endif
-
VOID
NTAPI
ObDereferenceObject(IN PVOID Object)