Proper way for counting process handles.

svn path=/trunk/; revision=9275
This commit is contained in:
James Tabor 2004-05-02 04:40:25 +00:00
parent f36cfa653a
commit f9df303240
4 changed files with 40 additions and 5 deletions

View file

@ -1,4 +1,4 @@
/* $Id: sysinfo.c,v 1.32 2004/04/28 20:50:02 hbirr Exp $
/* $Id: sysinfo.c,v 1.33 2004/05/02 04:40:24 jimtabor Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -552,7 +552,7 @@ QSI_DEF(SystemProcessInformation)
SpiCur->BasePriority = pr->Pcb.BasePriority;
SpiCur->ProcessId = pr->UniqueProcessId;
SpiCur->InheritedFromProcessId = (DWORD)(pr->InheritedFromUniqueProcessId);
SpiCur->HandleCount = ObGetObjectHandleCount(pr);
SpiCur->HandleCount = ObpGetHandleCountbyHandleTable(&pr->HandleTable);
SpiCur->VmCounters.PeakVirtualSize = pr->PeakVirtualSize;
SpiCur->VmCounters.VirtualSize = pr->VirtualSize.QuadPart;
SpiCur->VmCounters.PageFaultCount = pr->LastFaultCount;

View file

@ -133,4 +133,8 @@ ObDuplicateObject(PEPROCESS SourceProcess,
BOOLEAN InheritHandle,
ULONG Options);
ULONG
ObpGetHandleCountbyHandleTable(PHANDLE_TABLE HandleTable);
#endif /* __INCLUDE_INTERNAL_OBJMGR_H */

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: handle.c,v 1.54 2003/10/21 21:46:02 ekohl Exp $
/* $Id: handle.c,v 1.55 2004/05/02 04:40:25 jimtabor Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -949,4 +949,35 @@ ObInsertObject(IN PVOID Object,
Handle));
}
ULONG
ObpGetHandleCountbyHandleTable(PHANDLE_TABLE HandleTable)
{
unsigned int i, Count=0;
PHANDLE_BLOCK blk;
POBJECT_HEADER Header;
PVOID ObjectBody;
PLIST_ENTRY current = HandleTable->ListHead.Flink;
while (current != &HandleTable->ListHead)
{
blk = CONTAINING_RECORD(current, HANDLE_BLOCK, entry);
for ( i=0; i<HANDLE_BLOCK_ENTRIES; i++)
{
ObjectBody = OB_ENTRY_TO_POINTER(blk->handles[i].ObjectBody);
if (ObjectBody != NULL)
{
Header = BODY_TO_HEADER(ObjectBody);
/* Make sure this is real. */
if (Header->ObjectType != NULL)
Count++;
}
}
current = current->Flink;
}
return (Count);
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.130 2004/04/26 05:46:35 jimtabor Exp $
/* $Id: process.c,v 1.131 2004/05/02 04:40:25 jimtabor Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -1118,7 +1118,7 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
else
{
PULONG HandleCount = (PULONG)ProcessInformation;
*HandleCount = ObGetObjectHandleCount(Process);
*HandleCount = ObpGetHandleCountbyHandleTable(&Process->HandleTable);
if (ReturnLength)
{
*ReturnLength = sizeof(ULONG);