[NTOS:EX]
[reactos.git] / reactos / ntoskrnl / ex / sysinfo.c
index 54e9e26..15b6c85 100644 (file)
@@ -222,7 +222,7 @@ ExLockUserBuffer(
     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
     {
         ExFreePoolWithTag(Mdl, TAG_MDL);
-        return _SEH2_GetExceptionCode();
+        _SEH2_YIELD(return _SEH2_GetExceptionCode());
     }
     _SEH2_END;
 
@@ -812,6 +812,10 @@ QSI_DEF(SystemProcessInformation)
         {
             SpiCurrent = (PSYSTEM_PROCESS_INFORMATION) Current;
 
+            /* Lock the Process */
+            KeEnterCriticalRegion();
+            ExAcquirePushLockShared(&Process->ProcessLock);
+
             if ((Process->ProcessExiting) &&
                 (Process->Pcb.Header.SignalState) &&
                 !(Process->ActiveThreads) &&
@@ -821,6 +825,10 @@ QSI_DEF(SystemProcessInformation)
                         Process, Process->ImageFileName, Process->UniqueProcessId);
                 CurrentSize = 0;
                 ImageNameMaximumLength = 0;
+
+                /* Unlock the Process */
+                ExReleasePushLockShared(&Process->ProcessLock);
+                KeLeaveCriticalRegion();
                 goto Skip;
             }
 
@@ -955,6 +963,10 @@ QSI_DEF(SystemProcessInformation)
                 ProcessImageName = NULL;
             }
 
+            /* Unlock the Process */
+            ExReleasePushLockShared(&Process->ProcessLock);
+            KeLeaveCriticalRegion();
+
             /* Handle idle process entry */
 Skip:
             if (Process == PsIdleProcess) Process = NULL;
@@ -1171,14 +1183,19 @@ QSI_DEF(SystemNonPagedPoolInformation)
 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 +1216,94 @@ QSI_DEF(SystemHandleInformation)
         return Status;
     }
 
-    _SEH2_TRY
-    {
-        PLIST_ENTRY NextTableEntry;
+    /* Reset of count of handles */
+    HandleInformation->NumberOfHandles = 0;
 
-        /* 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();
+    /* Enter a critical region */
+    KeEnterCriticalRegion();
 
-            /* Acquire the handle table lock */
-            ExAcquirePushLockExclusive(&HandleTableListLock);
+    /* Acquire the handle table lock */
+    ExAcquirePushLockShared(&HandleTableListLock);
 
-            /* Get current handle table */
-            HandleTable = CONTAINING_RECORD(NextTableEntry, HANDLE_TABLE, HandleTableList);
+    /* Enumerate all system handles */
+    for (NextTableEntry = HandleTableListHead.Flink;
+         NextTableEntry != &HandleTableListHead;
+         NextTableEntry = NextTableEntry->Flink)
+    {
+        /* Get current handle table */
+        HandleTable = CONTAINING_RECORD(NextTableEntry, HANDLE_TABLE, HandleTableList);
 
-            _SEH2_TRY
+        /* 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;
+                /* Increase of count of handles */
+                ++HandleInformation->NumberOfHandles;
 
-                /* Set the initial value and loop the entries */
-                Handle.Value = 0;
-                while ((HandleTableEntry = ExpLookupHandleTableEntry(HandleTable, Handle)))
+                /* 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;
                     }
+                    else
+                    {
+                        POBJECT_HEADER ObjectHeader = ObpGetHandleObject(HandleTableEntry);
 
-                    /* Go to the next entry */
-                    Handle.Value += sizeof(HANDLE);
-                }
-            }
-            _SEH2_FINALLY
-            {
-                /* Release the lock */
-                ExReleasePushLockExclusive(&HandleTableListLock);
+                        /* Filling handle information */
+                        HandleInformation->Handles[Index].UniqueProcessId =
+                            (USHORT)(ULONG_PTR) HandleTable->UniqueProcessId;
 
-                /* Leave the critical region */
-                KeLeaveCriticalRegion();
+                        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_END;
 
-            if (!NT_SUCCESS(Status)) break;
+            /* Go to the next entry */
+            Handle.Value += sizeof(HANDLE);
         }
     }
-    _SEH2_FINALLY
-    {
-        /* Release the locked user buffer */
-        ExUnlockUserBuffer(Mdl);
-    }
-    _SEH2_END;
+
+    /* Release the lock */
+    ExReleasePushLockShared(&HandleTableListLock);
+
+    /* Leave the critical region */
+    KeLeaveCriticalRegion();
+
+    /* Release the locked user buffer */
+    ExUnlockUserBuffer(Mdl);
 
     return Status;
 }
@@ -2377,6 +2372,27 @@ QSI_DEF(SystemNumaAvailableMemory)
     return STATUS_SUCCESS;
 }
 
+/* Class 64 - Extended handle information  */
+QSI_DEF(SystemExtendedHandleInformation)
+{
+    PSYSTEM_HANDLE_INFORMATION_EX HandleInformation = (PSYSTEM_HANDLE_INFORMATION_EX)Buffer;
+
+    DPRINT1("NtQuerySystemInformation - SystemExtendedHandleInformation not implemented\n");
+
+    /* Set initial required buffer size */
+    *ReqSize = FIELD_OFFSET(SYSTEM_HANDLE_INFORMATION_EX, Handle);
+
+    /* Validate input size */
+    if (Size < *ReqSize)
+    {
+        return STATUS_INFO_LENGTH_MISMATCH;
+    }
+
+    /* FIXME */
+    HandleInformation->Count = 0;
+    return STATUS_NOT_IMPLEMENTED;
+}
+
 
 /* Query/Set Calls Table */
 typedef
@@ -2460,7 +2476,11 @@ CallQS [] =
     SI_QX(SystemExtendedProcessInformation),
     SI_QX(SystemRecommendedSharedDataAlignment),
     SI_XX(SystemComPlusPackage),
-    SI_QX(SystemNumaAvailableMemory)
+    SI_QX(SystemNumaAvailableMemory),
+    SI_XX(SystemProcessorPowerInformation), /* FIXME: not implemented */
+    SI_XX(SystemEmulationBasicInformation), /* FIXME: not implemented */
+    SI_XX(SystemEmulationProcessorInformation), /* FIXME: not implemented */
+    SI_QX(SystemExtendedHandleInformation),
 };
 
 C_ASSERT(SystemBasicInformation == 0);