- Implement ExEnumHandleTable. Had to add a small hack due to some memory freeing...
authorAlex Ionescu <aionescu@gmail.com>
Mon, 22 Jan 2007 09:57:10 +0000 (09:57 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Mon, 22 Jan 2007 09:57:10 +0000 (09:57 +0000)
- Implement ObpEnumFindHandleProcedure.

svn path=/trunk/; revision=25593

reactos/include/ndk/exfuncs.h
reactos/include/ndk/extypes.h
reactos/ntoskrnl/ex/handle.c
reactos/ntoskrnl/ex/sysinfo.c
reactos/ntoskrnl/ob/obhandle.c
reactos/subsystems/win32/win32k/ntuser/desktop.c

index ba79518..d987c74 100644 (file)
@@ -111,8 +111,8 @@ BOOLEAN
 NTAPI
 ExEnumHandleTable(
     IN PHANDLE_TABLE HandleTable,
-    IN PVOID Callback,
-    IN OUT PVOID Param,
+    IN PEX_ENUM_HANDLE_CALLBACK EnumHandleProcedure,
+    IN OUT PVOID Context,
     OUT PHANDLE Handle OPTIONAL
 );
 
index 01cb60d..fb221c6 100644 (file)
@@ -361,6 +361,17 @@ NTSTATUS
 
 #else
 
+//
+// Handle Enumeration Callback
+//
+struct _HANDLE_TABLE_ENTRY;
+typedef BOOLEAN
+(NTAPI *PEX_ENUM_HANDLE_CALLBACK)(
+    IN struct _HANDLE_TABLE_ENTRY *HandleTableEntry,
+    IN HANDLE Handle,
+    IN PVOID Context
+);
+
 //
 // Compatibility with Windows XP Drivers using ERESOURCE
 //
index 2e68cbe..e91a744 100644 (file)
@@ -39,7 +39,7 @@ ExpLookupHandleTableEntry(IN PHANDLE_TABLE HandleTable,
     ULONG_PTR TableBase;
     PHANDLE_TABLE_ENTRY Entry = NULL;
     EXHANDLE Handle = LookupHandle;
-    PCHAR Level1, Level2, Level3;
+    PUCHAR Level1, Level2, Level3;
 
     /* Clear the tag bits and check what the next handle is */
     Handle.TagBits = 0;
@@ -1239,3 +1239,61 @@ ExSweepHandleTable(IN PHANDLE_TABLE HandleTable,
         Handle.Value += SizeOfHandle(1);
     }
 }
+
+/*
+ * @implemented
+ */
+BOOLEAN
+NTAPI
+ExEnumHandleTable(IN PHANDLE_TABLE HandleTable,
+                  IN PEX_ENUM_HANDLE_CALLBACK EnumHandleProcedure,
+                  IN OUT PVOID Context,
+                  OUT PHANDLE EnumHandle OPTIONAL)
+{
+    EXHANDLE Handle;
+    PHANDLE_TABLE_ENTRY HandleTableEntry;
+    BOOLEAN Result = FALSE;
+    PAGED_CODE();
+
+    /* Enter a critical region */
+    KeEnterCriticalRegion();
+
+    /* Set the initial value and loop the entries */
+    Handle.Value = 0;
+    while ((HandleTableEntry = ExpLookupHandleTableEntry(HandleTable, Handle)))
+    {
+        /* Validate the entry */
+        if ((HandleTableEntry) &&
+            (HandleTableEntry->Object) &&
+            (HandleTableEntry->NextFreeTableEntry != -2) &&
+            (HandleTableEntry->Object != (PVOID)0xCDCDCDCD)) // HACK OF ETERNAL LAPDANCE
+        {
+            /* Lock the entry */
+            if (ExpLockHandleTableEntry(HandleTable, HandleTableEntry))
+            {
+                /* Notify the callback routine */
+                Result = EnumHandleProcedure(HandleTableEntry,
+                                             Handle.GenericHandleOverlay,
+                                             Context);
+
+                /* Unlock it */
+                ExUnlockHandleTableEntry(HandleTable, HandleTableEntry);
+
+                /* Was this the one looked for? */
+                if (Result)
+                {
+                    /* If so, return it if requested */
+                    if (EnumHandle) *EnumHandle = Handle.GenericHandleOverlay;
+                    break;
+                }
+            }
+        }
+
+        /* Go to the next entry */
+        Handle.Value += SizeOfHandle(1);
+    }
+
+    /* Leave the critical region and return callback result */
+    KeLeaveCriticalRegion();
+    return Result;
+}
index 8f91ef3..c04659e 100644 (file)
@@ -38,20 +38,6 @@ ExGetPreviousMode (VOID)
     return KeGetPreviousMode();
 }
 
