Author: dchapyshev
Date: Sun Aug 28 19:18:28 2016
New Revision: 72491
URL:
http://svn.reactos.org/svn/reactos?rev=72491&view=rev
Log:
[NTOS]
- Use ExpLookupHandleTableEntry function for enumerate handles of process
- Filling handle information
- Setting ReqSize value before check of the size
* Fixes 2 tests ntdll_winetest info
Modified:
trunk/reactos/ntoskrnl/ex/sysinfo.c
trunk/reactos/ntoskrnl/include/internal/ex.h
Modified: trunk/reactos/ntoskrnl/ex/sysinfo.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/sysinfo.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/ex/sysinfo.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ex/sysinfo.c [iso-8859-1] Sun Aug 28 19:18:28 2016
@@ -1167,11 +1167,13 @@
/* Class 16 - Handle Information */
QSI_DEF(SystemHandleInformation)
{
- PEPROCESS pr, syspr;
- ULONG curSize, i = 0;
- ULONG hCount = 0;
-
- PSYSTEM_HANDLE_INFORMATION Shi =
+ PEPROCESS Process;
+ PEPROCESS SystemProcess;
+ ULONG CurrentSize;
+ ULONG NumberOfHandles = 0;
+ ULONG Index;
+
+ PSYSTEM_HANDLE_INFORMATION HandleInformation =
(PSYSTEM_HANDLE_INFORMATION) Buffer;
DPRINT("NtQuerySystemInformation - SystemHandleInformation\n");
@@ -1182,68 +1184,92 @@
return STATUS_INFO_LENGTH_MISMATCH;
}
- DPRINT("SystemHandleInformation 1\n");
-
/* First Calc Size from Count. */
- syspr = PsGetNextProcess(NULL);
- pr = syspr;
+ SystemProcess = PsGetNextProcess(NULL);
+ Process = SystemProcess;
do
{
- hCount = hCount + ObGetProcessHandleCount(pr);
- pr = PsGetNextProcess(pr);
-
- if ((pr == syspr) || (pr == NULL)) break;
- }
- while ((pr != syspr) && (pr != NULL));
-
- if(pr != NULL)
- {
- ObDereferenceObject(pr);
- }
-
- DPRINT("SystemHandleInformation 2\n");
-
- 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;
- return (STATUS_INFO_LENGTH_MISMATCH);
- }
-
- DPRINT("SystemHandleInformation 3\n");
+ NumberOfHandles += ObGetProcessHandleCount(Process);
+ Process = PsGetNextProcess(Process);
+
+ if ((Process == SystemProcess) || (Process == NULL)) break;
+ }
+ while ((Process != SystemProcess) && (Process != NULL));
+
+ if (Process != NULL) ObDereferenceObject(Process);
+
+ CurrentSize = sizeof(SYSTEM_HANDLE_INFORMATION) +
+ ((sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO) * NumberOfHandles) -
+ (sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO)));
+
+ HandleInformation->NumberOfHandles = NumberOfHandles;
+
+ *ReqSize = CurrentSize;
+
+ if (CurrentSize > Size) return STATUS_INFO_LENGTH_MISMATCH;
/* Now get Handles from all processes. */
- syspr = PsGetNextProcess(NULL);
- pr = syspr;
+ SystemProcess = PsGetNextProcess(NULL);
+ Process = SystemProcess;
+
+ Index = 0;
do
{
- int Count = 0, HandleCount;
-
- HandleCount = ObGetProcessHandleCount(pr);
-
- for (Count = 0; HandleCount > 0 ; HandleCount--)
- {
- Shi->Handles[i].UniqueProcessId =
(USHORT)(ULONG_PTR)pr->UniqueProcessId;
- 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");
+ PHANDLE_TABLE_ENTRY HandleTableEntry;
+ EXHANDLE Handle;
+
+ /* Enter a critical region */
+ KeEnterCriticalRegion();
+
+ /* Set the initial value and loop the entries */
+ Handle.Value = 0;
+ while ((HandleTableEntry = ExpLookupHandleTableEntry(Process->ObjectTable,
Handle)))
+ {
+ /* Validate the entry */
+ if ((HandleTableEntry) &&
+ (HandleTableEntry->Object) &&
+ (HandleTableEntry->NextFreeTableEntry != -2))
+ {
+ /* Lock the entry */
+ if (ExpLockHandleTableEntry(Process->ObjectTable, HandleTableEntry))
+ {
+ POBJECT_HEADER ObjectHeader;
+
+ ObjectHeader = (POBJECT_HEADER)(((ULONG_PTR)
HandleTableEntry->Object) & ~OBJ_HANDLE_ATTRIBUTES);
+
+ /* Filling handle information */
+ HandleInformation->Handles[Index].UniqueProcessId =
(USHORT)(ULONG_PTR) Process->UniqueProcessId;
+ HandleInformation->Handles[Index].CreatorBackTraceIndex = 0;
+ HandleInformation->Handles[Index].ObjectTypeIndex = (UCHAR)
ObjectHeader->Type->Index;
+ HandleInformation->Handles[Index].HandleAttributes =
HandleTableEntry->ObAttributes & OBJ_HANDLE_ATTRIBUTES;
+ HandleInformation->Handles[Index].HandleValue =
(USHORT)(ULONG_PTR) Handle.GenericHandleOverlay;
+ HandleInformation->Handles[Index].Object =
&ObjectHeader->Body;
+ HandleInformation->Handles[Index].GrantedAccess =
HandleTableEntry->GrantedAccess;
+
+ /* Unlock it */
+ ExUnlockHandleTableEntry(Process->ObjectTable, HandleTableEntry);
+
+ ++Index;
+ }
+ }
+
+ /* Go to the next entry */
+ Handle.Value += sizeof(HANDLE);
+ }
+
+ /* Leave the critical region and return callback result */
+ KeLeaveCriticalRegion();
+
+ Process = PsGetNextProcess(Process);
+
+ if ((Process == SystemProcess) || (Process == NULL)) break;
+ }
+ while ((Process != SystemProcess) && (Process != NULL));
+
+ if (Process != NULL) ObDereferenceObject(Process);
+
return STATUS_SUCCESS;
}
Modified: trunk/reactos/ntoskrnl/include/internal/ex.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ex.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/ex.h [iso-8859-1] Sun Aug 28 19:18:28 2016
@@ -466,6 +466,20 @@
IN PVOID Context
);
+PHANDLE_TABLE_ENTRY
+NTAPI
+ExpLookupHandleTableEntry(
+ IN PHANDLE_TABLE HandleTable,
+ IN EXHANDLE Handle
+);
+
+BOOLEAN
+NTAPI
+ExpLockHandleTableEntry(
+ IN PHANDLE_TABLE HandleTable,
+ IN PHANDLE_TABLE_ENTRY HandleTableEntry
+);
+
/* PSEH EXCEPTION HANDLING **************************************************/
LONG