From 95957e58268055f9f96571a95416636dcafa109b Mon Sep 17 00:00:00 2001 From: James Tabor Date: Tue, 1 Mar 2005 02:32:09 +0000 Subject: [PATCH] Partial implementation of SystemHandleInformation and ObpGetNextHandleByProcessCount (Name will change very soon). Fix GetHandleCountByHandleTable return real number of open handles. svn path=/trunk/; revision=13787 --- reactos/ntoskrnl/ex/sysinfo.c | 100 +++++++++++++++++++++++++++++++++- reactos/ntoskrnl/ob/handle.c | 32 ++++++++++- 2 files changed, 127 insertions(+), 5 deletions(-) diff --git a/reactos/ntoskrnl/ex/sysinfo.c b/reactos/ntoskrnl/ex/sysinfo.c index 2efe7292c20..079005d347e 100644 --- a/reactos/ntoskrnl/ex/sysinfo.c +++ b/reactos/ntoskrnl/ex/sysinfo.c @@ -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) diff --git a/reactos/ntoskrnl/ob/handle.c b/reactos/ntoskrnl/ob/handle.c index b7811227fbb..58250750a72 100644 --- a/reactos/ntoskrnl/ob/handle.c +++ b/reactos/ntoskrnl/ob/handle.c @@ -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 */