Partial implementation of SystemHandleInformation and ObpGetNextHandleByProcessCount...
authorJames Tabor <james.tabor@reactos.org>
Tue, 1 Mar 2005 02:32:09 +0000 (02:32 +0000)
committerJames Tabor <james.tabor@reactos.org>
Tue, 1 Mar 2005 02:32:09 +0000 (02:32 +0000)
svn path=/trunk/; revision=13787

reactos/ntoskrnl/ex/sysinfo.c
reactos/ntoskrnl/ob/handle.c

index 2efe729..079005d 100644 (file)
@@ -811,13 +811,107 @@ QSI_DEF(SystemNonPagedPoolInformation)
        return (STATUS_NOT_IMPLEMENTED);
 }
 
+
+VOID
+ObpGetNextHandleByProcessCount(PSYSTEM_HANDLE_TABLE_ENTRY_INFO pshi,
+                               PEPROCESS Process,
+                               int Count);
+
 /* Class 16 - Handle Information */
 QSI_DEF(SystemHandleInformation)
 {
-       /* FIXME */
-       DPRINT1("NtQuerySystemInformation - SystemHandleInformation not implemented\n");
-       return (STATUS_NOT_IMPLEMENTED);
+
+        PSYSTEM_HANDLE_INFORMATION Shi = 
+               (PSYSTEM_HANDLE_INFORMATION) Buffer;
+
+        DPRINT("NtQuerySystemInformation - SystemHandleInformation\n");
+
+       if (Size < sizeof (SYSTEM_HANDLE_INFORMATION))
+        {
+               * ReqSize = sizeof (SYSTEM_HANDLE_INFORMATION);
+               return (STATUS_INFO_LENGTH_MISMATCH);
+       }
+
+       DPRINT("SystemHandleInformation 1\n");
+
+       PEPROCESS pr, syspr;
+       int curSize, i = 0;
+       ULONG hCount = 0;
+               
+        /* First Calc Size from Count. */
+        syspr = PsGetNextProcess(NULL);
+       pr = syspr;
+
+        do
+         {
+            hCount = hCount + ObpGetHandleCountByHandleTable(&pr->HandleTable);
+
+            curSize = sizeof(SYSTEM_HANDLE_INFORMATION)+
+                        (  (sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO) * hCount) - 
+                           (sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO) ));
+
+            Shi->NumberOfHandles = hCount;
+
+           if (curSize > Size)
+             {
+               *ReqSize = curSize;
+               DPRINT1("SystemHandleInformation 2\n");
+               return (STATUS_INFO_LENGTH_MISMATCH);
+             }
+
+           pr = PsGetNextProcess(pr);
+
+           if ((pr == syspr) || (pr == NULL))
+               break;
+        } while ((pr != syspr) && (pr != NULL));
+
+       if (pr != NULL)
+         {
+           ObDereferenceObject(pr);
+         }
+
+       DPRINT("SystemHandleInformation 3\n");
+
+        /* Now get Handles from all processs. */
+        syspr = PsGetNextProcess(NULL);
+       pr = syspr;
+
+        do
+         {
+            int Count = 0, HandleCount = 0;
+
+            HandleCount = ObpGetHandleCountByHandleTable(&pr->HandleTable);
+
+            for (Count = 0; HandleCount > 0 ; HandleCount--)
+               {
+                 ObpGetNextHandleByProcessCount( &Shi->Handles[i], pr, Count);
+                 Count++;
+                 i++;
+               }
+
+           pr = PsGetNextProcess(pr);
+
+           if ((pr == syspr) || (pr == NULL))
+               break;
+          } while ((pr != syspr) && (pr != NULL));
+
+
+       if (pr != NULL)
+         {
+           ObDereferenceObject(pr);
+         }
+
+       DPRINT("SystemHandleInformation 4\n");
+       return (STATUS_SUCCESS);
+
 }
+/*
+SSI_DEF(SystemHandleInformation)
+{
+       
+       return (STATUS_SUCCESS);
+}
+*/
 
 /* Class 17 -  Information */
 QSI_DEF(SystemObjectInformation)
index b781122..5825075 100644 (file)
@@ -1014,8 +1014,9 @@ ObpGetHandleCountByHandleTable(PHANDLE_TABLE HandleTable)
            {
              Header = BODY_TO_HEADER(ObjectBody);
 
-             /* Make sure this is real. */
-             if (Header->ObjectType != NULL)
+             /* Make sure this is real. Okay! For real!*/
+             if ((Header->ObjectType != NULL) &&
+                     (Header->ObjectType->Close != NULL))
                Count++;
            }
        }
@@ -1078,4 +1079,31 @@ ObFindHandleForObject(IN PEPROCESS Process,
   return STATUS_UNSUCCESSFUL;
 }
 
+VOID
+ObpGetNextHandleByProcessCount(PSYSTEM_HANDLE_TABLE_ENTRY_INFO pshi,
+                               PEPROCESS Process,
+                               int Count)
+{
+      ULONG P;
+      KIRQL oldIrql;
+
+//      pshi->HandleValue;
+
+      P = (ULONG) Process->UniqueProcessId;
+      pshi->UniqueProcessId = (USHORT) P;
+
+      KeAcquireSpinLock( &Process->HandleTable.ListLock, &oldIrql );
+
+//      pshi->GrantedAccess;
+//      pshi->Object;
+//      pshi->ObjectTypeIndex;
+//      pshi->HandleAttributes;
+
+      KeReleaseSpinLock( &Process->HandleTable.ListLock, oldIrql );
+
+      return;
+}
+
+
+
 /* EOF */