-/*
- * @unimplemented
- */
-BOOLEAN
-NTAPI
-ExEnumHandleTable(IN PHANDLE_TABLE HandleTable,
-                  IN PVOID Callback,
-                  IN OUT PVOID Param,
-                  OUT PHANDLE Handle OPTIONAL)
-{
-    UNIMPLEMENTED;
-    return FALSE;
-}
-
 /*
  * @implemented
  */
index 9383bd8..f9b71e2 100644 (file)
@@ -177,10 +177,46 @@ ObpEnumFindHandleProcedure(IN PHANDLE_TABLE_ENTRY HandleEntry,
                            IN HANDLE Handle,
                            IN PVOID Context)
 {
-    /* FIXME: TODO */
-    DPRINT1("Not yet implemented!\n");
-    KEBUGCHECK(0);
-    return FALSE;
+    POBJECT_HEADER ObjectHeader;
+    ACCESS_MASK GrantedAccess;
+    ULONG HandleAttributes;
+    POBP_FIND_HANDLE_DATA FindData = Context;
+
+    /* Get the object header */
+    ObjectHeader = ObpGetHandleObject(HandleEntry);
+
+    /* Make sure it's valid and matching */
+    if ((FindData->ObjectHeader) && (FindData->ObjectHeader != ObjectHeader))
+    {
+        /* No match, fail */
+        return FALSE;
+    }
+
+    /* Now attempt to match the object type */
+    if ((FindData->ObjectType) && (FindData->ObjectType != ObjectHeader->Type))
+    {
+        /* No match, fail */
+        return FALSE;
+    }
+
+    /* Check if we have extra information */
+    if (FindData->HandleInformation)
+    {
+        /* Get the granted access and attributes */
+        GrantedAccess = HandleEntry->GrantedAccess;
+        HandleAttributes = HandleEntry->ObAttributes & OBJ_HANDLE_ATTRIBUTES;
+
+        /* Attempt to match them */
+        if ((FindData->HandleInformation->HandleAttributes != HandleAttributes) ||
+            (FindData->HandleInformation->GrantedAccess != GrantedAccess))
+        {
+            /* No match, fail */
+            return FALSE;
+        }
+    }
+
+    /* We have a match */
+    return TRUE;
 }
 
 POBJECT_HANDLE_COUNT_ENTRY
index ec23d91..51ef630 100644 (file)
@@ -297,6 +297,7 @@ IntParseDesktopPath(PEPROCESS Process,
 
    if(!WinStaPresent)
    {
+#if 0
       /* search the process handle table for (inherited) window station
          handles, use a more appropriate one than WinSta0 if possible. */
       if (!ObFindHandleForObject(Process,
@@ -304,6 +305,7 @@ IntParseDesktopPath(PEPROCESS Process,
                                  ExWindowStationObjectType,
                                  NULL,
                                  (PHANDLE)hWinSta))
+#endif
       {
             /* we had no luck searching for opened handles, use WinSta0 now */
             RtlInitUnicodeString(&WinSta, L"WinSta0");
@@ -312,6 +314,7 @@ IntParseDesktopPath(PEPROCESS Process,
 
    if(!DesktopPresent && hDesktop != NULL)
    {
+#if 0
       /* search the process handle table for (inherited) desktop
          handles, use a more appropriate one than Default if possible. */
       if (!ObFindHandleForObject(Process,
@@ -319,6 +322,7 @@ IntParseDesktopPath(PEPROCESS Process,
                                  ExDesktopObjectType,
                                  NULL,
                                  (PHANDLE)hDesktop))
+#endif
       {
          /* we had no luck searching for opened handles, use Desktop now */
          RtlInitUnicodeString(&Desktop, L"Default");
@@ -497,6 +501,10 @@ IntGetDesktopObjectHandle(PDESKTOP_OBJECT DesktopObject)
          return NULL;
       }
    }
+   else
+   {
+       DPRINT1("Got handle: %lx\n", Ret);
+   }
 
    return Ret;
 }