Author: hyperion
Date: Wed Jan 28 04:32:43 2009
New Revision: 39169
URL:
http://svn.reactos.org/svn/reactos?rev=39169&view=rev
Log:
modified ntoskrnl/include/internal/ob.h
modified ntoskrnl/ob/obhandle.c
New helper routine ObGetProcessHandleCount to safely read the count of handles in a
process without messing with Ob internals
Goodbye ObpGetHandleCountByHandleTable
modified ntoskrnl/ex/sysinfo.c
modified ntoskrnl/ps/query.c
Read handle counts with ObGetProcessHandleCount instead of
ObpGetHandleCountByHandleTable
Fixes at least one crash
Thanks to Stefan Ginsberg for reporting the issue and testing
Thanks to Alex Ionescu for code review and suggestions
See issue #4050 for more details.
Modified:
trunk/reactos/ntoskrnl/ex/sysinfo.c
trunk/reactos/ntoskrnl/include/internal/ob.h
trunk/reactos/ntoskrnl/ob/obhandle.c
trunk/reactos/ntoskrnl/ps/query.c
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] Wed Jan 28 04:32:43 2009
@@ -778,7 +778,7 @@
SpiCurrent->BasePriority = Process->Pcb.BasePriority;
SpiCurrent->UniqueProcessId = Process->UniqueProcessId;
SpiCurrent->InheritedFromUniqueProcessId =
Process->InheritedFromUniqueProcessId;
- SpiCurrent->HandleCount = (Process->ObjectTable ?
ObpGetHandleCountByHandleTable(Process->ObjectTable) : 0);
+ SpiCurrent->HandleCount = ObGetProcessHandleCount(Process);
SpiCurrent->PeakVirtualSize = Process->PeakVirtualSize;
SpiCurrent->VirtualSize = Process->VirtualSize;
SpiCurrent->PageFaultCount = Process->Vm.PageFaultCount;
@@ -1023,7 +1023,7 @@
do
{
- hCount = hCount + (pr->ObjectTable ?
ObpGetHandleCountByHandleTable(pr->ObjectTable) : 0);
+ hCount = hCount + ObGetProcessHandleCount(pr);
pr = PsGetNextProcess(pr);
if ((pr == syspr) || (pr == NULL)) break;
@@ -1059,7 +1059,7 @@
{
int Count = 0, HandleCount;
- HandleCount = (pr->ObjectTable ?
ObpGetHandleCountByHandleTable(pr->ObjectTable) : 0);
+ HandleCount = ObGetProcessHandleCount(pr);
for (Count = 0; HandleCount > 0 ; HandleCount--)
{
Modified: trunk/reactos/ntoskrnl/include/internal/ob.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ob.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/ob.h [iso-8859-1] Wed Jan 28 04:32:43 2009
@@ -71,12 +71,6 @@
(HANDLE)((ULONG_PTR)(Handle) | KERNEL_HANDLE_FLAG)
//
-// Returns the number of handles in a handle table
-//
-#define ObpGetHandleCountByHandleTable(HandleTable) \
- ((PHANDLE_TABLE)HandleTable)->HandleCount
-
-//
// Converts from an EXHANDLE object to a POBJECT_HEADER
//
#define ObpGetHandleObject(x) \
@@ -124,7 +118,7 @@
LIST_ENTRY Link;
ULONG RefCount;
ULONG FullHash;
- QUAD SecurityDescriptor;
+ QUAD SecurityDescriptor;
} SECURITY_DESCRIPTOR_HEADER, *PSECURITY_DESCRIPTOR_HEADER;
//
@@ -568,6 +562,15 @@
IN BOOLEAN AllocateFromLookaside,
IN POBJECT_CREATE_INFORMATION ObjectCreateInfo,
OUT PUNICODE_STRING ObjectName
+);
+
+//
+// Miscellanea
+//
+ULONG
+NTAPI
+ObGetProcessHandleCount(
+ IN PEPROCESS Process
);
//
Modified: trunk/reactos/ntoskrnl/ob/obhandle.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/obhandle.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/ob/obhandle.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ob/obhandle.c [iso-8859-1] Wed Jan 28 04:32:43 2009
@@ -52,6 +52,35 @@
{
/* Release the process lock */
ExReleaseRundownProtection(&Process->RundownProtect);
+}
+
+ULONG
+NTAPI
+ObGetProcessHandleCount(IN PEPROCESS Process)
+{
+ ULONG HandleCount;
+ PHANDLE_TABLE HandleTable;
+
+ ASSERT(Process);
+
+ /* Ensure the handle table doesn't go away while we use it */
+ HandleTable = ObReferenceProcessHandleTable(Process);
+
+ if (HandleTable != NULL)
+ {
+ /* Count the number of handles the process has */
+ HandleCount = HandleTable->HandleCount;
+
+ /* Let the handle table go */
+ ObDereferenceProcessHandleTable(Process);
+ }
+ else
+ {
+ /* No handle table, no handles */
+ HandleCount = 0;
+ }
+
+ return HandleCount;
}
NTSTATUS
Modified: trunk/reactos/ntoskrnl/ps/query.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/query.c?rev=39…
==============================================================================
--- trunk/reactos/ntoskrnl/ps/query.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ps/query.c [iso-8859-1] Wed Jan 28 04:32:43 2009
@@ -237,7 +237,7 @@
}
/* Count the number of handles this process has */
- HandleCount = ObpGetHandleCountByHandleTable(Process->ObjectTable);
+ HandleCount = ObGetProcessHandleCount(Process);
/* Protect write in SEH */
_SEH2_TRY