Author: dchapyshev
Date: Wed Sep 7 17:34:17 2016
New Revision: 72608
URL:
http://svn.reactos.org/svn/reactos?rev=72608&view=rev
Log:
[NTOS:EX]
- Use ExAcquirePushLockShared instead ExAcquirePushLockExclusive (and move it outside
enumeration)
- Don't leave a enumeration at ReqSize > Size. It is used for calculation of the
size
- ObjectHeader->Type field currupted and I do not know who spoils it. Commented.
- Remove unneeded SEH
Modified:
trunk/reactos/ntoskrnl/ex/sysinfo.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 Sep 7 17:34:17 2016
@@ -222,7 +222,7 @@
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
ExFreePoolWithTag(Mdl, TAG_MDL);
- return _SEH2_GetExceptionCode();
+ _SEH2_YIELD(return _SEH2_GetExceptionCode());
}
_SEH2_END;
@@ -1171,14 +1171,19 @@
QSI_DEF(SystemHandleInformation)
{
PSYSTEM_HANDLE_INFORMATION HandleInformation;
+ PLIST_ENTRY NextTableEntry;
+ PHANDLE_TABLE HandleTable;
+ PHANDLE_TABLE_ENTRY HandleTableEntry;
+ EXHANDLE Handle;
ULONG Index = 0;
NTSTATUS Status;
PMDL Mdl;
+ PAGED_CODE();
DPRINT("NtQuerySystemInformation - SystemHandleInformation\n");
/* Set initial required buffer size */
- *ReqSize = sizeof(SYSTEM_HANDLE_INFORMATION);
+ *ReqSize = FIELD_OFFSET(SYSTEM_HANDLE_INFORMATION, Handles);
/* Check user's buffer size */
if (Size < *ReqSize)
@@ -1199,116 +1204,94 @@
return Status;
}
- _SEH2_TRY
- {
- PLIST_ENTRY NextTableEntry;
-
- /* Reset of count of handles */
- HandleInformation->NumberOfHandles = 0;
-
- /* Enumerate all system handles */
- for (NextTableEntry = HandleTableListHead.Flink;
- NextTableEntry != &HandleTableListHead;
- NextTableEntry = NextTableEntry->Flink)
- {
- PHANDLE_TABLE HandleTable;
-
- /* Enter a critical region */
- KeEnterCriticalRegion();
-
- /* Acquire the handle table lock */
- ExAcquirePushLockExclusive(&HandleTableListLock);
-
- /* Get current handle table */
- HandleTable = CONTAINING_RECORD(NextTableEntry, HANDLE_TABLE,
HandleTableList);
-
- _SEH2_TRY
+ /* Reset of count of handles */
+ HandleInformation->NumberOfHandles = 0;
+
+ /* Enter a critical region */
+ KeEnterCriticalRegion();
+
+ /* Acquire the handle table lock */
+ ExAcquirePushLockShared(&HandleTableListLock);
+
+ /* Enumerate all system handles */
+ for (NextTableEntry = HandleTableListHead.Flink;
+ NextTableEntry != &HandleTableListHead;
+ NextTableEntry = NextTableEntry->Flink)
+ {
+ /* Get current handle table */
+ HandleTable = CONTAINING_RECORD(NextTableEntry, HANDLE_TABLE, HandleTableList);
+
+ /* Set the initial value and loop the entries */
+ Handle.Value = 0;
+ while ((HandleTableEntry = ExpLookupHandleTableEntry(HandleTable, Handle)))
+ {
+ /* Validate the entry */
+ if ((HandleTableEntry->Object) &&
+ (HandleTableEntry->NextFreeTableEntry != -2))
{
- PHANDLE_TABLE_ENTRY HandleTableEntry;
- EXHANDLE Handle;
-
- /* Set the initial value and loop the entries */
- Handle.Value = 0;
- while ((HandleTableEntry = ExpLookupHandleTableEntry(HandleTable,
Handle)))
+ /* Increase of count of handles */
+ ++HandleInformation->NumberOfHandles;
+
+ /* Lock the entry */
+ if (ExpLockHandleTableEntry(HandleTable, HandleTableEntry))
{
- /* Validate the entry */
- if ((HandleTableEntry->Object) &&
- (HandleTableEntry->NextFreeTableEntry != -2))
+ /* Increase required buffer size */
+ *ReqSize += sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO);
+
+ /* Check user's buffer size */
+ if (*ReqSize > Size)
{
- /* Increase of count of handles */
- ++HandleInformation->NumberOfHandles;
-
- /* Increase required buffer size */
- *ReqSize += sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO);
-
- /* Check user's buffer size */
- if (*ReqSize > Size)
- {
- Status = STATUS_INFO_LENGTH_MISMATCH;
- break;
- }
-
- /* Lock the entry */
- if (ExpLockHandleTableEntry(HandleTable, HandleTableEntry))
- {
- _SEH2_TRY
- {
- POBJECT_HEADER ObjectHeader =
ObpGetHandleObject(HandleTableEntry);
-
- /* Filling handle information */
- HandleInformation->Handles[Index].UniqueProcessId =
- (USHORT)(ULONG_PTR) HandleTable->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;
-
- ++Index;
- }
- _SEH2_FINALLY
- {
- /* Unlock it */
- ExUnlockHandleTableEntry(HandleTable, HandleTableEntry);
- }
- _SEH2_END;
- }
+ Status = STATUS_INFO_LENGTH_MISMATCH;
}
-
- /* Go to the next entry */
- Handle.Value += sizeof(HANDLE);
+ else
+ {
+ POBJECT_HEADER ObjectHeader =
ObpGetHandleObject(HandleTableEntry);
+
+ /* Filling handle information */
+ HandleInformation->Handles[Index].UniqueProcessId =
+ (USHORT)(ULONG_PTR) HandleTable->UniqueProcessId;
+
+ HandleInformation->Handles[Index].CreatorBackTraceIndex = 0;
+
+#if 0 /* FIXME!!! Type field currupted */
+ HandleInformation->Handles[Index].ObjectTypeIndex =
+ (UCHAR) ObjectHeader->Type->Index;
+#else
+ HandleInformation->Handles[Index].ObjectTypeIndex = 0;
+#endif
+
+ 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;
+
+ ++Index;
+ }
+
+ /* Unlock it */
+ ExUnlockHandleTableEntry(HandleTable, HandleTableEntry);
}
}
- _SEH2_FINALLY
- {
- /* Release the lock */
- ExReleasePushLockExclusive(&HandleTableListLock);
-
- /* Leave the critical region */
- KeLeaveCriticalRegion();
- }
- _SEH2_END;
-
- if (!NT_SUCCESS(Status)) break;
- }
- }
- _SEH2_FINALLY
- {
- /* Release the locked user buffer */
- ExUnlockUserBuffer(Mdl);
- }
- _SEH2_END;
+
+ /* Go to the next entry */
+ Handle.Value += sizeof(HANDLE);
+ }
+ }
+
+ /* Release the lock */
+ ExReleasePushLockShared(&HandleTableListLock);
+
+ /* Leave the critical region */
+ KeLeaveCriticalRegion();
+
+ /* Release the locked user buffer */
+ ExUnlockUserBuffer(Mdl);
return Status;
}