xref: /reactos/ntoskrnl/ex/sysinfo.c (revision 63977328)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * COPYRIGHT:       See COPYING in the top level directory
3c2c66affSColin Finck  * PROJECT:         ReactOS kernel
4c2c66affSColin Finck  * FILE:            ntoskrnl/ex/sysinfo.c
5c2c66affSColin Finck  * PURPOSE:         System information functions
6c2c66affSColin Finck  *
7c2c66affSColin Finck  * PROGRAMMERS:     David Welch (welch@mcmail.com)
8c2c66affSColin Finck  *                  Aleksey Bragin (aleksey@reactos.org)
9c2c66affSColin Finck  */
10c2c66affSColin Finck 
11c2c66affSColin Finck /* INCLUDES *****************************************************************/
12c2c66affSColin Finck 
13c2c66affSColin Finck #include <ntoskrnl.h>
14d033fe9bSStanislav Motylkov #include <wmidata.h>
15d033fe9bSStanislav Motylkov #include <wmistr.h>
16c2c66affSColin Finck #define NDEBUG
17c2c66affSColin Finck #include <debug.h>
18c2c66affSColin Finck 
19c2c66affSColin Finck /* The maximum size of an environment value (in bytes) */
20c2c66affSColin Finck #define MAX_ENVVAL_SIZE 1024
21c2c66affSColin Finck 
22d033fe9bSStanislav Motylkov #define SIG_ACPI 0x41435049
23d033fe9bSStanislav Motylkov #define SIG_FIRM 0x4649524D
24d033fe9bSStanislav Motylkov #define SIG_RSMB 0x52534D42
25d033fe9bSStanislav Motylkov 
26c2c66affSColin Finck extern LIST_ENTRY HandleTableListHead;
27c2c66affSColin Finck extern EX_PUSH_LOCK HandleTableListLock;
28c2c66affSColin Finck 
29c2c66affSColin Finck FAST_MUTEX ExpEnvironmentLock;
30c2c66affSColin Finck ERESOURCE ExpFirmwareTableResource;
31c2c66affSColin Finck LIST_ENTRY ExpFirmwareTableProviderListHead;
32c2c66affSColin Finck 
33c2c66affSColin Finck FORCEINLINE
34c2c66affSColin Finck NTSTATUS
35c2c66affSColin Finck ExpConvertLdrModuleToRtlModule(IN ULONG ModuleCount,
36c2c66affSColin Finck                                IN PLDR_DATA_TABLE_ENTRY LdrEntry,
37c2c66affSColin Finck                                OUT PRTL_PROCESS_MODULE_INFORMATION ModuleInfo)
38c2c66affSColin Finck {
39c2c66affSColin Finck     PCHAR p;
40c2c66affSColin Finck     NTSTATUS Status;
41c2c66affSColin Finck     ANSI_STRING ModuleName;
42c2c66affSColin Finck 
43c2c66affSColin Finck     /* Fill it out */
44c2c66affSColin Finck     ModuleInfo->MappedBase = NULL;
45c2c66affSColin Finck     ModuleInfo->ImageBase = LdrEntry->DllBase;
46c2c66affSColin Finck     ModuleInfo->ImageSize = LdrEntry->SizeOfImage;
47c2c66affSColin Finck     ModuleInfo->Flags = LdrEntry->Flags;
48c2c66affSColin Finck     ModuleInfo->LoadCount = LdrEntry->LoadCount;
49c2c66affSColin Finck     ModuleInfo->LoadOrderIndex = (USHORT)ModuleCount;
50c2c66affSColin Finck     ModuleInfo->InitOrderIndex = 0;
51c2c66affSColin Finck 
52c2c66affSColin Finck     /* Setup name */
53c2c66affSColin Finck     RtlInitEmptyAnsiString(&ModuleName,
54c2c66affSColin Finck                            ModuleInfo->FullPathName,
55c2c66affSColin Finck                            sizeof(ModuleInfo->FullPathName));
56c2c66affSColin Finck 
57c2c66affSColin Finck     /* Convert it */
58c2c66affSColin Finck     Status = RtlUnicodeStringToAnsiString(&ModuleName,
59c2c66affSColin Finck                                           &LdrEntry->FullDllName,
60c2c66affSColin Finck                                           FALSE);
61c2c66affSColin Finck     if ((NT_SUCCESS(Status)) || (Status == STATUS_BUFFER_OVERFLOW))
62c2c66affSColin Finck     {
63c2c66affSColin Finck         /* Calculate offset to name */
64c2c66affSColin Finck         p = ModuleName.Buffer + ModuleName.Length;
65c2c66affSColin Finck         while ((p > ModuleName.Buffer) && (*--p))
66c2c66affSColin Finck         {
67c2c66affSColin Finck             /* Check if we found the separator */
68c2c66affSColin Finck             if (*p == OBJ_NAME_PATH_SEPARATOR)
69c2c66affSColin Finck             {
70c2c66affSColin Finck                 /* We did, break out */
71c2c66affSColin Finck                 p++;
72c2c66affSColin Finck                 break;
73c2c66affSColin Finck             }
74c2c66affSColin Finck         }
75c2c66affSColin Finck 
76c2c66affSColin Finck         /* Set the offset */
77c2c66affSColin Finck         ModuleInfo->OffsetToFileName = (USHORT)(p - ModuleName.Buffer);
78c2c66affSColin Finck     }
79c2c66affSColin Finck     else
80c2c66affSColin Finck     {
81c2c66affSColin Finck         /* Return empty name */
82c2c66affSColin Finck         ModuleInfo->FullPathName[0] = ANSI_NULL;
83c2c66affSColin Finck         ModuleInfo->OffsetToFileName = 0;
84c2c66affSColin Finck     }
85c2c66affSColin Finck 
86c2c66affSColin Finck     return Status;
87c2c66affSColin Finck }
88c2c66affSColin Finck 
89c2c66affSColin Finck NTSTATUS
90c2c66affSColin Finck NTAPI
91c2c66affSColin Finck ExpQueryModuleInformation(IN PLIST_ENTRY KernelModeList,
92c2c66affSColin Finck                           IN PLIST_ENTRY UserModeList,
93c2c66affSColin Finck                           OUT PRTL_PROCESS_MODULES Modules,
94c2c66affSColin Finck                           IN ULONG Length,
95c2c66affSColin Finck                           OUT PULONG ReturnLength)
96c2c66affSColin Finck {
97c2c66affSColin Finck     NTSTATUS Status = STATUS_SUCCESS;
98c2c66affSColin Finck     ULONG RequiredLength;
99c2c66affSColin Finck     PRTL_PROCESS_MODULE_INFORMATION ModuleInfo;
100c2c66affSColin Finck     PLDR_DATA_TABLE_ENTRY LdrEntry;
101c2c66affSColin Finck     ULONG ModuleCount = 0;
102c2c66affSColin Finck     PLIST_ENTRY NextEntry;
103c2c66affSColin Finck 
104c2c66affSColin Finck     /* Setup defaults */
105c2c66affSColin Finck     RequiredLength = FIELD_OFFSET(RTL_PROCESS_MODULES, Modules);
106c2c66affSColin Finck     ModuleInfo = &Modules->Modules[0];
107c2c66affSColin Finck 
108c2c66affSColin Finck     /* Loop the kernel list */
109c2c66affSColin Finck     NextEntry = KernelModeList->Flink;
110c2c66affSColin Finck     while (NextEntry != KernelModeList)
111c2c66affSColin Finck     {
112c2c66affSColin Finck         /* Get the entry */
113c2c66affSColin Finck         LdrEntry = CONTAINING_RECORD(NextEntry,
114c2c66affSColin Finck                                      LDR_DATA_TABLE_ENTRY,
115c2c66affSColin Finck                                      InLoadOrderLinks);
116c2c66affSColin Finck 
117c2c66affSColin Finck         /* Update size and check if we can manage one more entry */
118c2c66affSColin Finck         RequiredLength += sizeof(RTL_PROCESS_MODULE_INFORMATION);
119c2c66affSColin Finck         if (Length >= RequiredLength)
120c2c66affSColin Finck         {
121c2c66affSColin Finck             Status = ExpConvertLdrModuleToRtlModule(ModuleCount,
122c2c66affSColin Finck                                                     LdrEntry,
123c2c66affSColin Finck                                                     ModuleInfo);
124c2c66affSColin Finck 
125c2c66affSColin Finck             /* Go to the next module */
126c2c66affSColin Finck             ModuleInfo++;
127c2c66affSColin Finck         }
128c2c66affSColin Finck         else
129c2c66affSColin Finck         {
130c2c66affSColin Finck             /* Set error code */
131c2c66affSColin Finck             Status = STATUS_INFO_LENGTH_MISMATCH;
132c2c66affSColin Finck         }
133c2c66affSColin Finck 
134c2c66affSColin Finck         /* Update count and move to next entry */
135c2c66affSColin Finck         ModuleCount++;
136c2c66affSColin Finck         NextEntry = NextEntry->Flink;
137c2c66affSColin Finck     }
138c2c66affSColin Finck 
139c2c66affSColin Finck     /* Check if caller also wanted user modules */
140c2c66affSColin Finck     if (UserModeList)
141c2c66affSColin Finck     {
142c2c66affSColin Finck         NextEntry = UserModeList->Flink;
143c2c66affSColin Finck         while (NextEntry != UserModeList)
144c2c66affSColin Finck         {
145c2c66affSColin Finck             /* Get the entry */
146c2c66affSColin Finck             LdrEntry = CONTAINING_RECORD(NextEntry,
147c2c66affSColin Finck                                          LDR_DATA_TABLE_ENTRY,
148c2c66affSColin Finck                                          InLoadOrderLinks);
149c2c66affSColin Finck 
150c2c66affSColin Finck             /* Update size and check if we can manage one more entry */
151c2c66affSColin Finck             RequiredLength += sizeof(RTL_PROCESS_MODULE_INFORMATION);
152c2c66affSColin Finck             if (Length >= RequiredLength)
153c2c66affSColin Finck             {
154c2c66affSColin Finck                 Status = ExpConvertLdrModuleToRtlModule(ModuleCount,
155c2c66affSColin Finck                                                         LdrEntry,
156c2c66affSColin Finck                                                         ModuleInfo);
157c2c66affSColin Finck 
158c2c66affSColin Finck                 /* Go to the next module */
159c2c66affSColin Finck                 ModuleInfo++;
160c2c66affSColin Finck             }
161c2c66affSColin Finck             else
162c2c66affSColin Finck             {
163c2c66affSColin Finck                 /* Set error code */
164c2c66affSColin Finck                 Status = STATUS_INFO_LENGTH_MISMATCH;
165c2c66affSColin Finck             }
166c2c66affSColin Finck 
167c2c66affSColin Finck             /* Update count and move to next entry */
168c2c66affSColin Finck             ModuleCount++;
169c2c66affSColin Finck             NextEntry = NextEntry->Flink;
170c2c66affSColin Finck         }
171c2c66affSColin Finck     }
172c2c66affSColin Finck 
173c2c66affSColin Finck     /* Update return length */
174c2c66affSColin Finck     if (ReturnLength) *ReturnLength = RequiredLength;
175c2c66affSColin Finck 
176c2c66affSColin Finck     /* Validate the length again */
177c2c66affSColin Finck     if (Length >= FIELD_OFFSET(RTL_PROCESS_MODULES, Modules))
178c2c66affSColin Finck     {
179c2c66affSColin Finck         /* Set the final count */
180c2c66affSColin Finck         Modules->NumberOfModules = ModuleCount;
181c2c66affSColin Finck     }
182c2c66affSColin Finck     else
183c2c66affSColin Finck     {
184c2c66affSColin Finck         /* Otherwise, we failed */
185c2c66affSColin Finck         Status = STATUS_INFO_LENGTH_MISMATCH;
186c2c66affSColin Finck     }
187c2c66affSColin Finck 
188c2c66affSColin Finck     /* Done */
189c2c66affSColin Finck     return Status;
190c2c66affSColin Finck }
191c2c66affSColin Finck 
192c2c66affSColin Finck VOID
193c2c66affSColin Finck NTAPI
194c2c66affSColin Finck ExUnlockUserBuffer(PMDL Mdl)
195c2c66affSColin Finck {
196c2c66affSColin Finck     MmUnlockPages(Mdl);
197c2c66affSColin Finck     ExFreePoolWithTag(Mdl, TAG_MDL);
198c2c66affSColin Finck }
199c2c66affSColin Finck 
200c2c66affSColin Finck NTSTATUS
201c2c66affSColin Finck NTAPI
202c2c66affSColin Finck ExLockUserBuffer(
203c2c66affSColin Finck     PVOID BaseAddress,
204c2c66affSColin Finck     ULONG Length,
205c2c66affSColin Finck     KPROCESSOR_MODE AccessMode,
206c2c66affSColin Finck     LOCK_OPERATION Operation,
207c2c66affSColin Finck     PVOID *MappedSystemVa,
208c2c66affSColin Finck     PMDL *OutMdl)
209c2c66affSColin Finck {
210c2c66affSColin Finck     PMDL Mdl;
211c2c66affSColin Finck     PAGED_CODE();
212c2c66affSColin Finck 
213c2c66affSColin Finck     *MappedSystemVa = NULL;
214c2c66affSColin Finck     *OutMdl = NULL;
215c2c66affSColin Finck 
216c2c66affSColin Finck     /* Allocate an MDL for the buffer */
217c2c66affSColin Finck     Mdl = IoAllocateMdl(BaseAddress, Length, FALSE, TRUE, NULL);
218c2c66affSColin Finck     if (Mdl == NULL)
219c2c66affSColin Finck     {
220c2c66affSColin Finck         return STATUS_INSUFFICIENT_RESOURCES;
221c2c66affSColin Finck     }
222c2c66affSColin Finck 
223c2c66affSColin Finck     /* Enter SEH for probing */
224c2c66affSColin Finck     _SEH2_TRY
225c2c66affSColin Finck     {
226c2c66affSColin Finck         MmProbeAndLockPages(Mdl, AccessMode, Operation);
227c2c66affSColin Finck     }
228c2c66affSColin Finck     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
229c2c66affSColin Finck     {
230c2c66affSColin Finck         ExFreePoolWithTag(Mdl, TAG_MDL);
231c2c66affSColin Finck         _SEH2_YIELD(return _SEH2_GetExceptionCode());
232c2c66affSColin Finck     }
233c2c66affSColin Finck     _SEH2_END;
234c2c66affSColin Finck 
235c2c66affSColin Finck     /* Return the safe kernel mode buffer */
236c2c66affSColin Finck     *MappedSystemVa = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
237c2c66affSColin Finck     if (*MappedSystemVa == NULL)
238c2c66affSColin Finck     {
239c2c66affSColin Finck         ExUnlockUserBuffer(Mdl);
240c2c66affSColin Finck         return STATUS_INSUFFICIENT_RESOURCES;
241c2c66affSColin Finck     }
242c2c66affSColin Finck 
243c2c66affSColin Finck     /* Return the MDL */
244c2c66affSColin Finck     *OutMdl = Mdl;
245c2c66affSColin Finck     return STATUS_SUCCESS;
246c2c66affSColin Finck }
247c2c66affSColin Finck 
248d033fe9bSStanislav Motylkov NTSTATUS
249d033fe9bSStanislav Motylkov NTAPI
250d033fe9bSStanislav Motylkov ExpGetRawSMBiosTable(
251d033fe9bSStanislav Motylkov     _Out_opt_ PVOID Buffer,
252d033fe9bSStanislav Motylkov     _Out_ ULONG * OutSize,
253d033fe9bSStanislav Motylkov     _In_ ULONG BufferSize)
254d033fe9bSStanislav Motylkov {
255d033fe9bSStanislav Motylkov     NTSTATUS Status;
256d033fe9bSStanislav Motylkov     PVOID DataBlockObject;
257d033fe9bSStanislav Motylkov     PWNODE_ALL_DATA AllData;
258d033fe9bSStanislav Motylkov     ULONG WMIBufSize;
259d033fe9bSStanislav Motylkov 
260d033fe9bSStanislav Motylkov     ASSERT(OutSize != NULL);
261d033fe9bSStanislav Motylkov     *OutSize = 0;
262d033fe9bSStanislav Motylkov 
263d033fe9bSStanislav Motylkov     /* Open the data block object for the SMBIOS table */
264d033fe9bSStanislav Motylkov     Status = IoWMIOpenBlock(&MSSmBios_RawSMBiosTables_GUID,
265d033fe9bSStanislav Motylkov                             WMIGUID_QUERY,
266d033fe9bSStanislav Motylkov                             &DataBlockObject);
267d033fe9bSStanislav Motylkov     if (!NT_SUCCESS(Status))
268d033fe9bSStanislav Motylkov     {
269d033fe9bSStanislav Motylkov         DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
270d033fe9bSStanislav Motylkov         return Status;
271d033fe9bSStanislav Motylkov     }
272d033fe9bSStanislav Motylkov 
273d033fe9bSStanislav Motylkov     /* Query the required buffer size */
274d033fe9bSStanislav Motylkov     WMIBufSize = 0;
275d033fe9bSStanislav Motylkov     Status = IoWMIQueryAllData(DataBlockObject, &WMIBufSize, NULL);
276d033fe9bSStanislav Motylkov     if (!NT_SUCCESS(Status))
277d033fe9bSStanislav Motylkov     {
278d033fe9bSStanislav Motylkov         DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
279d033fe9bSStanislav Motylkov         return Status;
280d033fe9bSStanislav Motylkov     }
281d033fe9bSStanislav Motylkov 
282d033fe9bSStanislav Motylkov     AllData = ExAllocatePoolWithTag(PagedPool, WMIBufSize, 'itfS');
283d033fe9bSStanislav Motylkov     if (AllData == NULL)
284d033fe9bSStanislav Motylkov     {
285d033fe9bSStanislav Motylkov         DPRINT1("Failed to allocate %lu bytes for SMBIOS tables\n", WMIBufSize);
286d033fe9bSStanislav Motylkov         return STATUS_INSUFFICIENT_RESOURCES;
287d033fe9bSStanislav Motylkov     }
288d033fe9bSStanislav Motylkov 
289d033fe9bSStanislav Motylkov     /* Query the buffer data */
290d033fe9bSStanislav Motylkov     Status = IoWMIQueryAllData(DataBlockObject, &WMIBufSize, AllData);
291d033fe9bSStanislav Motylkov     if (!NT_SUCCESS(Status))
292d033fe9bSStanislav Motylkov     {
293d033fe9bSStanislav Motylkov         DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
294d033fe9bSStanislav Motylkov         ExFreePoolWithTag(AllData, 'itfS');
295d033fe9bSStanislav Motylkov         return Status;
296d033fe9bSStanislav Motylkov     }
297d033fe9bSStanislav Motylkov 
298d033fe9bSStanislav Motylkov     Status = STATUS_SUCCESS;
299d033fe9bSStanislav Motylkov     *OutSize = AllData->FixedInstanceSize;
300d033fe9bSStanislav Motylkov     if (Buffer != NULL)
301d033fe9bSStanislav Motylkov     {
302d033fe9bSStanislav Motylkov         if (BufferSize >= *OutSize)
303d033fe9bSStanislav Motylkov         {
304d033fe9bSStanislav Motylkov             RtlMoveMemory(Buffer, AllData + 1, *OutSize);
305d033fe9bSStanislav Motylkov         }
306d033fe9bSStanislav Motylkov         else
307d033fe9bSStanislav Motylkov         {
308d033fe9bSStanislav Motylkov             Status = STATUS_BUFFER_TOO_SMALL;
309d033fe9bSStanislav Motylkov         }
310d033fe9bSStanislav Motylkov     }
311d033fe9bSStanislav Motylkov 
312d033fe9bSStanislav Motylkov     /* Free the buffer */
313d033fe9bSStanislav Motylkov     ExFreePoolWithTag(AllData, 'itfS');
314d033fe9bSStanislav Motylkov     return Status;
315d033fe9bSStanislav Motylkov }
316d033fe9bSStanislav Motylkov 
317c2c66affSColin Finck /* FUNCTIONS *****************************************************************/
318c2c66affSColin Finck 
319c2c66affSColin Finck /*
320c2c66affSColin Finck  * @implemented
321c2c66affSColin Finck  */
322c2c66affSColin Finck VOID
323c2c66affSColin Finck NTAPI
324c2c66affSColin Finck ExGetCurrentProcessorCpuUsage(PULONG CpuUsage)
325c2c66affSColin Finck {
326c2c66affSColin Finck     PKPRCB Prcb;
327c2c66affSColin Finck     ULONG TotalTime;
328c2c66affSColin Finck     ULONGLONG ScaledIdle;
329c2c66affSColin Finck 
330c2c66affSColin Finck     Prcb = KeGetCurrentPrcb();
331c2c66affSColin Finck 
332c2c66affSColin Finck     ScaledIdle = (ULONGLONG)Prcb->IdleThread->KernelTime * 100;
333c2c66affSColin Finck     TotalTime = Prcb->KernelTime + Prcb->UserTime;
334c2c66affSColin Finck     if (TotalTime != 0)
335c2c66affSColin Finck         *CpuUsage = (ULONG)(100 - (ScaledIdle / TotalTime));
336c2c66affSColin Finck     else
337c2c66affSColin Finck         *CpuUsage = 0;
338c2c66affSColin Finck }
339c2c66affSColin Finck 
340c2c66affSColin Finck /*
341c2c66affSColin Finck  * @implemented
342c2c66affSColin Finck  */
343c2c66affSColin Finck VOID
344c2c66affSColin Finck NTAPI
345c2c66affSColin Finck ExGetCurrentProcessorCounts(PULONG ThreadKernelTime,
346c2c66affSColin Finck                             PULONG TotalCpuTime,
347c2c66affSColin Finck                             PULONG ProcessorNumber)
348c2c66affSColin Finck {
349c2c66affSColin Finck     PKPRCB Prcb;
350c2c66affSColin Finck 
351c2c66affSColin Finck     Prcb = KeGetCurrentPrcb();
352c2c66affSColin Finck 
353c2c66affSColin Finck     *ThreadKernelTime = Prcb->KernelTime + Prcb->UserTime;
354c2c66affSColin Finck     *TotalCpuTime = Prcb->CurrentThread->KernelTime;
355c2c66affSColin Finck     *ProcessorNumber = KeGetCurrentProcessorNumber();
356c2c66affSColin Finck }
357c2c66affSColin Finck 
358c2c66affSColin Finck /*
359c2c66affSColin Finck  * @implemented
360c2c66affSColin Finck  */
361c2c66affSColin Finck BOOLEAN
362c2c66affSColin Finck NTAPI
363c2c66affSColin Finck ExIsProcessorFeaturePresent(IN ULONG ProcessorFeature)
364c2c66affSColin Finck {
365c2c66affSColin Finck     /* Quick check to see if it exists at all */
366c2c66affSColin Finck     if (ProcessorFeature >= PROCESSOR_FEATURE_MAX) return(FALSE);
367c2c66affSColin Finck 
368c2c66affSColin Finck     /* Return our support for it */
369c2c66affSColin Finck     return(SharedUserData->ProcessorFeatures[ProcessorFeature]);
370c2c66affSColin Finck }
371c2c66affSColin Finck 
372c2c66affSColin Finck /*
373c2c66affSColin Finck  * @implemented
374c2c66affSColin Finck  */
375c2c66affSColin Finck BOOLEAN
376c2c66affSColin Finck NTAPI
377c2c66affSColin Finck ExVerifySuite(SUITE_TYPE SuiteType)
378c2c66affSColin Finck {
379c2c66affSColin Finck     if (SuiteType == Personal) return TRUE;
380c2c66affSColin Finck     return FALSE;
381c2c66affSColin Finck }
382c2c66affSColin Finck 
383c2c66affSColin Finck NTSTATUS
384c2c66affSColin Finck NTAPI
385c2c66affSColin Finck NtQuerySystemEnvironmentValue(IN PUNICODE_STRING VariableName,
386c2c66affSColin Finck                               OUT PWSTR ValueBuffer,
387c2c66affSColin Finck                               IN ULONG ValueBufferLength,
388c2c66affSColin Finck                               IN OUT PULONG ReturnLength OPTIONAL)
389c2c66affSColin Finck {
390c2c66affSColin Finck     ANSI_STRING AName;
391c2c66affSColin Finck     UNICODE_STRING WName;
392c2c66affSColin Finck     ARC_STATUS Result;
393c2c66affSColin Finck     PCH AnsiValueBuffer;
394c2c66affSColin Finck     ANSI_STRING AValue;
395c2c66affSColin Finck     UNICODE_STRING WValue;
396c2c66affSColin Finck     KPROCESSOR_MODE PreviousMode;
397c2c66affSColin Finck     NTSTATUS Status;
398c2c66affSColin Finck     PAGED_CODE();
399c2c66affSColin Finck 
400c2c66affSColin Finck     /* Check if the call came from user mode */
401c2c66affSColin Finck     PreviousMode = ExGetPreviousMode();
402c2c66affSColin Finck     if (PreviousMode != KernelMode)
403c2c66affSColin Finck     {
404c2c66affSColin Finck         _SEH2_TRY
405c2c66affSColin Finck         {
406c2c66affSColin Finck             /* Probe the input and output buffers */
407c2c66affSColin Finck             ProbeForRead(VariableName, sizeof(UNICODE_STRING), sizeof(ULONG));
408c2c66affSColin Finck             ProbeForWrite(ValueBuffer, ValueBufferLength, sizeof(WCHAR));
409c2c66affSColin Finck             if (ReturnLength != NULL) ProbeForWriteUlong(ReturnLength);
410c2c66affSColin Finck         }
411c2c66affSColin Finck         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
412c2c66affSColin Finck         {
413c2c66affSColin Finck             /* Return the exception code */
414c2c66affSColin Finck             _SEH2_YIELD(return _SEH2_GetExceptionCode());
415c2c66affSColin Finck         }
416c2c66affSColin Finck         _SEH2_END;
417c2c66affSColin Finck     }
418c2c66affSColin Finck 
419c2c66affSColin Finck     /* According to NTInternals the SeSystemEnvironmentName privilege is required! */
420c2c66affSColin Finck     if (!SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege, PreviousMode))
421c2c66affSColin Finck     {
422c2c66affSColin Finck         DPRINT1("NtQuerySystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
423c2c66affSColin Finck         return STATUS_PRIVILEGE_NOT_HELD;
424c2c66affSColin Finck     }
425c2c66affSColin Finck 
426c2c66affSColin Finck     /* Copy the name to kernel space if necessary */
427c2c66affSColin Finck     Status = ProbeAndCaptureUnicodeString(&WName, PreviousMode, VariableName);
428c2c66affSColin Finck     if (!NT_SUCCESS(Status)) return Status;
429c2c66affSColin Finck 
430c2c66affSColin Finck     /* Convert the name to ANSI and release the captured UNICODE string */
431c2c66affSColin Finck     Status = RtlUnicodeStringToAnsiString(&AName, &WName, TRUE);
432c2c66affSColin Finck     ReleaseCapturedUnicodeString(&WName, PreviousMode);
433c2c66affSColin Finck     if (!NT_SUCCESS(Status)) return Status;
434c2c66affSColin Finck 
435c2c66affSColin Finck     /* Allocate a buffer for the ANSI environment variable */
436c2c66affSColin Finck     AnsiValueBuffer = ExAllocatePoolWithTag(NonPagedPool, MAX_ENVVAL_SIZE, 'rvnE');
437c2c66affSColin Finck     if (AnsiValueBuffer == NULL)
438c2c66affSColin Finck     {
439c2c66affSColin Finck         RtlFreeAnsiString(&AName);
440c2c66affSColin Finck         return STATUS_INSUFFICIENT_RESOURCES;
441c2c66affSColin Finck     }
442c2c66affSColin Finck 
443c2c66affSColin Finck     /* Get the environment variable and free the ANSI name */
444c2c66affSColin Finck     Result = HalGetEnvironmentVariable(AName.Buffer,
445c2c66affSColin Finck                                        MAX_ENVVAL_SIZE,
446c2c66affSColin Finck                                        AnsiValueBuffer);
447c2c66affSColin Finck     RtlFreeAnsiString(&AName);
448c2c66affSColin Finck 
449c2c66affSColin Finck     /* Check if we had success */
450c2c66affSColin Finck     if (Result == ESUCCESS)
451c2c66affSColin Finck     {
452c2c66affSColin Finck         /* Copy the result back to the caller. */
453c2c66affSColin Finck         _SEH2_TRY
454c2c66affSColin Finck         {
455c2c66affSColin Finck             /* Initialize ANSI string from the result */
456c2c66affSColin Finck             RtlInitAnsiString(&AValue, AnsiValueBuffer);
457c2c66affSColin Finck 
458c2c66affSColin Finck             /* Initialize a UNICODE string from the callers buffer */
459c2c66affSColin Finck             RtlInitEmptyUnicodeString(&WValue, ValueBuffer, (USHORT)ValueBufferLength);
460c2c66affSColin Finck 
461c2c66affSColin Finck             /* Convert the result to UNICODE */
462c2c66affSColin Finck             Status = RtlAnsiStringToUnicodeString(&WValue, &AValue, FALSE);
463c2c66affSColin Finck 
464c2c66affSColin Finck             if (ReturnLength != NULL)
465c2c66affSColin Finck                 *ReturnLength = WValue.Length;
466c2c66affSColin Finck         }
467c2c66affSColin Finck         _SEH2_EXCEPT(ExSystemExceptionFilter())
468c2c66affSColin Finck         {
469c2c66affSColin Finck             Status = _SEH2_GetExceptionCode();
470c2c66affSColin Finck         }
471c2c66affSColin Finck         _SEH2_END;
472c2c66affSColin Finck     }
473c2c66affSColin Finck     else
474c2c66affSColin Finck     {
475c2c66affSColin Finck         Status = STATUS_UNSUCCESSFUL;
476c2c66affSColin Finck     }
477c2c66affSColin Finck 
478c2c66affSColin Finck     /* Free the allocated ANSI value buffer */
479c2c66affSColin Finck     ExFreePoolWithTag(AnsiValueBuffer, 'rvnE');
480c2c66affSColin Finck 
481c2c66affSColin Finck     return Status;
482c2c66affSColin Finck }
483c2c66affSColin Finck 
484c2c66affSColin Finck 
485c2c66affSColin Finck NTSTATUS
486c2c66affSColin Finck NTAPI
487c2c66affSColin Finck NtSetSystemEnvironmentValue(IN PUNICODE_STRING VariableName,
488c2c66affSColin Finck                             IN PUNICODE_STRING Value)
489c2c66affSColin Finck {
490c2c66affSColin Finck     UNICODE_STRING CapturedName, CapturedValue;
491c2c66affSColin Finck     ANSI_STRING AName, AValue;
492c2c66affSColin Finck     KPROCESSOR_MODE PreviousMode;
493c2c66affSColin Finck     NTSTATUS Status;
494c2c66affSColin Finck 
495c2c66affSColin Finck     PAGED_CODE();
496c2c66affSColin Finck 
497c2c66affSColin Finck     PreviousMode = ExGetPreviousMode();
498c2c66affSColin Finck 
499c2c66affSColin Finck     /*
500c2c66affSColin Finck      * Copy the strings to kernel space if necessary
501c2c66affSColin Finck      */
502c2c66affSColin Finck     Status = ProbeAndCaptureUnicodeString(&CapturedName,
503c2c66affSColin Finck                                           PreviousMode,
504c2c66affSColin Finck                                           VariableName);
505c2c66affSColin Finck     if (NT_SUCCESS(Status))
506c2c66affSColin Finck     {
507c2c66affSColin Finck         Status = ProbeAndCaptureUnicodeString(&CapturedValue,
508c2c66affSColin Finck                                               PreviousMode,
509c2c66affSColin Finck                                               Value);
510c2c66affSColin Finck         if (NT_SUCCESS(Status))
511c2c66affSColin Finck         {
512c2c66affSColin Finck             /*
513c2c66affSColin Finck              * according to ntinternals the SeSystemEnvironmentName privilege is required!
514c2c66affSColin Finck              */
515c2c66affSColin Finck             if (SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege,
516c2c66affSColin Finck                                        PreviousMode))
517c2c66affSColin Finck             {
518c2c66affSColin Finck                 /*
519c2c66affSColin Finck                  * convert the strings to ANSI
520c2c66affSColin Finck                  */
521c2c66affSColin Finck                 Status = RtlUnicodeStringToAnsiString(&AName,
522c2c66affSColin Finck                                                       &CapturedName,
523c2c66affSColin Finck                                                       TRUE);
524c2c66affSColin Finck                 if (NT_SUCCESS(Status))
525c2c66affSColin Finck                 {
526c2c66affSColin Finck                     Status = RtlUnicodeStringToAnsiString(&AValue,
527c2c66affSColin Finck                                                           &CapturedValue,
528c2c66affSColin Finck                                                           TRUE);
529c2c66affSColin Finck                     if (NT_SUCCESS(Status))
530c2c66affSColin Finck                     {
531c2c66affSColin Finck                         ARC_STATUS Result = HalSetEnvironmentVariable(AName.Buffer,
532c2c66affSColin Finck                                                                       AValue.Buffer);
533c2c66affSColin Finck 
534c2c66affSColin Finck                         Status = (Result ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
535c2c66affSColin Finck                     }
536c2c66affSColin Finck                 }
537c2c66affSColin Finck             }
538c2c66affSColin Finck             else
539c2c66affSColin Finck             {
540c2c66affSColin Finck                 DPRINT1("NtSetSystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
541c2c66affSColin Finck                 Status = STATUS_PRIVILEGE_NOT_HELD;
542c2c66affSColin Finck             }
543c2c66affSColin Finck 
544c2c66affSColin Finck             ReleaseCapturedUnicodeString(&CapturedValue,
545c2c66affSColin Finck                                          PreviousMode);
546c2c66affSColin Finck         }
547c2c66affSColin Finck 
548c2c66affSColin Finck         ReleaseCapturedUnicodeString(&CapturedName,
549c2c66affSColin Finck                                      PreviousMode);
550c2c66affSColin Finck     }
551c2c66affSColin Finck 
552c2c66affSColin Finck     return Status;
553c2c66affSColin Finck }
554c2c66affSColin Finck 
555c2c66affSColin Finck NTSTATUS
556c2c66affSColin Finck NTAPI
557c2c66affSColin Finck NtEnumerateSystemEnvironmentValuesEx(IN ULONG InformationClass,
558c2c66affSColin Finck                                      IN PVOID Buffer,
559c2c66affSColin Finck                                      IN ULONG BufferLength)
560c2c66affSColin Finck {
561c2c66affSColin Finck     UNIMPLEMENTED;
562c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
563c2c66affSColin Finck }
564c2c66affSColin Finck 
565c2c66affSColin Finck NTSTATUS
566c2c66affSColin Finck NTAPI
567c2c66affSColin Finck NtQuerySystemEnvironmentValueEx(IN PUNICODE_STRING VariableName,
568c2c66affSColin Finck                                 IN LPGUID VendorGuid,
569c2c66affSColin Finck                                 IN PVOID Value,
570c2c66affSColin Finck                                 IN OUT PULONG ReturnLength,
571c2c66affSColin Finck                                 IN OUT PULONG Attributes)
572c2c66affSColin Finck {
573c2c66affSColin Finck     UNIMPLEMENTED;
574c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
575c2c66affSColin Finck }
576c2c66affSColin Finck 
577c2c66affSColin Finck NTSTATUS
578c2c66affSColin Finck NTAPI
579c2c66affSColin Finck NtSetSystemEnvironmentValueEx(IN PUNICODE_STRING VariableName,
580c2c66affSColin Finck                               IN LPGUID VendorGuid,
581c2c66affSColin Finck                               IN PVOID Value,
582c2c66affSColin Finck                               IN OUT PULONG ReturnLength,
583c2c66affSColin Finck                               IN OUT PULONG Attributes)
584c2c66affSColin Finck {
585c2c66affSColin Finck     UNIMPLEMENTED;
586c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
587c2c66affSColin Finck }
588c2c66affSColin Finck 
589c2c66affSColin Finck /* --- Query/Set System Information --- */
590c2c66affSColin Finck 
591c2c66affSColin Finck /*
592c2c66affSColin Finck  * NOTE: QSI_DEF(n) and SSI_DEF(n) define _cdecl function symbols
593c2c66affSColin Finck  * so the stack is popped only in one place on x86 platform.
594c2c66affSColin Finck  */
595c2c66affSColin Finck #define QSI_USE(n) QSI##n
596c2c66affSColin Finck #define QSI_DEF(n) \
597c2c66affSColin Finck static NTSTATUS QSI_USE(n) (PVOID Buffer, ULONG Size, PULONG ReqSize)
598c2c66affSColin Finck 
599c2c66affSColin Finck #define SSI_USE(n) SSI##n
600c2c66affSColin Finck #define SSI_DEF(n) \
601c2c66affSColin Finck static NTSTATUS SSI_USE(n) (PVOID Buffer, ULONG Size)
602c2c66affSColin Finck 
603c2c66affSColin Finck VOID
604c2c66affSColin Finck NTAPI
605c2c66affSColin Finck ExQueryPoolUsage(OUT PULONG PagedPoolPages,
606c2c66affSColin Finck                  OUT PULONG NonPagedPoolPages,
607c2c66affSColin Finck                  OUT PULONG PagedPoolAllocs,
608c2c66affSColin Finck                  OUT PULONG PagedPoolFrees,
609c2c66affSColin Finck                  OUT PULONG PagedPoolLookasideHits,
610c2c66affSColin Finck                  OUT PULONG NonPagedPoolAllocs,
611c2c66affSColin Finck                  OUT PULONG NonPagedPoolFrees,
612c2c66affSColin Finck                  OUT PULONG NonPagedPoolLookasideHits);
613c2c66affSColin Finck 
614c2c66affSColin Finck /* Class 0 - Basic Information */
615c2c66affSColin Finck QSI_DEF(SystemBasicInformation)
616c2c66affSColin Finck {
617c2c66affSColin Finck     PSYSTEM_BASIC_INFORMATION Sbi
618c2c66affSColin Finck         = (PSYSTEM_BASIC_INFORMATION) Buffer;
619c2c66affSColin Finck 
620c2c66affSColin Finck     *ReqSize = sizeof(SYSTEM_BASIC_INFORMATION);
621c2c66affSColin Finck 
622c2c66affSColin Finck     /* Check user buffer's size */
623c2c66affSColin Finck     if (Size != sizeof(SYSTEM_BASIC_INFORMATION))
624c2c66affSColin Finck     {
625c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
626c2c66affSColin Finck     }
627c2c66affSColin Finck 
628c2c66affSColin Finck     RtlZeroMemory(Sbi, Size);
629c2c66affSColin Finck     Sbi->Reserved = 0;
630c2c66affSColin Finck     Sbi->TimerResolution = KeMaximumIncrement;
631c2c66affSColin Finck     Sbi->PageSize = PAGE_SIZE;
632c2c66affSColin Finck     Sbi->NumberOfPhysicalPages = MmNumberOfPhysicalPages;
633c2c66affSColin Finck     Sbi->LowestPhysicalPageNumber = (ULONG)MmLowestPhysicalPage;
634c2c66affSColin Finck     Sbi->HighestPhysicalPageNumber = (ULONG)MmHighestPhysicalPage;
635c2c66affSColin Finck     Sbi->AllocationGranularity = MM_VIRTMEM_GRANULARITY; /* hard coded on Intel? */
636c2c66affSColin Finck     Sbi->MinimumUserModeAddress = 0x10000; /* Top of 64k */
637c2c66affSColin Finck     Sbi->MaximumUserModeAddress = (ULONG_PTR)MmHighestUserAddress;
638c2c66affSColin Finck     Sbi->ActiveProcessorsAffinityMask = KeActiveProcessors;
639c2c66affSColin Finck     Sbi->NumberOfProcessors = KeNumberProcessors;
640c2c66affSColin Finck 
641c2c66affSColin Finck     return STATUS_SUCCESS;
642c2c66affSColin Finck }
643c2c66affSColin Finck 
644c2c66affSColin Finck /* Class 1 - Processor Information */
645c2c66affSColin Finck QSI_DEF(SystemProcessorInformation)
646c2c66affSColin Finck {
647c2c66affSColin Finck     PSYSTEM_PROCESSOR_INFORMATION Spi
648c2c66affSColin Finck         = (PSYSTEM_PROCESSOR_INFORMATION) Buffer;
649c2c66affSColin Finck 
650c2c66affSColin Finck     *ReqSize = sizeof(SYSTEM_PROCESSOR_INFORMATION);
651c2c66affSColin Finck 
652c2c66affSColin Finck     /* Check user buffer's size */
653c2c66affSColin Finck     if (Size < sizeof(SYSTEM_PROCESSOR_INFORMATION))
654c2c66affSColin Finck     {
655c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
656c2c66affSColin Finck     }
657c2c66affSColin Finck     Spi->ProcessorArchitecture = KeProcessorArchitecture;
658c2c66affSColin Finck     Spi->ProcessorLevel = KeProcessorLevel;
659c2c66affSColin Finck     Spi->ProcessorRevision = KeProcessorRevision;
660c2c66affSColin Finck     Spi->Reserved = 0;
661c2c66affSColin Finck     Spi->ProcessorFeatureBits = KeFeatureBits;
662c2c66affSColin Finck 
663c2c66affSColin Finck     DPRINT("Arch %u Level %u Rev 0x%x\n", Spi->ProcessorArchitecture,
664c2c66affSColin Finck         Spi->ProcessorLevel, Spi->ProcessorRevision);
665c2c66affSColin Finck 
666c2c66affSColin Finck     return STATUS_SUCCESS;
667c2c66affSColin Finck }
668c2c66affSColin Finck 
669c2c66affSColin Finck /* Class 2 - Performance Information */
670c2c66affSColin Finck QSI_DEF(SystemPerformanceInformation)
671c2c66affSColin Finck {
672e6323758SPierre Schweitzer     LONG i;
673c2c66affSColin Finck     ULONG IdleUser, IdleKernel;
674e6323758SPierre Schweitzer     PKPRCB Prcb;
675c2c66affSColin Finck     PSYSTEM_PERFORMANCE_INFORMATION Spi
676c2c66affSColin Finck         = (PSYSTEM_PERFORMANCE_INFORMATION) Buffer;
677c2c66affSColin Finck 
678c2c66affSColin Finck     PEPROCESS TheIdleProcess;
679c2c66affSColin Finck 
680c2c66affSColin Finck     *ReqSize = sizeof(SYSTEM_PERFORMANCE_INFORMATION);
681c2c66affSColin Finck 
682c2c66affSColin Finck     /* Check user buffer's size */
683c2c66affSColin Finck     if (Size < sizeof(SYSTEM_PERFORMANCE_INFORMATION))
684c2c66affSColin Finck     {
685c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
686c2c66affSColin Finck     }
687c2c66affSColin Finck 
688c2c66affSColin Finck     TheIdleProcess = PsIdleProcess;
689c2c66affSColin Finck 
690c2c66affSColin Finck     IdleKernel = KeQueryRuntimeProcess(&TheIdleProcess->Pcb, &IdleUser);
691c2c66affSColin Finck     Spi->IdleProcessTime.QuadPart = UInt32x32To64(IdleKernel, KeMaximumIncrement);
692c2c66affSColin Finck     Spi->IoReadTransferCount = IoReadTransferCount;
693c2c66affSColin Finck     Spi->IoWriteTransferCount = IoWriteTransferCount;
694c2c66affSColin Finck     Spi->IoOtherTransferCount = IoOtherTransferCount;
695c2c66affSColin Finck     Spi->IoReadOperationCount = IoReadOperationCount;
696c2c66affSColin Finck     Spi->IoWriteOperationCount = IoWriteOperationCount;
697c2c66affSColin Finck     Spi->IoOtherOperationCount = IoOtherOperationCount;
69813d9d3ebSPierre Schweitzer     for (i = 0; i < KeNumberProcessors; i ++)
69913d9d3ebSPierre Schweitzer     {
70013d9d3ebSPierre Schweitzer         Prcb = KiProcessorBlock[i];
70113d9d3ebSPierre Schweitzer         if (Prcb)
70213d9d3ebSPierre Schweitzer         {
70313d9d3ebSPierre Schweitzer             Spi->IoReadTransferCount.QuadPart += Prcb->IoReadTransferCount.QuadPart;
70413d9d3ebSPierre Schweitzer             Spi->IoWriteTransferCount.QuadPart += Prcb->IoWriteTransferCount.QuadPart;
70513d9d3ebSPierre Schweitzer             Spi->IoOtherTransferCount.QuadPart += Prcb->IoOtherTransferCount.QuadPart;
70613d9d3ebSPierre Schweitzer             Spi->IoReadOperationCount += Prcb->IoReadOperationCount;
70713d9d3ebSPierre Schweitzer             Spi->IoWriteOperationCount += Prcb->IoWriteOperationCount;
70813d9d3ebSPierre Schweitzer             Spi->IoOtherOperationCount += Prcb->IoOtherOperationCount;
70913d9d3ebSPierre Schweitzer         }
71013d9d3ebSPierre Schweitzer     }
711c2c66affSColin Finck 
712c2c66affSColin Finck     Spi->AvailablePages = (ULONG)MmAvailablePages;
713c2c66affSColin Finck     /*
714c2c66affSColin Finck      *   Add up all the used "Committed" memory + pagefile.
715c2c66affSColin Finck      *   Not sure this is right. 8^\
716c2c66affSColin Finck      */
717c2c66affSColin Finck     Spi->CommittedPages = MiMemoryConsumers[MC_SYSTEM].PagesUsed +
718c2c66affSColin Finck                           MiMemoryConsumers[MC_CACHE].PagesUsed +
719c2c66affSColin Finck                           MiMemoryConsumers[MC_USER].PagesUsed +
720c2c66affSColin Finck                           MiUsedSwapPages;
721c2c66affSColin Finck     /*
722c2c66affSColin Finck      *  Add up the full system total + pagefile.
723c2c66affSColin Finck      *  All this make Taskmgr happy but not sure it is the right numbers.
724c2c66affSColin Finck      *  This too, fixes some of GlobalMemoryStatusEx numbers.
725c2c66affSColin Finck      */
726c2c66affSColin Finck     Spi->CommitLimit = MmNumberOfPhysicalPages + MiFreeSwapPages + MiUsedSwapPages;
727c2c66affSColin Finck 
728c2c66affSColin Finck     Spi->PeakCommitment = 0; /* FIXME */
729c2c66affSColin Finck     Spi->PageFaultCount = 0; /* FIXME */
730c2c66affSColin Finck     Spi->CopyOnWriteCount = 0; /* FIXME */
731c2c66affSColin Finck     Spi->TransitionCount = 0; /* FIXME */
732c2c66affSColin Finck     Spi->CacheTransitionCount = 0; /* FIXME */
733c2c66affSColin Finck     Spi->DemandZeroCount = 0; /* FIXME */
734c2c66affSColin Finck     Spi->PageReadCount = 0; /* FIXME */
735c2c66affSColin Finck     Spi->PageReadIoCount = 0; /* FIXME */
736c2c66affSColin Finck     Spi->CacheReadCount = 0; /* FIXME */
737c2c66affSColin Finck     Spi->CacheIoCount = 0; /* FIXME */
738c2c66affSColin Finck     Spi->DirtyPagesWriteCount = 0; /* FIXME */
739c2c66affSColin Finck     Spi->DirtyWriteIoCount = 0; /* FIXME */
740c2c66affSColin Finck     Spi->MappedPagesWriteCount = 0; /* FIXME */
741c2c66affSColin Finck     Spi->MappedWriteIoCount = 0; /* FIXME */
742c2c66affSColin Finck 
743c2c66affSColin Finck     Spi->PagedPoolPages = 0;
744c2c66affSColin Finck     Spi->NonPagedPoolPages = 0;
745c2c66affSColin Finck     Spi->PagedPoolAllocs = 0;
746c2c66affSColin Finck     Spi->PagedPoolFrees = 0;
747c2c66affSColin Finck     Spi->PagedPoolLookasideHits = 0;
748c2c66affSColin Finck     Spi->NonPagedPoolAllocs = 0;
749c2c66affSColin Finck     Spi->NonPagedPoolFrees = 0;
750c2c66affSColin Finck     Spi->NonPagedPoolLookasideHits = 0;
751c2c66affSColin Finck     ExQueryPoolUsage(&Spi->PagedPoolPages,
752c2c66affSColin Finck                      &Spi->NonPagedPoolPages,
753c2c66affSColin Finck                      &Spi->PagedPoolAllocs,
754c2c66affSColin Finck                      &Spi->PagedPoolFrees,
755c2c66affSColin Finck                      &Spi->PagedPoolLookasideHits,
756c2c66affSColin Finck                      &Spi->NonPagedPoolAllocs,
757c2c66affSColin Finck                      &Spi->NonPagedPoolFrees,
758c2c66affSColin Finck                      &Spi->NonPagedPoolLookasideHits);
759c2c66affSColin Finck     Spi->FreeSystemPtes = 0; /* FIXME */
760c2c66affSColin Finck 
761c2c66affSColin Finck     Spi->ResidentSystemCodePage = 0; /* FIXME */
762c2c66affSColin Finck 
763c2c66affSColin Finck     Spi->TotalSystemDriverPages = 0; /* FIXME */
764c2c66affSColin Finck     Spi->Spare3Count = 0; /* FIXME */
765c2c66affSColin Finck 
766c2c66affSColin Finck     Spi->ResidentSystemCachePage = MiMemoryConsumers[MC_CACHE].PagesUsed;
767c2c66affSColin Finck     Spi->ResidentPagedPoolPage = 0; /* FIXME */
768c2c66affSColin Finck 
769c2c66affSColin Finck     Spi->ResidentSystemDriverPage = 0; /* FIXME */
770c2c66affSColin Finck     Spi->CcFastReadNoWait = 0; /* FIXME */
771c2c66affSColin Finck     Spi->CcFastReadWait = 0; /* FIXME */
772c2c66affSColin Finck     Spi->CcFastReadResourceMiss = 0; /* FIXME */
773c2c66affSColin Finck     Spi->CcFastReadNotPossible = 0; /* FIXME */
774c2c66affSColin Finck 
775c2c66affSColin Finck     Spi->CcFastMdlReadNoWait = 0; /* FIXME */
776c2c66affSColin Finck     Spi->CcFastMdlReadWait = 0; /* FIXME */
777c2c66affSColin Finck     Spi->CcFastMdlReadResourceMiss = 0; /* FIXME */
778c2c66affSColin Finck     Spi->CcFastMdlReadNotPossible = 0; /* FIXME */
779c2c66affSColin Finck 
78045964099SPierre Schweitzer     Spi->CcMapDataNoWait = CcMapDataNoWait;
78145964099SPierre Schweitzer     Spi->CcMapDataWait = CcMapDataWait;
782c2c66affSColin Finck     Spi->CcMapDataNoWaitMiss = 0; /* FIXME */
783c2c66affSColin Finck     Spi->CcMapDataWaitMiss = 0; /* FIXME */
784c2c66affSColin Finck 
7853d13a464SPierre Schweitzer     Spi->CcPinMappedDataCount = CcPinMappedDataCount;
7860fbdf317SPierre Schweitzer     Spi->CcPinReadNoWait = CcPinReadNoWait;
7870fbdf317SPierre Schweitzer     Spi->CcPinReadWait = CcPinReadWait;
788c2c66affSColin Finck     Spi->CcPinReadNoWaitMiss = 0; /* FIXME */
789c2c66affSColin Finck     Spi->CcPinReadWaitMiss = 0; /* FIXME */
790c2c66affSColin Finck     Spi->CcCopyReadNoWait = 0; /* FIXME */
791c2c66affSColin Finck     Spi->CcCopyReadWait = 0; /* FIXME */
792c2c66affSColin Finck     Spi->CcCopyReadNoWaitMiss = 0; /* FIXME */
793c2c66affSColin Finck     Spi->CcCopyReadWaitMiss = 0; /* FIXME */
794c2c66affSColin Finck 
795c2c66affSColin Finck     Spi->CcMdlReadNoWait = 0; /* FIXME */
796c2c66affSColin Finck     Spi->CcMdlReadWait = 0; /* FIXME */
797c2c66affSColin Finck     Spi->CcMdlReadNoWaitMiss = 0; /* FIXME */
798c2c66affSColin Finck     Spi->CcMdlReadWaitMiss = 0; /* FIXME */
799c2c66affSColin Finck     Spi->CcReadAheadIos = 0; /* FIXME */
80045964099SPierre Schweitzer     Spi->CcLazyWriteIos = CcLazyWriteIos;
80145964099SPierre Schweitzer     Spi->CcLazyWritePages = CcLazyWritePages;
8029ac2e985SPierre Schweitzer     Spi->CcDataFlushes = CcDataFlushes;
8039ac2e985SPierre Schweitzer     Spi->CcDataPages = CcDataPages;
804e6323758SPierre Schweitzer 
805e6323758SPierre Schweitzer     Spi->ContextSwitches = 0;
806e6323758SPierre Schweitzer     Spi->FirstLevelTbFills = 0;
807e6323758SPierre Schweitzer     Spi->SecondLevelTbFills = 0;
808e6323758SPierre Schweitzer     Spi->SystemCalls = 0;
809e6323758SPierre Schweitzer     for (i = 0; i < KeNumberProcessors; i ++)
810e6323758SPierre Schweitzer     {
811e6323758SPierre Schweitzer         Prcb = KiProcessorBlock[i];
812e6323758SPierre Schweitzer         if (Prcb)
813e6323758SPierre Schweitzer         {
814e6323758SPierre Schweitzer             Spi->ContextSwitches += KeGetContextSwitches(Prcb);
815e6323758SPierre Schweitzer             Spi->FirstLevelTbFills += Prcb->KeFirstLevelTbFills;
816e6323758SPierre Schweitzer             Spi->SecondLevelTbFills += Prcb->KeSecondLevelTbFills;
817e6323758SPierre Schweitzer             Spi->SystemCalls += Prcb->KeSystemCalls;
818e6323758SPierre Schweitzer         }
819e6323758SPierre Schweitzer     }
820e6323758SPierre Schweitzer 
821c2c66affSColin Finck     return STATUS_SUCCESS;
822c2c66affSColin Finck }
823c2c66affSColin Finck 
824c2c66affSColin Finck /* Class 3 - Time Of Day Information */
825c2c66affSColin Finck QSI_DEF(SystemTimeOfDayInformation)
826c2c66affSColin Finck {
827c2c66affSColin Finck     SYSTEM_TIMEOFDAY_INFORMATION Sti;
828c2c66affSColin Finck     LARGE_INTEGER CurrentTime;
829c2c66affSColin Finck 
830c2c66affSColin Finck     /* Set amount of written information to 0 */
831c2c66affSColin Finck     *ReqSize = 0;
832c2c66affSColin Finck 
833c2c66affSColin Finck     /* Check user buffer's size */
834c2c66affSColin Finck     if (Size > sizeof(SYSTEM_TIMEOFDAY_INFORMATION))
835c2c66affSColin Finck     {
836c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
837c2c66affSColin Finck     }
838c2c66affSColin Finck 
839c2c66affSColin Finck     /* Get current time */
840c2c66affSColin Finck     KeQuerySystemTime(&CurrentTime);
841c2c66affSColin Finck 
842c2c66affSColin Finck     /* Zero local buffer */
843c2c66affSColin Finck     RtlZeroMemory(&Sti, sizeof(SYSTEM_TIMEOFDAY_INFORMATION));
844c2c66affSColin Finck 
845c2c66affSColin Finck     /* Fill local time structure */
846c2c66affSColin Finck     Sti.BootTime= KeBootTime;
847c2c66affSColin Finck     Sti.CurrentTime = CurrentTime;
848c2c66affSColin Finck     Sti.TimeZoneBias.QuadPart = ExpTimeZoneBias.QuadPart;
849c2c66affSColin Finck     Sti.TimeZoneId = ExpTimeZoneId;
850c2c66affSColin Finck     Sti.Reserved = 0;
851c2c66affSColin Finck 
852c2c66affSColin Finck     /* Copy as much as requested by caller */
853c2c66affSColin Finck     RtlCopyMemory(Buffer, &Sti, Size);
854c2c66affSColin Finck 
855c2c66affSColin Finck     /* Set amount of information we copied */
856c2c66affSColin Finck     *ReqSize = Size;
857c2c66affSColin Finck 
858c2c66affSColin Finck     return STATUS_SUCCESS;
859c2c66affSColin Finck }
860c2c66affSColin Finck 
861c2c66affSColin Finck /* Class 4 - Path Information */
862c2c66affSColin Finck QSI_DEF(SystemPathInformation)
863c2c66affSColin Finck {
864c2c66affSColin Finck     /* FIXME: QSI returns STATUS_BREAKPOINT. Why? */
865c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemPathInformation not implemented\n");
866c2c66affSColin Finck 
867c2c66affSColin Finck     return STATUS_BREAKPOINT;
868c2c66affSColin Finck }
869c2c66affSColin Finck 
870c2c66affSColin Finck /* Class 5 - Process Information */
871c2c66affSColin Finck QSI_DEF(SystemProcessInformation)
872c2c66affSColin Finck {
873c2c66affSColin Finck     PSYSTEM_PROCESS_INFORMATION SpiCurrent;
874c2c66affSColin Finck     PSYSTEM_THREAD_INFORMATION ThreadInfo;
875c2c66affSColin Finck     PEPROCESS Process = NULL, SystemProcess;
876c2c66affSColin Finck     PETHREAD CurrentThread;
877c2c66affSColin Finck     ANSI_STRING ImageName;
878c2c66affSColin Finck     ULONG CurrentSize;
879c2c66affSColin Finck     USHORT ImageNameMaximumLength; // image name length in bytes
880c2c66affSColin Finck     USHORT ImageNameLength;
881c2c66affSColin Finck     PLIST_ENTRY CurrentEntry;
882c2c66affSColin Finck     ULONG TotalSize = 0, ThreadsCount;
883c2c66affSColin Finck     ULONG TotalUser, TotalKernel;
884c2c66affSColin Finck     PUCHAR Current;
885c2c66affSColin Finck     NTSTATUS Status = STATUS_SUCCESS;
886c2c66affSColin Finck     PUNICODE_STRING TempProcessImageName;
887c2c66affSColin Finck     _SEH2_VOLATILE PUNICODE_STRING ProcessImageName = NULL;
888c2c66affSColin Finck     PWCHAR szSrc;
889c2c66affSColin Finck     BOOLEAN Overflow = FALSE;
890c2c66affSColin Finck 
891c2c66affSColin Finck     _SEH2_TRY
892c2c66affSColin Finck     {
893c2c66affSColin Finck         /* scan the process list */
894c2c66affSColin Finck 
895c2c66affSColin Finck         PSYSTEM_PROCESS_INFORMATION Spi
896c2c66affSColin Finck             = (PSYSTEM_PROCESS_INFORMATION) Buffer;
897c2c66affSColin Finck 
898c2c66affSColin Finck         *ReqSize = sizeof(SYSTEM_PROCESS_INFORMATION);
899c2c66affSColin Finck 
900c2c66affSColin Finck         /* Check for overflow */
901c2c66affSColin Finck         if (Size < sizeof(SYSTEM_PROCESS_INFORMATION))
902c2c66affSColin Finck         {
903c2c66affSColin Finck             Overflow = TRUE;
904c2c66affSColin Finck         }
905c2c66affSColin Finck 
906c2c66affSColin Finck         /* Zero user's buffer */
907c2c66affSColin Finck         if (!Overflow) RtlZeroMemory(Spi, Size);
908c2c66affSColin Finck 
909c2c66affSColin Finck         SystemProcess = PsIdleProcess;
910c2c66affSColin Finck         Process = SystemProcess;
911c2c66affSColin Finck         Current = (PUCHAR) Spi;
912c2c66affSColin Finck 
913c2c66affSColin Finck         do
914c2c66affSColin Finck         {
915c2c66affSColin Finck             SpiCurrent = (PSYSTEM_PROCESS_INFORMATION) Current;
916c2c66affSColin Finck 
917c2c66affSColin Finck             /* Lock the Process */
918c2c66affSColin Finck             KeEnterCriticalRegion();
919c2c66affSColin Finck             ExAcquirePushLockShared(&Process->ProcessLock);
920c2c66affSColin Finck 
921c2c66affSColin Finck             if ((Process->ProcessExiting) &&
922c2c66affSColin Finck                 (Process->Pcb.Header.SignalState) &&
923c2c66affSColin Finck                 !(Process->ActiveThreads) &&
924c2c66affSColin Finck                 (IsListEmpty(&Process->Pcb.ThreadListHead)))
925c2c66affSColin Finck             {
926c2c66affSColin Finck                 DPRINT1("Process %p (%s:%p) is a zombie\n",
927c2c66affSColin Finck                         Process, Process->ImageFileName, Process->UniqueProcessId);
928c2c66affSColin Finck                 CurrentSize = 0;
929c2c66affSColin Finck                 ImageNameMaximumLength = 0;
930c2c66affSColin Finck 
931c2c66affSColin Finck                 /* Unlock the Process */
932c2c66affSColin Finck                 ExReleasePushLockShared(&Process->ProcessLock);
933c2c66affSColin Finck                 KeLeaveCriticalRegion();
934c2c66affSColin Finck                 goto Skip;
935c2c66affSColin Finck             }
936c2c66affSColin Finck 
937c2c66affSColin Finck             ThreadsCount = 0;
938c2c66affSColin Finck             CurrentEntry = Process->Pcb.ThreadListHead.Flink;
939c2c66affSColin Finck             while (CurrentEntry != &Process->Pcb.ThreadListHead)
940c2c66affSColin Finck             {
941c2c66affSColin Finck                 ThreadsCount++;
942c2c66affSColin Finck                 CurrentEntry = CurrentEntry->Flink;
943c2c66affSColin Finck             }
944c2c66affSColin Finck 
945c2c66affSColin Finck             // size of the structure for every process
946c2c66affSColin Finck             CurrentSize = sizeof(SYSTEM_PROCESS_INFORMATION) + sizeof(SYSTEM_THREAD_INFORMATION) * ThreadsCount;
947c2c66affSColin Finck             ImageNameLength = 0;
948c2c66affSColin Finck             Status = SeLocateProcessImageName(Process, &TempProcessImageName);
949c2c66affSColin Finck             ProcessImageName = TempProcessImageName;
950c2c66affSColin Finck             szSrc = NULL;
951c2c66affSColin Finck             if (NT_SUCCESS(Status) && (ProcessImageName->Length > 0))
952c2c66affSColin Finck             {
953c2c66affSColin Finck               szSrc = (PWCHAR)((PCHAR)ProcessImageName->Buffer + ProcessImageName->Length);
954c2c66affSColin Finck               /* Loop the file name*/
955c2c66affSColin Finck               while (szSrc > ProcessImageName->Buffer)
956c2c66affSColin Finck               {
957c2c66affSColin Finck                 /* Make sure this isn't a backslash */
958c2c66affSColin Finck                 if (*--szSrc == OBJ_NAME_PATH_SEPARATOR)
959c2c66affSColin Finck                 {
960c2c66affSColin Finck                     szSrc++;
961c2c66affSColin Finck                     break;
962c2c66affSColin Finck                 }
963c2c66affSColin Finck                 else
964c2c66affSColin Finck                 {
965c2c66affSColin Finck                     ImageNameLength += sizeof(WCHAR);
966c2c66affSColin Finck                 }
967c2c66affSColin Finck               }
968c2c66affSColin Finck             }
969c2c66affSColin Finck             if (!ImageNameLength && Process != PsIdleProcess)
970c2c66affSColin Finck             {
971c2c66affSColin Finck               ImageNameLength = (USHORT)strlen(Process->ImageFileName) * sizeof(WCHAR);
972c2c66affSColin Finck             }
973c2c66affSColin Finck 
974c2c66affSColin Finck             /* Round up the image name length as NT does */
975c2c66affSColin Finck             if (ImageNameLength > 0)
976c2c66affSColin Finck                 ImageNameMaximumLength = ROUND_UP(ImageNameLength + sizeof(WCHAR), 8);
977c2c66affSColin Finck             else
978c2c66affSColin Finck                 ImageNameMaximumLength = 0;
979c2c66affSColin Finck 
980c2c66affSColin Finck             TotalSize += CurrentSize + ImageNameMaximumLength;
981c2c66affSColin Finck 
982c2c66affSColin Finck             /* Check for overflow */
983c2c66affSColin Finck             if (TotalSize > Size)
984c2c66affSColin Finck             {
985c2c66affSColin Finck                 Overflow = TRUE;
986c2c66affSColin Finck             }
987c2c66affSColin Finck 
988c2c66affSColin Finck             /* Fill system information */
989c2c66affSColin Finck             if (!Overflow)
990c2c66affSColin Finck             {
991c2c66affSColin Finck                 SpiCurrent->NextEntryOffset = CurrentSize + ImageNameMaximumLength; // relative offset to the beginning of the next structure
992c2c66affSColin Finck                 SpiCurrent->NumberOfThreads = ThreadsCount;
993c2c66affSColin Finck                 SpiCurrent->CreateTime = Process->CreateTime;
994c2c66affSColin Finck                 SpiCurrent->ImageName.Length = ImageNameLength;
995c2c66affSColin Finck                 SpiCurrent->ImageName.MaximumLength = ImageNameMaximumLength;
996c2c66affSColin Finck                 SpiCurrent->ImageName.Buffer = (void*)(Current + CurrentSize);
997c2c66affSColin Finck 
998c2c66affSColin Finck                 /* Copy name to the end of the struct */
999c2c66affSColin Finck                 if(Process != PsIdleProcess)
1000c2c66affSColin Finck                 {
1001c2c66affSColin Finck                     if (szSrc)
1002c2c66affSColin Finck                     {
1003c2c66affSColin Finck                         RtlCopyMemory(SpiCurrent->ImageName.Buffer, szSrc, SpiCurrent->ImageName.Length);
1004c2c66affSColin Finck                     }
1005c2c66affSColin Finck                     else
1006c2c66affSColin Finck                     {
1007c2c66affSColin Finck                         RtlInitAnsiString(&ImageName, Process->ImageFileName);
1008c2c66affSColin Finck                         RtlAnsiStringToUnicodeString(&SpiCurrent->ImageName, &ImageName, FALSE);
1009c2c66affSColin Finck                     }
1010c2c66affSColin Finck                 }
1011c2c66affSColin Finck                 else
1012c2c66affSColin Finck                 {
1013c2c66affSColin Finck                     RtlInitUnicodeString(&SpiCurrent->ImageName, NULL);
1014c2c66affSColin Finck                 }
1015c2c66affSColin Finck 
1016c2c66affSColin Finck                 SpiCurrent->BasePriority = Process->Pcb.BasePriority;
1017c2c66affSColin Finck                 SpiCurrent->UniqueProcessId = Process->UniqueProcessId;
1018c2c66affSColin Finck                 SpiCurrent->InheritedFromUniqueProcessId = Process->InheritedFromUniqueProcessId;
1019c2c66affSColin Finck                 SpiCurrent->HandleCount = ObGetProcessHandleCount(Process);
1020c2c66affSColin Finck                 SpiCurrent->PeakVirtualSize = Process->PeakVirtualSize;
1021c2c66affSColin Finck                 SpiCurrent->VirtualSize = Process->VirtualSize;
1022c2c66affSColin Finck                 SpiCurrent->PageFaultCount = Process->Vm.PageFaultCount;
1023c2c66affSColin Finck                 SpiCurrent->PeakWorkingSetSize = Process->Vm.PeakWorkingSetSize;
1024c2c66affSColin Finck                 SpiCurrent->WorkingSetSize = Process->Vm.WorkingSetSize;
1025c2c66affSColin Finck                 SpiCurrent->QuotaPeakPagedPoolUsage = Process->QuotaPeak[0];
1026c2c66affSColin Finck                 SpiCurrent->QuotaPagedPoolUsage = Process->QuotaUsage[0];
1027c2c66affSColin Finck                 SpiCurrent->QuotaPeakNonPagedPoolUsage = Process->QuotaPeak[1];
1028c2c66affSColin Finck                 SpiCurrent->QuotaNonPagedPoolUsage = Process->QuotaUsage[1];
1029c2c66affSColin Finck                 SpiCurrent->PagefileUsage = Process->QuotaUsage[2];
1030c2c66affSColin Finck                 SpiCurrent->PeakPagefileUsage = Process->QuotaPeak[2];
1031c2c66affSColin Finck                 SpiCurrent->PrivatePageCount = Process->CommitCharge;
1032c2c66affSColin Finck                 ThreadInfo = (PSYSTEM_THREAD_INFORMATION)(SpiCurrent + 1);
1033c2c66affSColin Finck 
1034c2c66affSColin Finck                 CurrentEntry = Process->Pcb.ThreadListHead.Flink;
1035c2c66affSColin Finck                 while (CurrentEntry != &Process->Pcb.ThreadListHead)
1036c2c66affSColin Finck                 {
1037c2c66affSColin Finck                     CurrentThread = CONTAINING_RECORD(CurrentEntry, ETHREAD, Tcb.ThreadListEntry);
1038c2c66affSColin Finck 
1039c2c66affSColin Finck                     ThreadInfo->KernelTime.QuadPart = UInt32x32To64(CurrentThread->Tcb.KernelTime, KeMaximumIncrement);
1040c2c66affSColin Finck                     ThreadInfo->UserTime.QuadPart = UInt32x32To64(CurrentThread->Tcb.UserTime, KeMaximumIncrement);
1041c2c66affSColin Finck                     ThreadInfo->CreateTime.QuadPart = CurrentThread->CreateTime.QuadPart;
1042c2c66affSColin Finck                     ThreadInfo->WaitTime = CurrentThread->Tcb.WaitTime;
1043c2c66affSColin Finck                     ThreadInfo->StartAddress = (PVOID) CurrentThread->StartAddress;
1044c2c66affSColin Finck                     ThreadInfo->ClientId = CurrentThread->Cid;
1045c2c66affSColin Finck                     ThreadInfo->Priority = CurrentThread->Tcb.Priority;
1046c2c66affSColin Finck                     ThreadInfo->BasePriority = CurrentThread->Tcb.BasePriority;
1047c2c66affSColin Finck                     ThreadInfo->ContextSwitches = CurrentThread->Tcb.ContextSwitches;
1048c2c66affSColin Finck                     ThreadInfo->ThreadState = CurrentThread->Tcb.State;
1049c2c66affSColin Finck                     ThreadInfo->WaitReason = CurrentThread->Tcb.WaitReason;
1050c2c66affSColin Finck 
1051c2c66affSColin Finck                     ThreadInfo++;
1052c2c66affSColin Finck                     CurrentEntry = CurrentEntry->Flink;
1053c2c66affSColin Finck                 }
1054c2c66affSColin Finck 
1055c2c66affSColin Finck                 /* Query total user/kernel times of a process */
1056c2c66affSColin Finck                 TotalKernel = KeQueryRuntimeProcess(&Process->Pcb, &TotalUser);
1057c2c66affSColin Finck                 SpiCurrent->UserTime.QuadPart = UInt32x32To64(TotalUser, KeMaximumIncrement);
1058c2c66affSColin Finck                 SpiCurrent->KernelTime.QuadPart = UInt32x32To64(TotalKernel, KeMaximumIncrement);
1059c2c66affSColin Finck             }
1060c2c66affSColin Finck 
1061c2c66affSColin Finck             if (ProcessImageName)
1062c2c66affSColin Finck             {
1063c2c66affSColin Finck                 /* Release the memory allocated by SeLocateProcessImageName */
1064c2c66affSColin Finck                 ExFreePoolWithTag(ProcessImageName, TAG_SEPA);
1065c2c66affSColin Finck                 ProcessImageName = NULL;
1066c2c66affSColin Finck             }
1067c2c66affSColin Finck 
1068c2c66affSColin Finck             /* Unlock the Process */
1069c2c66affSColin Finck             ExReleasePushLockShared(&Process->ProcessLock);
1070c2c66affSColin Finck             KeLeaveCriticalRegion();
1071c2c66affSColin Finck 
1072c2c66affSColin Finck             /* Handle idle process entry */
1073c2c66affSColin Finck Skip:
1074c2c66affSColin Finck             if (Process == PsIdleProcess) Process = NULL;
1075c2c66affSColin Finck 
1076c2c66affSColin Finck             Process = PsGetNextProcess(Process);
1077c2c66affSColin Finck             ThreadsCount = 0;
1078c2c66affSColin Finck             if ((Process == SystemProcess) || (Process == NULL))
1079c2c66affSColin Finck             {
1080c2c66affSColin Finck                 if (!Overflow)
1081c2c66affSColin Finck                     SpiCurrent->NextEntryOffset = 0;
1082c2c66affSColin Finck                 break;
1083c2c66affSColin Finck             }
1084c2c66affSColin Finck             else
1085c2c66affSColin Finck                 Current += CurrentSize + ImageNameMaximumLength;
1086c2c66affSColin Finck           }  while ((Process != SystemProcess) && (Process != NULL));
1087c2c66affSColin Finck 
1088c2c66affSColin Finck           if(Process != NULL)
1089c2c66affSColin Finck             ObDereferenceObject(Process);
1090c2c66affSColin Finck           Status = STATUS_SUCCESS;
1091c2c66affSColin Finck     }
1092c2c66affSColin Finck     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
1093c2c66affSColin Finck     {
1094c2c66affSColin Finck         if(Process != NULL)
1095c2c66affSColin Finck             ObDereferenceObject(Process);
1096c2c66affSColin Finck         if (ProcessImageName)
1097c2c66affSColin Finck         {
1098c2c66affSColin Finck             /* Release the memory allocated by SeLocateProcessImageName */
1099c2c66affSColin Finck             ExFreePoolWithTag(ProcessImageName, TAG_SEPA);
1100c2c66affSColin Finck         }
1101c2c66affSColin Finck 
1102c2c66affSColin Finck         Status = _SEH2_GetExceptionCode();
1103c2c66affSColin Finck     }
1104c2c66affSColin Finck     _SEH2_END
1105c2c66affSColin Finck 
1106c2c66affSColin Finck     if (Overflow)
1107c2c66affSColin Finck         Status = STATUS_INFO_LENGTH_MISMATCH;
1108c2c66affSColin Finck 
1109c2c66affSColin Finck     *ReqSize = TotalSize;
1110c2c66affSColin Finck     return Status;
1111c2c66affSColin Finck }
1112c2c66affSColin Finck 
1113c2c66affSColin Finck /* Class 6 - Call Count Information */
1114c2c66affSColin Finck QSI_DEF(SystemCallCountInformation)
1115c2c66affSColin Finck {
1116c2c66affSColin Finck     /* FIXME */
1117c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemCallCountInformation not implemented\n");
1118c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1119c2c66affSColin Finck }
1120c2c66affSColin Finck 
1121c2c66affSColin Finck /* Class 7 - Device Information */
1122c2c66affSColin Finck QSI_DEF(SystemDeviceInformation)
1123c2c66affSColin Finck {
1124c2c66affSColin Finck     PSYSTEM_DEVICE_INFORMATION Sdi
1125c2c66affSColin Finck         = (PSYSTEM_DEVICE_INFORMATION) Buffer;
1126c2c66affSColin Finck     PCONFIGURATION_INFORMATION ConfigInfo;
1127c2c66affSColin Finck 
1128c2c66affSColin Finck     *ReqSize = sizeof(SYSTEM_DEVICE_INFORMATION);
1129c2c66affSColin Finck 
1130c2c66affSColin Finck     /* Check user buffer's size */
1131c2c66affSColin Finck     if (Size < sizeof(SYSTEM_DEVICE_INFORMATION))
1132c2c66affSColin Finck     {
1133c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1134c2c66affSColin Finck     }
1135c2c66affSColin Finck 
1136c2c66affSColin Finck     ConfigInfo = IoGetConfigurationInformation();
1137c2c66affSColin Finck 
1138c2c66affSColin Finck     Sdi->NumberOfDisks = ConfigInfo->DiskCount;
1139c2c66affSColin Finck     Sdi->NumberOfFloppies = ConfigInfo->FloppyCount;
1140c2c66affSColin Finck     Sdi->NumberOfCdRoms = ConfigInfo->CdRomCount;
1141c2c66affSColin Finck     Sdi->NumberOfTapes = ConfigInfo->TapeCount;
1142c2c66affSColin Finck     Sdi->NumberOfSerialPorts = ConfigInfo->SerialCount;
1143c2c66affSColin Finck     Sdi->NumberOfParallelPorts = ConfigInfo->ParallelCount;
1144c2c66affSColin Finck 
1145c2c66affSColin Finck     return STATUS_SUCCESS;
1146c2c66affSColin Finck }
1147c2c66affSColin Finck 
1148c2c66affSColin Finck /* Class 8 - Processor Performance Information */
1149c2c66affSColin Finck QSI_DEF(SystemProcessorPerformanceInformation)
1150c2c66affSColin Finck {
1151c2c66affSColin Finck     PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION Spi
1152c2c66affSColin Finck         = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) Buffer;
1153c2c66affSColin Finck 
1154c2c66affSColin Finck     LONG i;
1155c2c66affSColin Finck     ULONG TotalTime;
1156c2c66affSColin Finck     PKPRCB Prcb;
1157c2c66affSColin Finck 
1158c2c66affSColin Finck     *ReqSize = KeNumberProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
1159c2c66affSColin Finck 
1160c2c66affSColin Finck     /* Check user buffer's size */
1161c2c66affSColin Finck     if (Size < *ReqSize)
1162c2c66affSColin Finck     {
1163c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1164c2c66affSColin Finck     }
1165c2c66affSColin Finck 
1166c2c66affSColin Finck     for (i = 0; i < KeNumberProcessors; i++)
1167c2c66affSColin Finck     {
1168c2c66affSColin Finck         /* Get the PRCB on this processor */
1169c2c66affSColin Finck         Prcb = KiProcessorBlock[i];
1170c2c66affSColin Finck 
1171c2c66affSColin Finck         /* Calculate total user and kernel times */
1172c2c66affSColin Finck         TotalTime = Prcb->IdleThread->KernelTime + Prcb->IdleThread->UserTime;
1173c2c66affSColin Finck         Spi->IdleTime.QuadPart = UInt32x32To64(TotalTime, KeMaximumIncrement);
1174c2c66affSColin Finck         Spi->KernelTime.QuadPart =  UInt32x32To64(Prcb->KernelTime, KeMaximumIncrement);
1175c2c66affSColin Finck         Spi->UserTime.QuadPart = UInt32x32To64(Prcb->UserTime, KeMaximumIncrement);
1176c2c66affSColin Finck         Spi->DpcTime.QuadPart = UInt32x32To64(Prcb->DpcTime, KeMaximumIncrement);
1177c2c66affSColin Finck         Spi->InterruptTime.QuadPart = UInt32x32To64(Prcb->InterruptTime, KeMaximumIncrement);
1178c2c66affSColin Finck         Spi->InterruptCount = Prcb->InterruptCount;
1179c2c66affSColin Finck         Spi++;
1180c2c66affSColin Finck     }
1181c2c66affSColin Finck 
1182c2c66affSColin Finck     return STATUS_SUCCESS;
1183c2c66affSColin Finck }
1184c2c66affSColin Finck 
1185c2c66affSColin Finck /* Class 9 - Flags Information */
1186c2c66affSColin Finck QSI_DEF(SystemFlagsInformation)
1187c2c66affSColin Finck {
1188c2c66affSColin Finck #if (NTDDI_VERSION >= NTDDI_VISTA)
1189c2c66affSColin Finck     *ReqSize = sizeof(SYSTEM_FLAGS_INFORMATION);
1190c2c66affSColin Finck #endif
1191c2c66affSColin Finck 
1192c2c66affSColin Finck     if (sizeof(SYSTEM_FLAGS_INFORMATION) != Size)
1193c2c66affSColin Finck     {
1194c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1195c2c66affSColin Finck     }
1196c2c66affSColin Finck 
1197c2c66affSColin Finck     ((PSYSTEM_FLAGS_INFORMATION) Buffer)->Flags = NtGlobalFlag;
1198c2c66affSColin Finck #if (NTDDI_VERSION < NTDDI_VISTA)
1199c2c66affSColin Finck     *ReqSize = sizeof(SYSTEM_FLAGS_INFORMATION);
1200c2c66affSColin Finck #endif
1201c2c66affSColin Finck 
1202c2c66affSColin Finck     return STATUS_SUCCESS;
1203c2c66affSColin Finck }
1204c2c66affSColin Finck 
1205c2c66affSColin Finck SSI_DEF(SystemFlagsInformation)
1206c2c66affSColin Finck {
1207c2c66affSColin Finck     if (sizeof(SYSTEM_FLAGS_INFORMATION) != Size)
1208c2c66affSColin Finck     {
1209c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1210c2c66affSColin Finck     }
1211c2c66affSColin Finck 
1212c2c66affSColin Finck     if (!SeSinglePrivilegeCheck(SeDebugPrivilege, ExGetPreviousMode()))
1213c2c66affSColin Finck     {
1214c2c66affSColin Finck         return STATUS_ACCESS_DENIED;
1215c2c66affSColin Finck     }
1216c2c66affSColin Finck 
1217c2c66affSColin Finck     NtGlobalFlag = ((PSYSTEM_FLAGS_INFORMATION) Buffer)->Flags;
1218c2c66affSColin Finck     return STATUS_SUCCESS;
1219c2c66affSColin Finck }
1220c2c66affSColin Finck 
1221c2c66affSColin Finck /* Class 10 - Call Time Information */
1222c2c66affSColin Finck QSI_DEF(SystemCallTimeInformation)
1223c2c66affSColin Finck {
1224c2c66affSColin Finck     /* FIXME */
1225c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemCallTimeInformation not implemented\n");
1226c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1227c2c66affSColin Finck }
1228c2c66affSColin Finck 
1229c2c66affSColin Finck /* Class 11 - Module Information */
1230c2c66affSColin Finck QSI_DEF(SystemModuleInformation)
1231c2c66affSColin Finck {
1232c2c66affSColin Finck     NTSTATUS Status;
1233c2c66affSColin Finck 
1234c2c66affSColin Finck     /* Acquire system module list lock */
1235c2c66affSColin Finck     KeEnterCriticalRegion();
1236c2c66affSColin Finck     ExAcquireResourceExclusiveLite(&PsLoadedModuleResource, TRUE);
1237c2c66affSColin Finck 
1238c2c66affSColin Finck     /* Call the generic handler with the system module list */
1239c2c66affSColin Finck     Status = ExpQueryModuleInformation(&PsLoadedModuleList,
1240c2c66affSColin Finck                                        &MmLoadedUserImageList,
1241c2c66affSColin Finck                                        (PRTL_PROCESS_MODULES)Buffer,
1242c2c66affSColin Finck                                        Size,
1243c2c66affSColin Finck                                        ReqSize);
1244c2c66affSColin Finck 
1245c2c66affSColin Finck     /* Release list lock and return status */
1246c2c66affSColin Finck     ExReleaseResourceLite(&PsLoadedModuleResource);
1247c2c66affSColin Finck     KeLeaveCriticalRegion();
1248c2c66affSColin Finck     return Status;
1249c2c66affSColin Finck }
1250c2c66affSColin Finck 
1251c2c66affSColin Finck /* Class 12 - Locks Information */
1252c2c66affSColin Finck QSI_DEF(SystemLocksInformation)
1253c2c66affSColin Finck {
1254c2c66affSColin Finck     /* FIXME */
1255c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemLocksInformation not implemented\n");
1256c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1257c2c66affSColin Finck }
1258c2c66affSColin Finck 
1259c2c66affSColin Finck /* Class 13 - Stack Trace Information */
1260c2c66affSColin Finck QSI_DEF(SystemStackTraceInformation)
1261c2c66affSColin Finck {
1262c2c66affSColin Finck     /* FIXME */
1263c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemStackTraceInformation not implemented\n");
1264c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1265c2c66affSColin Finck }
1266c2c66affSColin Finck 
1267c2c66affSColin Finck /* Class 14 - Paged Pool Information */
1268c2c66affSColin Finck QSI_DEF(SystemPagedPoolInformation)
1269c2c66affSColin Finck {
1270c2c66affSColin Finck     /* FIXME */
1271c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemPagedPoolInformation not implemented\n");
1272c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1273c2c66affSColin Finck }
1274c2c66affSColin Finck 
1275c2c66affSColin Finck /* Class 15 - Non Paged Pool Information */
1276c2c66affSColin Finck QSI_DEF(SystemNonPagedPoolInformation)
1277c2c66affSColin Finck {
1278c2c66affSColin Finck     /* FIXME */
1279c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemNonPagedPoolInformation not implemented\n");
1280c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1281c2c66affSColin Finck }
1282c2c66affSColin Finck 
1283c2c66affSColin Finck 
1284c2c66affSColin Finck /* Class 16 - Handle Information */
1285c2c66affSColin Finck QSI_DEF(SystemHandleInformation)
1286c2c66affSColin Finck {
1287c2c66affSColin Finck     PSYSTEM_HANDLE_INFORMATION HandleInformation;
1288c2c66affSColin Finck     PLIST_ENTRY NextTableEntry;
1289c2c66affSColin Finck     PHANDLE_TABLE HandleTable;
1290c2c66affSColin Finck     PHANDLE_TABLE_ENTRY HandleTableEntry;
1291c2c66affSColin Finck     EXHANDLE Handle;
1292c2c66affSColin Finck     ULONG Index = 0;
1293c2c66affSColin Finck     NTSTATUS Status;
1294c2c66affSColin Finck     PMDL Mdl;
1295c2c66affSColin Finck     PAGED_CODE();
1296c2c66affSColin Finck 
1297c2c66affSColin Finck     DPRINT("NtQuerySystemInformation - SystemHandleInformation\n");
1298c2c66affSColin Finck 
1299c2c66affSColin Finck     /* Set initial required buffer size */
1300c2c66affSColin Finck     *ReqSize = FIELD_OFFSET(SYSTEM_HANDLE_INFORMATION, Handles);
1301c2c66affSColin Finck 
1302c2c66affSColin Finck     /* Check user's buffer size */
1303c2c66affSColin Finck     if (Size < *ReqSize)
1304c2c66affSColin Finck     {
1305c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1306c2c66affSColin Finck     }
1307c2c66affSColin Finck 
1308c2c66affSColin Finck     /* We need to lock down the memory */
1309c2c66affSColin Finck     Status = ExLockUserBuffer(Buffer,
1310c2c66affSColin Finck                               Size,
1311c2c66affSColin Finck                               ExGetPreviousMode(),
1312c2c66affSColin Finck                               IoWriteAccess,
1313c2c66affSColin Finck                               (PVOID*)&HandleInformation,
1314c2c66affSColin Finck                               &Mdl);
1315c2c66affSColin Finck     if (!NT_SUCCESS(Status))
1316c2c66affSColin Finck     {
1317c2c66affSColin Finck         DPRINT1("Failed to lock the user buffer: 0x%lx\n", Status);
1318c2c66affSColin Finck         return Status;
1319c2c66affSColin Finck     }
1320c2c66affSColin Finck 
1321c2c66affSColin Finck     /* Reset of count of handles */
1322c2c66affSColin Finck     HandleInformation->NumberOfHandles = 0;
1323c2c66affSColin Finck 
1324c2c66affSColin Finck     /* Enter a critical region */
1325c2c66affSColin Finck     KeEnterCriticalRegion();
1326c2c66affSColin Finck 
1327c2c66affSColin Finck     /* Acquire the handle table lock */
1328c2c66affSColin Finck     ExAcquirePushLockShared(&HandleTableListLock);
1329c2c66affSColin Finck 
1330c2c66affSColin Finck     /* Enumerate all system handles */
1331c2c66affSColin Finck     for (NextTableEntry = HandleTableListHead.Flink;
1332c2c66affSColin Finck          NextTableEntry != &HandleTableListHead;
1333c2c66affSColin Finck          NextTableEntry = NextTableEntry->Flink)
1334c2c66affSColin Finck     {
1335c2c66affSColin Finck         /* Get current handle table */
1336c2c66affSColin Finck         HandleTable = CONTAINING_RECORD(NextTableEntry, HANDLE_TABLE, HandleTableList);
1337c2c66affSColin Finck 
1338c2c66affSColin Finck         /* Set the initial value and loop the entries */
1339c2c66affSColin Finck         Handle.Value = 0;
1340c2c66affSColin Finck         while ((HandleTableEntry = ExpLookupHandleTableEntry(HandleTable, Handle)))
1341c2c66affSColin Finck         {
1342c2c66affSColin Finck             /* Validate the entry */
1343c2c66affSColin Finck             if ((HandleTableEntry->Object) &&
1344c2c66affSColin Finck                 (HandleTableEntry->NextFreeTableEntry != -2))
1345c2c66affSColin Finck             {
1346c2c66affSColin Finck                 /* Increase of count of handles */
1347c2c66affSColin Finck                 ++HandleInformation->NumberOfHandles;
1348c2c66affSColin Finck 
1349c2c66affSColin Finck                 /* Lock the entry */
1350c2c66affSColin Finck                 if (ExpLockHandleTableEntry(HandleTable, HandleTableEntry))
1351c2c66affSColin Finck                 {
1352c2c66affSColin Finck                     /* Increase required buffer size */
1353c2c66affSColin Finck                     *ReqSize += sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO);
1354c2c66affSColin Finck 
1355c2c66affSColin Finck                     /* Check user's buffer size */
1356c2c66affSColin Finck                     if (*ReqSize > Size)
1357c2c66affSColin Finck                     {
1358c2c66affSColin Finck                         Status = STATUS_INFO_LENGTH_MISMATCH;
1359c2c66affSColin Finck                     }
1360c2c66affSColin Finck                     else
1361c2c66affSColin Finck                     {
1362c2c66affSColin Finck                         POBJECT_HEADER ObjectHeader = ObpGetHandleObject(HandleTableEntry);
1363c2c66affSColin Finck 
1364c2c66affSColin Finck                         /* Filling handle information */
1365c2c66affSColin Finck                         HandleInformation->Handles[Index].UniqueProcessId =
1366c2c66affSColin Finck                             (USHORT)(ULONG_PTR) HandleTable->UniqueProcessId;
1367c2c66affSColin Finck 
1368c2c66affSColin Finck                         HandleInformation->Handles[Index].CreatorBackTraceIndex = 0;
1369c2c66affSColin Finck 
1370c2c66affSColin Finck #if 0 /* FIXME!!! Type field currupted */
1371c2c66affSColin Finck                         HandleInformation->Handles[Index].ObjectTypeIndex =
1372c2c66affSColin Finck                             (UCHAR) ObjectHeader->Type->Index;
1373c2c66affSColin Finck #else
1374c2c66affSColin Finck                         HandleInformation->Handles[Index].ObjectTypeIndex = 0;
1375c2c66affSColin Finck #endif
1376c2c66affSColin Finck 
1377c2c66affSColin Finck                         HandleInformation->Handles[Index].HandleAttributes =
1378c2c66affSColin Finck                             HandleTableEntry->ObAttributes & OBJ_HANDLE_ATTRIBUTES;
1379c2c66affSColin Finck 
1380c2c66affSColin Finck                         HandleInformation->Handles[Index].HandleValue =
1381c2c66affSColin Finck                             (USHORT)(ULONG_PTR) Handle.GenericHandleOverlay;
1382c2c66affSColin Finck 
1383c2c66affSColin Finck                         HandleInformation->Handles[Index].Object = &ObjectHeader->Body;
1384c2c66affSColin Finck 
1385c2c66affSColin Finck                         HandleInformation->Handles[Index].GrantedAccess =
1386c2c66affSColin Finck                             HandleTableEntry->GrantedAccess;
1387c2c66affSColin Finck 
1388c2c66affSColin Finck                         ++Index;
1389c2c66affSColin Finck                     }
1390c2c66affSColin Finck 
1391c2c66affSColin Finck                     /* Unlock it */
1392c2c66affSColin Finck                     ExUnlockHandleTableEntry(HandleTable, HandleTableEntry);
1393c2c66affSColin Finck                 }
1394c2c66affSColin Finck             }
1395c2c66affSColin Finck 
1396c2c66affSColin Finck             /* Go to the next entry */
1397c2c66affSColin Finck             Handle.Value += sizeof(HANDLE);
1398c2c66affSColin Finck         }
1399c2c66affSColin Finck     }
1400c2c66affSColin Finck 
1401c2c66affSColin Finck     /* Release the lock */
1402c2c66affSColin Finck     ExReleasePushLockShared(&HandleTableListLock);
1403c2c66affSColin Finck 
1404c2c66affSColin Finck     /* Leave the critical region */
1405c2c66affSColin Finck     KeLeaveCriticalRegion();
1406c2c66affSColin Finck 
1407c2c66affSColin Finck     /* Release the locked user buffer */
1408c2c66affSColin Finck     ExUnlockUserBuffer(Mdl);
1409c2c66affSColin Finck 
1410c2c66affSColin Finck     return Status;
1411c2c66affSColin Finck }
1412c2c66affSColin Finck 
1413c2c66affSColin Finck /* Class 17 -  Information */
1414c2c66affSColin Finck QSI_DEF(SystemObjectInformation)
1415c2c66affSColin Finck {
1416c2c66affSColin Finck     /* FIXME */
1417c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemObjectInformation not implemented\n");
1418c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1419c2c66affSColin Finck }
1420c2c66affSColin Finck 
1421c2c66affSColin Finck /* Class 18 -  Information */
1422c2c66affSColin Finck QSI_DEF(SystemPageFileInformation)
1423c2c66affSColin Finck {
1424c2c66affSColin Finck     UNICODE_STRING FileName; /* FIXME */
1425c2c66affSColin Finck     SYSTEM_PAGEFILE_INFORMATION *Spfi = (SYSTEM_PAGEFILE_INFORMATION *) Buffer;
1426c2c66affSColin Finck 
1427c2c66affSColin Finck     if (Size < sizeof(SYSTEM_PAGEFILE_INFORMATION))
1428c2c66affSColin Finck     {
1429c2c66affSColin Finck         * ReqSize = sizeof(SYSTEM_PAGEFILE_INFORMATION);
1430c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1431c2c66affSColin Finck     }
1432c2c66affSColin Finck 
1433c2c66affSColin Finck     RtlInitUnicodeString(&FileName, NULL); /* FIXME */
1434c2c66affSColin Finck 
1435c2c66affSColin Finck     /* FIXME */
1436c2c66affSColin Finck     Spfi->NextEntryOffset = 0;
1437c2c66affSColin Finck 
1438c2c66affSColin Finck     Spfi->TotalSize = MiFreeSwapPages + MiUsedSwapPages;
1439c2c66affSColin Finck     Spfi->TotalInUse = MiUsedSwapPages;
1440c2c66affSColin Finck     Spfi->PeakUsage = MiUsedSwapPages; /* FIXME */
1441c2c66affSColin Finck     Spfi->PageFileName = FileName;
1442c2c66affSColin Finck     return STATUS_SUCCESS;
1443c2c66affSColin Finck }
1444c2c66affSColin Finck 
1445c2c66affSColin Finck /* Class 19 - Vdm Instemul Information */
1446c2c66affSColin Finck QSI_DEF(SystemVdmInstemulInformation)
1447c2c66affSColin Finck {
1448c2c66affSColin Finck     /* FIXME */
1449c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemVdmInstemulInformation not implemented\n");
1450c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1451c2c66affSColin Finck }
1452c2c66affSColin Finck 
1453c2c66affSColin Finck /* Class 20 - Vdm Bop Information */
1454c2c66affSColin Finck QSI_DEF(SystemVdmBopInformation)
1455c2c66affSColin Finck {
1456c2c66affSColin Finck     /* FIXME */
1457c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemVdmBopInformation not implemented\n");
1458c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1459c2c66affSColin Finck }
1460c2c66affSColin Finck 
1461c2c66affSColin Finck /* Class 21 - File Cache Information */
1462c2c66affSColin Finck QSI_DEF(SystemFileCacheInformation)
1463c2c66affSColin Finck {
1464c2c66affSColin Finck     SYSTEM_FILECACHE_INFORMATION *Sci = (SYSTEM_FILECACHE_INFORMATION *) Buffer;
1465c2c66affSColin Finck 
1466c2c66affSColin Finck     *ReqSize = sizeof(SYSTEM_FILECACHE_INFORMATION);
1467c2c66affSColin Finck 
1468c2c66affSColin Finck     if (Size < *ReqSize)
1469c2c66affSColin Finck     {
1470c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1471c2c66affSColin Finck     }
1472c2c66affSColin Finck 
1473c2c66affSColin Finck     RtlZeroMemory(Sci, sizeof(SYSTEM_FILECACHE_INFORMATION));
1474c2c66affSColin Finck 
1475c2c66affSColin Finck     /* Return the Byte size not the page size. */
1476c2c66affSColin Finck     Sci->CurrentSize =
1477c2c66affSColin Finck         MiMemoryConsumers[MC_CACHE].PagesUsed * PAGE_SIZE;
1478c2c66affSColin Finck     Sci->PeakSize =
1479c2c66affSColin Finck             MiMemoryConsumers[MC_CACHE].PagesUsed * PAGE_SIZE; /* FIXME */
1480c2c66affSColin Finck     /* Taskmgr multiplies this one by page size right away */
1481c2c66affSColin Finck     Sci->CurrentSizeIncludingTransitionInPages =
1482c2c66affSColin Finck         MiMemoryConsumers[MC_CACHE].PagesUsed; /* FIXME: Should be */
1483c2c66affSColin Finck     /* system working set and standby pages. */
1484c2c66affSColin Finck     Sci->PageFaultCount = 0; /* FIXME */
1485c2c66affSColin Finck     Sci->MinimumWorkingSet = 0; /* FIXME */
1486c2c66affSColin Finck     Sci->MaximumWorkingSet = 0; /* FIXME */
1487c2c66affSColin Finck 
1488c2c66affSColin Finck     return STATUS_SUCCESS;
1489c2c66affSColin Finck }
1490c2c66affSColin Finck 
1491c2c66affSColin Finck SSI_DEF(SystemFileCacheInformation)
1492c2c66affSColin Finck {
1493c2c66affSColin Finck     if (Size < sizeof(SYSTEM_FILECACHE_INFORMATION))
1494c2c66affSColin Finck     {
1495c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1496c2c66affSColin Finck     }
1497c2c66affSColin Finck     /* FIXME */
1498c2c66affSColin Finck     DPRINT1("NtSetSystemInformation - SystemFileCacheInformation not implemented\n");
1499c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1500c2c66affSColin Finck }
1501c2c66affSColin Finck 
1502c2c66affSColin Finck /* Class 22 - Pool Tag Information */
1503c2c66affSColin Finck QSI_DEF(SystemPoolTagInformation)
1504c2c66affSColin Finck {
1505c2c66affSColin Finck     if (Size < sizeof(SYSTEM_POOLTAG_INFORMATION)) return STATUS_INFO_LENGTH_MISMATCH;
1506c2c66affSColin Finck     return ExGetPoolTagInfo(Buffer, Size, ReqSize);
1507c2c66affSColin Finck }
1508c2c66affSColin Finck 
1509c2c66affSColin Finck /* Class 23 - Interrupt Information for all processors */
1510c2c66affSColin Finck QSI_DEF(SystemInterruptInformation)
1511c2c66affSColin Finck {
1512c2c66affSColin Finck     PKPRCB Prcb;
1513c2c66affSColin Finck     LONG i;
1514c2c66affSColin Finck     ULONG ti;
1515c2c66affSColin Finck     PSYSTEM_INTERRUPT_INFORMATION sii = (PSYSTEM_INTERRUPT_INFORMATION)Buffer;
1516c2c66affSColin Finck 
1517c2c66affSColin Finck     if(Size < KeNumberProcessors * sizeof(SYSTEM_INTERRUPT_INFORMATION))
1518c2c66affSColin Finck     {
1519c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1520c2c66affSColin Finck     }
1521c2c66affSColin Finck 
1522c2c66affSColin Finck     ti = KeQueryTimeIncrement();
1523c2c66affSColin Finck 
1524c2c66affSColin Finck     for (i = 0; i < KeNumberProcessors; i++)
1525c2c66affSColin Finck     {
1526c2c66affSColin Finck         Prcb = KiProcessorBlock[i];
1527c2c66affSColin Finck         sii->ContextSwitches = KeGetContextSwitches(Prcb);
1528c2c66affSColin Finck         sii->DpcCount = Prcb->DpcData[0].DpcCount;
1529c2c66affSColin Finck         sii->DpcRate = Prcb->DpcRequestRate;
1530c2c66affSColin Finck         sii->TimeIncrement = ti;
1531c2c66affSColin Finck         sii->DpcBypassCount = 0;
1532c2c66affSColin Finck         sii->ApcBypassCount = 0;
1533c2c66affSColin Finck         sii++;
1534c2c66affSColin Finck     }
1535c2c66affSColin Finck 
1536c2c66affSColin Finck     return STATUS_SUCCESS;
1537c2c66affSColin Finck }
1538c2c66affSColin Finck 
1539c2c66affSColin Finck /* Class 24 - DPC Behaviour Information */
1540c2c66affSColin Finck QSI_DEF(SystemDpcBehaviourInformation)
1541c2c66affSColin Finck {
1542962b2fd6SPierre Schweitzer     PSYSTEM_DPC_BEHAVIOR_INFORMATION sdbi = (PSYSTEM_DPC_BEHAVIOR_INFORMATION)Buffer;
1543962b2fd6SPierre Schweitzer 
1544962b2fd6SPierre Schweitzer     if (Size < sizeof(SYSTEM_DPC_BEHAVIOR_INFORMATION))
1545962b2fd6SPierre Schweitzer     {
1546962b2fd6SPierre Schweitzer         return STATUS_INFO_LENGTH_MISMATCH;
1547962b2fd6SPierre Schweitzer     }
1548962b2fd6SPierre Schweitzer 
1549962b2fd6SPierre Schweitzer     sdbi->DpcQueueDepth = KiMaximumDpcQueueDepth;
1550962b2fd6SPierre Schweitzer     sdbi->MinimumDpcRate = KiMinimumDpcRate;
1551962b2fd6SPierre Schweitzer     sdbi->AdjustDpcThreshold = KiAdjustDpcThreshold;
1552962b2fd6SPierre Schweitzer     sdbi->IdealDpcRate = KiIdealDpcRate;
1553962b2fd6SPierre Schweitzer 
1554962b2fd6SPierre Schweitzer     return STATUS_SUCCESS;
1555c2c66affSColin Finck }
1556c2c66affSColin Finck 
1557c2c66affSColin Finck SSI_DEF(SystemDpcBehaviourInformation)
1558c2c66affSColin Finck {
1559c2c66affSColin Finck     /* FIXME */
1560c2c66affSColin Finck     DPRINT1("NtSetSystemInformation - SystemDpcBehaviourInformation not implemented\n");
1561c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1562c2c66affSColin Finck }
1563c2c66affSColin Finck 
1564c2c66affSColin Finck /* Class 25 - Full Memory Information */
1565c2c66affSColin Finck QSI_DEF(SystemFullMemoryInformation)
1566c2c66affSColin Finck {
1567c2c66affSColin Finck     PULONG Spi = (PULONG) Buffer;
1568c2c66affSColin Finck 
1569c2c66affSColin Finck     PEPROCESS TheIdleProcess;
1570c2c66affSColin Finck 
1571c2c66affSColin Finck     *ReqSize = sizeof(ULONG);
1572c2c66affSColin Finck 
1573c2c66affSColin Finck     if (sizeof(ULONG) != Size)
1574c2c66affSColin Finck     {
1575c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1576c2c66affSColin Finck     }
1577c2c66affSColin Finck 
1578c2c66affSColin Finck     DPRINT("SystemFullMemoryInformation\n");
1579c2c66affSColin Finck 
1580c2c66affSColin Finck     TheIdleProcess = PsIdleProcess;
1581c2c66affSColin Finck 
1582c2c66affSColin Finck     DPRINT("PID: %p, KernelTime: %u PFFree: %lu PFUsed: %lu\n",
1583c2c66affSColin Finck            TheIdleProcess->UniqueProcessId,
1584c2c66affSColin Finck            TheIdleProcess->Pcb.KernelTime,
1585c2c66affSColin Finck            MiFreeSwapPages,
1586c2c66affSColin Finck            MiUsedSwapPages);
1587c2c66affSColin Finck 
1588c2c66affSColin Finck     *Spi = MiMemoryConsumers[MC_USER].PagesUsed;
1589c2c66affSColin Finck 
1590c2c66affSColin Finck     return STATUS_SUCCESS;
1591c2c66affSColin Finck }
1592c2c66affSColin Finck 
1593c2c66affSColin Finck /* Class 26 - Load Image */
1594c2c66affSColin Finck SSI_DEF(SystemLoadGdiDriverInformation)
1595c2c66affSColin Finck {
1596c2c66affSColin Finck     PSYSTEM_GDI_DRIVER_INFORMATION DriverInfo = (PVOID)Buffer;
1597c2c66affSColin Finck     UNICODE_STRING ImageName;
1598c2c66affSColin Finck     PVOID ImageBase;
1599c2c66affSColin Finck     PVOID SectionPointer;
1600c2c66affSColin Finck     ULONG_PTR EntryPoint;
1601c2c66affSColin Finck     NTSTATUS Status;
1602c2c66affSColin Finck     ULONG DirSize;
1603c2c66affSColin Finck     PIMAGE_NT_HEADERS NtHeader;
1604c2c66affSColin Finck 
1605c2c66affSColin Finck     /* Validate size */
1606c2c66affSColin Finck     if (Size != sizeof(SYSTEM_GDI_DRIVER_INFORMATION))
1607c2c66affSColin Finck     {
1608c2c66affSColin Finck         /* Incorrect buffer length, fail */
1609c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1610c2c66affSColin Finck     }
1611c2c66affSColin Finck 
1612c2c66affSColin Finck     /* Only kernel mode can call this function */
1613c2c66affSColin Finck     if (ExGetPreviousMode() != KernelMode) return STATUS_PRIVILEGE_NOT_HELD;
1614c2c66affSColin Finck 
1615c2c66affSColin Finck     /* Load the driver */
1616c2c66affSColin Finck     ImageName = DriverInfo->DriverName;
1617c2c66affSColin Finck     Status = MmLoadSystemImage(&ImageName,
1618c2c66affSColin Finck                                NULL,
1619c2c66affSColin Finck                                NULL,
1620c2c66affSColin Finck                                0,
1621c2c66affSColin Finck                                &SectionPointer,
1622c2c66affSColin Finck                                &ImageBase);
1623c2c66affSColin Finck     if (!NT_SUCCESS(Status)) return Status;
1624c2c66affSColin Finck 
1625c2c66affSColin Finck     /* Return the export pointer */
1626c2c66affSColin Finck     DriverInfo->ExportSectionPointer =
1627c2c66affSColin Finck         RtlImageDirectoryEntryToData(ImageBase,
1628c2c66affSColin Finck                                      TRUE,
1629c2c66affSColin Finck                                      IMAGE_DIRECTORY_ENTRY_EXPORT,
1630c2c66affSColin Finck                                      &DirSize);
1631c2c66affSColin Finck 
1632c2c66affSColin Finck     /* Get the entrypoint */
1633c2c66affSColin Finck     NtHeader = RtlImageNtHeader(ImageBase);
1634c2c66affSColin Finck     EntryPoint = NtHeader->OptionalHeader.AddressOfEntryPoint;
1635c2c66affSColin Finck     EntryPoint += (ULONG_PTR)ImageBase;
1636c2c66affSColin Finck 
1637c2c66affSColin Finck     /* Save other data */
1638c2c66affSColin Finck     DriverInfo->ImageAddress = ImageBase;
1639c2c66affSColin Finck     DriverInfo->SectionPointer = SectionPointer;
1640c2c66affSColin Finck     DriverInfo->EntryPoint = (PVOID)EntryPoint;
1641c2c66affSColin Finck     DriverInfo->ImageLength = NtHeader->OptionalHeader.SizeOfImage;
1642c2c66affSColin Finck 
1643c2c66affSColin Finck     /* All is good */
1644c2c66affSColin Finck     return STATUS_SUCCESS;
1645c2c66affSColin Finck }
1646c2c66affSColin Finck 
1647c2c66affSColin Finck /* Class 27 - Unload Image */
1648c2c66affSColin Finck SSI_DEF(SystemUnloadGdiDriverInformation)
1649c2c66affSColin Finck {
1650c2c66affSColin Finck     PVOID *SectionPointer = Buffer;
1651c2c66affSColin Finck 
1652c2c66affSColin Finck     /* Validate size */
1653c2c66affSColin Finck     if (Size != sizeof(PVOID))
1654c2c66affSColin Finck     {
1655c2c66affSColin Finck         /* Incorrect length, fail */
1656c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1657c2c66affSColin Finck     }
1658c2c66affSColin Finck 
1659c2c66affSColin Finck     /* Only kernel mode can call this function */
1660c2c66affSColin Finck     if (ExGetPreviousMode() != KernelMode) return STATUS_PRIVILEGE_NOT_HELD;
1661c2c66affSColin Finck 
1662c2c66affSColin Finck     /* Unload the image */
1663c2c66affSColin Finck     MmUnloadSystemImage(*SectionPointer);
1664c2c66affSColin Finck     return STATUS_SUCCESS;
1665c2c66affSColin Finck }
1666c2c66affSColin Finck 
1667c2c66affSColin Finck /* Class 28 - Time Adjustment Information */
1668c2c66affSColin Finck QSI_DEF(SystemTimeAdjustmentInformation)
1669c2c66affSColin Finck {
1670c2c66affSColin Finck     PSYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfo =
1671c2c66affSColin Finck         (PSYSTEM_QUERY_TIME_ADJUST_INFORMATION)Buffer;
1672c2c66affSColin Finck 
1673c2c66affSColin Finck     /* Check if enough storage was provided */
1674c2c66affSColin Finck     if (sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION) > Size)
1675c2c66affSColin Finck     {
1676c2c66affSColin Finck         * ReqSize = sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION);
1677c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1678c2c66affSColin Finck     }
1679c2c66affSColin Finck 
1680c2c66affSColin Finck     /* Give time values to our caller */
1681c2c66affSColin Finck     TimeInfo->TimeIncrement = KeMaximumIncrement;
1682c2c66affSColin Finck     TimeInfo->TimeAdjustment = KeTimeAdjustment;
1683c2c66affSColin Finck     TimeInfo->Enable = !KiTimeAdjustmentEnabled;
1684c2c66affSColin Finck 
1685c2c66affSColin Finck     return STATUS_SUCCESS;
1686c2c66affSColin Finck }
1687c2c66affSColin Finck 
1688c2c66affSColin Finck SSI_DEF(SystemTimeAdjustmentInformation)
1689c2c66affSColin Finck {
1690c2c66affSColin Finck     KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
1691c2c66affSColin Finck     PSYSTEM_SET_TIME_ADJUST_INFORMATION TimeInfo =
1692c2c66affSColin Finck         (PSYSTEM_SET_TIME_ADJUST_INFORMATION)Buffer;
1693c2c66affSColin Finck 
1694c2c66affSColin Finck     /* Check size of a buffer, it must match our expectations */
1695c2c66affSColin Finck     if (sizeof(SYSTEM_SET_TIME_ADJUST_INFORMATION) != Size)
1696c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1697c2c66affSColin Finck 
1698c2c66affSColin Finck     /* Check who is calling */
1699c2c66affSColin Finck     if (PreviousMode != KernelMode)
1700c2c66affSColin Finck     {
1701c2c66affSColin Finck         /* Check access rights */
1702c2c66affSColin Finck         if (!SeSinglePrivilegeCheck(SeSystemtimePrivilege, PreviousMode))
1703c2c66affSColin Finck         {
1704c2c66affSColin Finck             return STATUS_PRIVILEGE_NOT_HELD;
1705c2c66affSColin Finck         }
1706c2c66affSColin Finck     }
1707c2c66affSColin Finck 
1708c2c66affSColin Finck     /* FIXME: behaviour suggests the member be named 'Disable' */
1709c2c66affSColin Finck     if (TimeInfo->Enable)
1710c2c66affSColin Finck     {
1711c2c66affSColin Finck         /* Disable time adjustment and set default value */
1712c2c66affSColin Finck         KiTimeAdjustmentEnabled = FALSE;
1713c2c66affSColin Finck         KeTimeAdjustment = KeMaximumIncrement;
1714c2c66affSColin Finck     }
1715c2c66affSColin Finck     else
1716c2c66affSColin Finck     {
1717c2c66affSColin Finck         /* Check if a valid time adjustment value is given */
1718c2c66affSColin Finck         if (TimeInfo->TimeAdjustment == 0) return STATUS_INVALID_PARAMETER_2;
1719c2c66affSColin Finck 
1720c2c66affSColin Finck         /* Enable time adjustment and set the adjustment value */
1721c2c66affSColin Finck         KiTimeAdjustmentEnabled = TRUE;
1722c2c66affSColin Finck         KeTimeAdjustment = TimeInfo->TimeAdjustment;
1723c2c66affSColin Finck     }
1724c2c66affSColin Finck 
1725c2c66affSColin Finck     return STATUS_SUCCESS;
1726c2c66affSColin Finck }
1727c2c66affSColin Finck 
1728c2c66affSColin Finck /* Class 29 - Summary Memory Information */
1729c2c66affSColin Finck QSI_DEF(SystemSummaryMemoryInformation)
1730c2c66affSColin Finck {
1731c2c66affSColin Finck     /* FIXME */
1732c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemSummaryMemoryInformation not implemented\n");
1733c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1734c2c66affSColin Finck }
1735c2c66affSColin Finck 
1736c2c66affSColin Finck /* Class 30 - Next Event Id Information */
1737c2c66affSColin Finck QSI_DEF(SystemNextEventIdInformation)
1738c2c66affSColin Finck {
1739c2c66affSColin Finck     /* FIXME */
1740c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemNextEventIdInformation not implemented\n");
1741c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1742c2c66affSColin Finck }
1743c2c66affSColin Finck 
1744c2c66affSColin Finck /* Class 31 */
1745c2c66affSColin Finck QSI_DEF(SystemPerformanceTraceInformation)
1746c2c66affSColin Finck {
1747c2c66affSColin Finck     /* FIXME */
1748c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemPerformanceTraceInformation not implemented\n");
1749c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1750c2c66affSColin Finck }
1751c2c66affSColin Finck 
1752c2c66affSColin Finck /* Class 32 - Crash Dump Information */
1753c2c66affSColin Finck QSI_DEF(SystemCrashDumpInformation)
1754c2c66affSColin Finck {
1755c2c66affSColin Finck     /* FIXME */
1756c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemCrashDumpInformation not implemented\n");
1757c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1758c2c66affSColin Finck }
1759c2c66affSColin Finck 
1760c2c66affSColin Finck /* Class 33 - Exception Information */
1761c2c66affSColin Finck QSI_DEF(SystemExceptionInformation)
1762c2c66affSColin Finck {
1763c2c66affSColin Finck     PSYSTEM_EXCEPTION_INFORMATION ExceptionInformation =
1764c2c66affSColin Finck         (PSYSTEM_EXCEPTION_INFORMATION)Buffer;
1765c2c66affSColin Finck     PKPRCB Prcb;
1766c2c66affSColin Finck     ULONG AlignmentFixupCount = 0, ExceptionDispatchCount = 0;
1767c2c66affSColin Finck     ULONG FloatingEmulationCount = 0, ByteWordEmulationCount = 0;
1768c2c66affSColin Finck     CHAR i;
1769c2c66affSColin Finck 
1770c2c66affSColin Finck     /* Check size of a buffer, it must match our expectations */
1771c2c66affSColin Finck     if (sizeof(SYSTEM_EXCEPTION_INFORMATION) != Size)
1772c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1773c2c66affSColin Finck 
1774c2c66affSColin Finck     /* Sum up exception count information from all processors */
1775c2c66affSColin Finck     for (i = 0; i < KeNumberProcessors; i++)
1776c2c66affSColin Finck     {
1777c2c66affSColin Finck         Prcb = KiProcessorBlock[i];
1778c2c66affSColin Finck         if (Prcb)
1779c2c66affSColin Finck         {
1780c2c66affSColin Finck             AlignmentFixupCount += Prcb->KeAlignmentFixupCount;
1781c2c66affSColin Finck             ExceptionDispatchCount += Prcb->KeExceptionDispatchCount;
1782c2c66affSColin Finck #ifndef _M_ARM
1783c2c66affSColin Finck             FloatingEmulationCount += Prcb->KeFloatingEmulationCount;
1784c2c66affSColin Finck #endif // _M_ARM
1785c2c66affSColin Finck         }
1786c2c66affSColin Finck     }
1787c2c66affSColin Finck 
1788c2c66affSColin Finck     /* Save information in user's buffer */
1789c2c66affSColin Finck     ExceptionInformation->AlignmentFixupCount = AlignmentFixupCount;
1790c2c66affSColin Finck     ExceptionInformation->ExceptionDispatchCount = ExceptionDispatchCount;
1791c2c66affSColin Finck     ExceptionInformation->FloatingEmulationCount = FloatingEmulationCount;
1792c2c66affSColin Finck     ExceptionInformation->ByteWordEmulationCount = ByteWordEmulationCount;
1793c2c66affSColin Finck 
1794c2c66affSColin Finck     return STATUS_SUCCESS;
1795c2c66affSColin Finck }
1796c2c66affSColin Finck 
1797c2c66affSColin Finck /* Class 34 - Crash Dump State Information */
1798c2c66affSColin Finck QSI_DEF(SystemCrashDumpStateInformation)
1799c2c66affSColin Finck {
1800c2c66affSColin Finck     /* FIXME */
1801c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemCrashDumpStateInformation not implemented\n");
1802c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1803c2c66affSColin Finck }
1804c2c66affSColin Finck 
1805c2c66affSColin Finck /* Class 35 - Kernel Debugger Information */
1806c2c66affSColin Finck QSI_DEF(SystemKernelDebuggerInformation)
1807c2c66affSColin Finck {
1808c2c66affSColin Finck     PSYSTEM_KERNEL_DEBUGGER_INFORMATION skdi = (PSYSTEM_KERNEL_DEBUGGER_INFORMATION) Buffer;
1809c2c66affSColin Finck 
1810c2c66affSColin Finck #if (NTDDI_VERSION >= NTDDI_VISTA)
1811c2c66affSColin Finck     *ReqSize = sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION);
1812c2c66affSColin Finck #endif
1813c2c66affSColin Finck 
1814c2c66affSColin Finck     if (Size < sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION))
1815c2c66affSColin Finck     {
1816c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1817c2c66affSColin Finck     }
1818c2c66affSColin Finck 
1819c2c66affSColin Finck     skdi->KernelDebuggerEnabled = KD_DEBUGGER_ENABLED;
1820c2c66affSColin Finck     skdi->KernelDebuggerNotPresent = KD_DEBUGGER_NOT_PRESENT;
1821c2c66affSColin Finck 
1822c2c66affSColin Finck #if (NTDDI_VERSION < NTDDI_VISTA)
1823c2c66affSColin Finck     *ReqSize = sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION);
1824c2c66affSColin Finck #endif
1825c2c66affSColin Finck 
1826c2c66affSColin Finck     return STATUS_SUCCESS;
1827c2c66affSColin Finck }
1828c2c66affSColin Finck 
1829c2c66affSColin Finck /* Class 36 - Context Switch Information */
1830c2c66affSColin Finck QSI_DEF(SystemContextSwitchInformation)
1831c2c66affSColin Finck {
1832c2c66affSColin Finck     PSYSTEM_CONTEXT_SWITCH_INFORMATION ContextSwitchInformation =
1833c2c66affSColin Finck         (PSYSTEM_CONTEXT_SWITCH_INFORMATION)Buffer;
1834c2c66affSColin Finck     ULONG ContextSwitches;
1835c2c66affSColin Finck     PKPRCB Prcb;
1836c2c66affSColin Finck     CHAR i;
1837c2c66affSColin Finck 
1838c2c66affSColin Finck     /* Check size of a buffer, it must match our expectations */
1839c2c66affSColin Finck     if (sizeof(SYSTEM_CONTEXT_SWITCH_INFORMATION) != Size)
1840c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1841c2c66affSColin Finck 
1842c2c66affSColin Finck     /* Calculate total value of context switches across all processors */
1843c2c66affSColin Finck     ContextSwitches = 0;
1844c2c66affSColin Finck     for (i = 0; i < KeNumberProcessors; i ++)
1845c2c66affSColin Finck     {
1846c2c66affSColin Finck         Prcb = KiProcessorBlock[i];
1847c2c66affSColin Finck         if (Prcb)
1848c2c66affSColin Finck         {
1849c2c66affSColin Finck             ContextSwitches += KeGetContextSwitches(Prcb);
1850c2c66affSColin Finck         }
1851c2c66affSColin Finck     }
1852c2c66affSColin Finck 
1853c2c66affSColin Finck     ContextSwitchInformation->ContextSwitches = ContextSwitches;
1854c2c66affSColin Finck 
1855c2c66affSColin Finck     /* FIXME */
1856c2c66affSColin Finck     ContextSwitchInformation->FindAny = 0;
1857c2c66affSColin Finck     ContextSwitchInformation->FindLast = 0;
1858c2c66affSColin Finck     ContextSwitchInformation->FindIdeal = 0;
1859c2c66affSColin Finck     ContextSwitchInformation->IdleAny = 0;
1860c2c66affSColin Finck     ContextSwitchInformation->IdleCurrent = 0;
1861c2c66affSColin Finck     ContextSwitchInformation->IdleLast = 0;
1862c2c66affSColin Finck     ContextSwitchInformation->IdleIdeal = 0;
1863c2c66affSColin Finck     ContextSwitchInformation->PreemptAny = 0;
1864c2c66affSColin Finck     ContextSwitchInformation->PreemptCurrent = 0;
1865c2c66affSColin Finck     ContextSwitchInformation->PreemptLast = 0;
1866c2c66affSColin Finck     ContextSwitchInformation->SwitchToIdle = 0;
1867c2c66affSColin Finck 
1868c2c66affSColin Finck     return STATUS_SUCCESS;
1869c2c66affSColin Finck }
1870c2c66affSColin Finck 
1871c2c66affSColin Finck /* Class 37 - Registry Quota Information */
1872c2c66affSColin Finck QSI_DEF(SystemRegistryQuotaInformation)
1873c2c66affSColin Finck {
1874c2c66affSColin Finck     PSYSTEM_REGISTRY_QUOTA_INFORMATION srqi = (PSYSTEM_REGISTRY_QUOTA_INFORMATION) Buffer;
1875c2c66affSColin Finck 
1876c2c66affSColin Finck     *ReqSize = sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION);
1877c2c66affSColin Finck     if (Size < sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION))
1878c2c66affSColin Finck     {
1879c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1880c2c66affSColin Finck     }
1881c2c66affSColin Finck 
1882c2c66affSColin Finck     DPRINT1("Faking max registry size of 32 MB\n");
1883c2c66affSColin Finck     srqi->RegistryQuotaAllowed = 0x2000000;
1884c2c66affSColin Finck     srqi->RegistryQuotaUsed = 0x200000;
1885c2c66affSColin Finck     srqi->PagedPoolSize = 0x200000;
1886c2c66affSColin Finck 
1887c2c66affSColin Finck     return STATUS_SUCCESS;
1888c2c66affSColin Finck }
1889c2c66affSColin Finck 
1890c2c66affSColin Finck SSI_DEF(SystemRegistryQuotaInformation)
1891c2c66affSColin Finck {
1892c2c66affSColin Finck     /* FIXME */
1893c2c66affSColin Finck     DPRINT1("NtSetSystemInformation - SystemRegistryQuotaInformation not implemented\n");
1894c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
1895c2c66affSColin Finck }
1896c2c66affSColin Finck 
1897c2c66affSColin Finck /* Class 38 - Load And Call Image */
1898c2c66affSColin Finck SSI_DEF(SystemExtendServiceTableInformation)
1899c2c66affSColin Finck {
1900c2c66affSColin Finck     UNICODE_STRING ImageName;
1901c2c66affSColin Finck     KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
1902c2c66affSColin Finck     PLDR_DATA_TABLE_ENTRY ModuleObject;
1903c2c66affSColin Finck     NTSTATUS Status;
1904c2c66affSColin Finck     PIMAGE_NT_HEADERS NtHeader;
1905c2c66affSColin Finck     DRIVER_OBJECT Win32k;
1906c2c66affSColin Finck     PDRIVER_INITIALIZE DriverInit;
1907c2c66affSColin Finck     PVOID ImageBase;
1908c2c66affSColin Finck     ULONG_PTR EntryPoint;
1909c2c66affSColin Finck 
1910c2c66affSColin Finck     /* Validate the size */
1911c2c66affSColin Finck     if (Size != sizeof(UNICODE_STRING)) return STATUS_INFO_LENGTH_MISMATCH;
1912c2c66affSColin Finck 
1913c2c66affSColin Finck     /* Check who is calling */
1914c2c66affSColin Finck     if (PreviousMode != KernelMode)
1915c2c66affSColin Finck     {
1916c2c66affSColin Finck         static const UNICODE_STRING Win32kName =
1917c2c66affSColin Finck             RTL_CONSTANT_STRING(L"\\SystemRoot\\System32\\win32k.sys");
1918c2c66affSColin Finck 
1919c2c66affSColin Finck         /* Make sure we can load drivers */
1920c2c66affSColin Finck         if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege, UserMode))
1921c2c66affSColin Finck         {
1922c2c66affSColin Finck             /* FIXME: We can't, fail */
1923c2c66affSColin Finck             return STATUS_PRIVILEGE_NOT_HELD;
1924c2c66affSColin Finck         }
1925c2c66affSColin Finck 
1926c2c66affSColin Finck         _SEH2_TRY
1927c2c66affSColin Finck         {
1928c2c66affSColin Finck             /* Probe and copy the unicode string */
1929c2c66affSColin Finck             ProbeForRead(Buffer, sizeof(ImageName), 1);
1930c2c66affSColin Finck             ImageName = *(PUNICODE_STRING)Buffer;
1931c2c66affSColin Finck 
1932c2c66affSColin Finck             /* Probe the string buffer */
1933c2c66affSColin Finck             ProbeForRead(ImageName.Buffer, ImageName.Length, sizeof(WCHAR));
1934c2c66affSColin Finck 
1935c2c66affSColin Finck             /* Check if we have the correct name (nothing else is allowed!) */
1936c2c66affSColin Finck             if (!RtlEqualUnicodeString(&ImageName, &Win32kName, FALSE))
1937c2c66affSColin Finck             {
1938c2c66affSColin Finck                 _SEH2_YIELD(return STATUS_PRIVILEGE_NOT_HELD);
1939c2c66affSColin Finck             }
1940c2c66affSColin Finck         }
1941c2c66affSColin Finck         _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
1942c2c66affSColin Finck         {
1943c2c66affSColin Finck             _SEH2_YIELD(return _SEH2_GetExceptionCode());
1944c2c66affSColin Finck         }
1945c2c66affSColin Finck         _SEH2_END;
1946c2c66affSColin Finck 
1947c2c66affSColin Finck         /* Recursively call the function, so that we are from kernel mode */
1948c2c66affSColin Finck         return ZwSetSystemInformation(SystemExtendServiceTableInformation,
1949c2c66affSColin Finck                                       (PVOID)&Win32kName,
1950c2c66affSColin Finck                                       sizeof(Win32kName));
1951c2c66affSColin Finck     }
1952c2c66affSColin Finck 
1953c2c66affSColin Finck     /* Load the image */
1954c2c66affSColin Finck     Status = MmLoadSystemImage((PUNICODE_STRING)Buffer,
1955c2c66affSColin Finck                                NULL,
1956c2c66affSColin Finck                                NULL,
1957c2c66affSColin Finck                                0,
1958c2c66affSColin Finck                                (PVOID)&ModuleObject,
1959c2c66affSColin Finck                                &ImageBase);
1960c2c66affSColin Finck 
1961c2c66affSColin Finck     if (!NT_SUCCESS(Status)) return Status;
1962c2c66affSColin Finck 
1963c2c66affSColin Finck     /* Get the headers */
1964c2c66affSColin Finck     NtHeader = RtlImageNtHeader(ImageBase);
1965c2c66affSColin Finck     if (!NtHeader)
1966c2c66affSColin Finck     {
1967c2c66affSColin Finck         /* Fail */
1968c2c66affSColin Finck         MmUnloadSystemImage(ModuleObject);
1969c2c66affSColin Finck         return STATUS_INVALID_IMAGE_FORMAT;
1970c2c66affSColin Finck     }
1971c2c66affSColin Finck 
1972c2c66affSColin Finck     /* Get the entrypoint */
1973c2c66affSColin Finck     EntryPoint = NtHeader->OptionalHeader.AddressOfEntryPoint;
1974c2c66affSColin Finck     EntryPoint += (ULONG_PTR)ImageBase;
1975c2c66affSColin Finck     DriverInit = (PDRIVER_INITIALIZE)EntryPoint;
1976c2c66affSColin Finck 
1977c2c66affSColin Finck     /* Create a dummy device */
1978c2c66affSColin Finck     RtlZeroMemory(&Win32k, sizeof(Win32k));
1979c2c66affSColin Finck     ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
1980c2c66affSColin Finck     Win32k.DriverStart = ImageBase;
1981c2c66affSColin Finck 
1982c2c66affSColin Finck     /* Call it */
1983c2c66affSColin Finck     Status = (DriverInit)(&Win32k, NULL);
1984c2c66affSColin Finck     ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
1985c2c66affSColin Finck 
1986c2c66affSColin Finck     /* Unload if we failed */
1987c2c66affSColin Finck     if (!NT_SUCCESS(Status)) MmUnloadSystemImage(ModuleObject);
1988c2c66affSColin Finck     return Status;
1989c2c66affSColin Finck }
1990c2c66affSColin Finck 
1991c2c66affSColin Finck /* Class 39 - Priority Separation */
1992c2c66affSColin Finck SSI_DEF(SystemPrioritySeperation)
1993c2c66affSColin Finck {
1994c2c66affSColin Finck     /* Check if the size is correct */
1995c2c66affSColin Finck     if (Size != sizeof(ULONG))
1996c2c66affSColin Finck     {
1997c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
1998c2c66affSColin Finck     }
1999c2c66affSColin Finck 
2000c2c66affSColin Finck     /* We need the TCB privilege */
2001c2c66affSColin Finck     if (!SeSinglePrivilegeCheck(SeTcbPrivilege, ExGetPreviousMode()))
2002c2c66affSColin Finck     {
2003c2c66affSColin Finck         return STATUS_PRIVILEGE_NOT_HELD;
2004c2c66affSColin Finck     }
2005c2c66affSColin Finck 
2006c2c66affSColin Finck     /* Modify the quantum table */
2007c2c66affSColin Finck     PsChangeQuantumTable(TRUE, *(PULONG)Buffer);
2008c2c66affSColin Finck 
2009c2c66affSColin Finck     return STATUS_SUCCESS;
2010c2c66affSColin Finck }
2011c2c66affSColin Finck 
2012c2c66affSColin Finck /* Class 40 */
2013c2c66affSColin Finck QSI_DEF(SystemVerifierAddDriverInformation)
2014c2c66affSColin Finck {
2015c2c66affSColin Finck     /* FIXME */
2016c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemVerifierAddDriverInformation not implemented\n");
2017c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2018c2c66affSColin Finck }
2019c2c66affSColin Finck 
2020c2c66affSColin Finck /* Class 41 */
2021c2c66affSColin Finck QSI_DEF(SystemVerifierRemoveDriverInformation)
2022c2c66affSColin Finck {
2023c2c66affSColin Finck     /* FIXME */
2024c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemVerifierRemoveDriverInformation not implemented\n");
2025c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2026c2c66affSColin Finck }
2027c2c66affSColin Finck 
2028c2c66affSColin Finck /* Class 42 - Power Information */
2029c2c66affSColin Finck QSI_DEF(SystemProcessorIdleInformation)
2030c2c66affSColin Finck {
2031c2c66affSColin Finck     *ReqSize = sizeof(PROCESSOR_POWER_INFORMATION) * KeNumberProcessors;
2032c2c66affSColin Finck 
2033c2c66affSColin Finck     if (sizeof(PROCESSOR_POWER_INFORMATION) * KeNumberProcessors > Size)
2034c2c66affSColin Finck     {
2035c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
2036c2c66affSColin Finck     }
2037c2c66affSColin Finck 
2038c2c66affSColin Finck     /* FIXME */
2039c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemPowerInformation not implemented\n");
2040c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2041c2c66affSColin Finck }
2042c2c66affSColin Finck 
2043c2c66affSColin Finck /* Class 43 */
2044c2c66affSColin Finck QSI_DEF(SystemLegacyDriverInformation)
2045c2c66affSColin Finck {
2046c2c66affSColin Finck     /* FIXME */
2047c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemLegacyDriverInformation not implemented\n");
2048c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2049c2c66affSColin Finck }
2050c2c66affSColin Finck 
2051c2c66affSColin Finck /* Class 44 - Current Time Zone Information */
2052c2c66affSColin Finck QSI_DEF(SystemCurrentTimeZoneInformation)
2053c2c66affSColin Finck {
205449113829SEric Kohl     *ReqSize = sizeof(RTL_TIME_ZONE_INFORMATION);
2055c2c66affSColin Finck 
205649113829SEric Kohl     if (sizeof(RTL_TIME_ZONE_INFORMATION) != Size)
2057c2c66affSColin Finck     {
2058c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
2059c2c66affSColin Finck     }
2060c2c66affSColin Finck 
2061c2c66affSColin Finck     /* Copy the time zone information struct */
2062c2c66affSColin Finck     memcpy(Buffer,
2063c2c66affSColin Finck            &ExpTimeZoneInfo,
206449113829SEric Kohl            sizeof(RTL_TIME_ZONE_INFORMATION));
2065c2c66affSColin Finck 
2066c2c66affSColin Finck     return STATUS_SUCCESS;
2067c2c66affSColin Finck }
2068c2c66affSColin Finck 
2069c2c66affSColin Finck 
2070c2c66affSColin Finck SSI_DEF(SystemCurrentTimeZoneInformation)
2071c2c66affSColin Finck {
2072c2c66affSColin Finck     /* Check user buffer's size */
207349113829SEric Kohl     if (Size < sizeof(RTL_TIME_ZONE_INFORMATION))
2074c2c66affSColin Finck     {
2075c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
2076c2c66affSColin Finck     }
2077c2c66affSColin Finck 
207849113829SEric Kohl     return ExpSetTimeZoneInformation((PRTL_TIME_ZONE_INFORMATION)Buffer);
2079c2c66affSColin Finck }
2080c2c66affSColin Finck 
2081c2c66affSColin Finck static
2082c2c66affSColin Finck VOID
2083c2c66affSColin Finck ExpCopyLookasideInformation(
2084c2c66affSColin Finck     PSYSTEM_LOOKASIDE_INFORMATION *InfoPointer,
2085c2c66affSColin Finck     PULONG RemainingPointer,
2086c2c66affSColin Finck     PLIST_ENTRY ListHead,
2087c2c66affSColin Finck     BOOLEAN ListUsesMisses)
2088c2c66affSColin Finck 
2089c2c66affSColin Finck {
2090c2c66affSColin Finck     PSYSTEM_LOOKASIDE_INFORMATION Info;
2091c2c66affSColin Finck     PGENERAL_LOOKASIDE LookasideList;
2092c2c66affSColin Finck     PLIST_ENTRY ListEntry;
2093c2c66affSColin Finck     ULONG Remaining;
2094c2c66affSColin Finck 
2095c2c66affSColin Finck     /* Get info pointer and remaining count of free array element */
2096c2c66affSColin Finck     Info = *InfoPointer;
2097c2c66affSColin Finck     Remaining = *RemainingPointer;
2098c2c66affSColin Finck 
2099c2c66affSColin Finck     /* Loop as long as we have lookaside lists and free array elements */
2100c2c66affSColin Finck     for (ListEntry = ListHead->Flink;
2101c2c66affSColin Finck          (ListEntry != ListHead) && (Remaining > 0);
2102c2c66affSColin Finck          ListEntry = ListEntry->Flink, Remaining--)
2103c2c66affSColin Finck     {
2104c2c66affSColin Finck         LookasideList = CONTAINING_RECORD(ListEntry, GENERAL_LOOKASIDE, ListEntry);
2105c2c66affSColin Finck 
2106c2c66affSColin Finck         /* Fill the next array element */
2107c2c66affSColin Finck         Info->CurrentDepth = LookasideList->Depth;
2108c2c66affSColin Finck         Info->MaximumDepth = LookasideList->MaximumDepth;
2109c2c66affSColin Finck         Info->TotalAllocates = LookasideList->TotalAllocates;
2110c2c66affSColin Finck         Info->TotalFrees = LookasideList->TotalFrees;
2111c2c66affSColin Finck         Info->Type = LookasideList->Type;
2112c2c66affSColin Finck         Info->Tag = LookasideList->Tag;
2113c2c66affSColin Finck         Info->Size = LookasideList->Size;
2114c2c66affSColin Finck 
2115c2c66affSColin Finck         /* Check how the lists track misses/hits */
2116c2c66affSColin Finck         if (ListUsesMisses)
2117c2c66affSColin Finck         {
2118c2c66affSColin Finck             /* Copy misses */
2119c2c66affSColin Finck             Info->AllocateMisses = LookasideList->AllocateMisses;
2120c2c66affSColin Finck             Info->FreeMisses = LookasideList->FreeMisses;
2121c2c66affSColin Finck         }
2122c2c66affSColin Finck         else
2123c2c66affSColin Finck         {
2124c2c66affSColin Finck             /* Calculate misses */
2125c2c66affSColin Finck             Info->AllocateMisses = LookasideList->TotalAllocates
2126c2c66affSColin Finck                                    - LookasideList->AllocateHits;
2127c2c66affSColin Finck             Info->FreeMisses = LookasideList->TotalFrees
2128c2c66affSColin Finck                                - LookasideList->FreeHits;
2129c2c66affSColin Finck         }
2130c2c66affSColin Finck     }
2131c2c66affSColin Finck 
2132c2c66affSColin Finck     /* Return the updated pointer and remaining count */
2133c2c66affSColin Finck     *InfoPointer = Info;
2134c2c66affSColin Finck     *RemainingPointer = Remaining;
2135c2c66affSColin Finck }
2136c2c66affSColin Finck 
2137c2c66affSColin Finck /* Class 45 - Lookaside Information */
2138c2c66affSColin Finck QSI_DEF(SystemLookasideInformation)
2139c2c66affSColin Finck {
2140c2c66affSColin Finck     KPROCESSOR_MODE PreviousMode;
2141c2c66affSColin Finck     PSYSTEM_LOOKASIDE_INFORMATION Info;
2142c2c66affSColin Finck     PMDL Mdl;
2143c2c66affSColin Finck     ULONG MaxCount, Remaining;
2144c2c66affSColin Finck     KIRQL OldIrql;
2145c2c66affSColin Finck     NTSTATUS Status;
2146c2c66affSColin Finck 
2147c2c66affSColin Finck     /* First we need to lock down the memory, since we are going to access it
2148c2c66affSColin Finck        at high IRQL */
2149c2c66affSColin Finck     PreviousMode = ExGetPreviousMode();
2150c2c66affSColin Finck     Status = ExLockUserBuffer(Buffer,
2151c2c66affSColin Finck                               Size,
2152c2c66affSColin Finck                               PreviousMode,
2153c2c66affSColin Finck                               IoWriteAccess,
2154c2c66affSColin Finck                               (PVOID*)&Info,
2155c2c66affSColin Finck                               &Mdl);
2156c2c66affSColin Finck     if (!NT_SUCCESS(Status))
2157c2c66affSColin Finck     {
2158c2c66affSColin Finck         DPRINT1("Failed to lock the user buffer: 0x%lx\n", Status);
2159c2c66affSColin Finck         return Status;
2160c2c66affSColin Finck     }
2161c2c66affSColin Finck 
2162c2c66affSColin Finck     /* Calculate how many items we can store */
2163c2c66affSColin Finck     Remaining = MaxCount = Size / sizeof(SYSTEM_LOOKASIDE_INFORMATION);
2164c2c66affSColin Finck     if (Remaining == 0)
2165c2c66affSColin Finck     {
2166c2c66affSColin Finck         goto Leave;
2167c2c66affSColin Finck     }
2168c2c66affSColin Finck 
2169c2c66affSColin Finck     /* Copy info from pool lookaside lists */
2170c2c66affSColin Finck     ExpCopyLookasideInformation(&Info,
2171c2c66affSColin Finck                                 &Remaining,
2172c2c66affSColin Finck                                 &ExPoolLookasideListHead,
2173c2c66affSColin Finck                                 FALSE);
2174c2c66affSColin Finck     if (Remaining == 0)
2175c2c66affSColin Finck     {
2176c2c66affSColin Finck         goto Leave;
2177c2c66affSColin Finck     }
2178c2c66affSColin Finck 
2179c2c66affSColin Finck     /* Copy info from system lookaside lists */
2180c2c66affSColin Finck     ExpCopyLookasideInformation(&Info,
2181c2c66affSColin Finck                                 &Remaining,
2182c2c66affSColin Finck                                 &ExSystemLookasideListHead,
2183c2c66affSColin Finck                                 TRUE);
2184c2c66affSColin Finck     if (Remaining == 0)
2185c2c66affSColin Finck     {
2186c2c66affSColin Finck         goto Leave;
2187c2c66affSColin Finck     }
2188c2c66affSColin Finck 
2189c2c66affSColin Finck     /* Acquire spinlock for ExpNonPagedLookasideListHead */
2190c2c66affSColin Finck     KeAcquireSpinLock(&ExpNonPagedLookasideListLock, &OldIrql);
2191c2c66affSColin Finck 
2192c2c66affSColin Finck     /* Copy info from non-paged lookaside lists */
2193c2c66affSColin Finck     ExpCopyLookasideInformation(&Info,
2194c2c66affSColin Finck                                 &Remaining,
2195c2c66affSColin Finck                                 &ExpNonPagedLookasideListHead,
2196c2c66affSColin Finck                                 TRUE);
2197c2c66affSColin Finck 
2198c2c66affSColin Finck     /* Release spinlock for ExpNonPagedLookasideListHead */
2199c2c66affSColin Finck     KeReleaseSpinLock(&ExpNonPagedLookasideListLock, OldIrql);
2200c2c66affSColin Finck 
2201c2c66affSColin Finck     if (Remaining == 0)
2202c2c66affSColin Finck     {
2203c2c66affSColin Finck         goto Leave;
2204c2c66affSColin Finck     }
2205c2c66affSColin Finck 
2206c2c66affSColin Finck     /* Acquire spinlock for ExpPagedLookasideListHead */
2207c2c66affSColin Finck     KeAcquireSpinLock(&ExpPagedLookasideListLock, &OldIrql);
2208c2c66affSColin Finck 
2209c2c66affSColin Finck     /* Copy info from paged lookaside lists */
2210c2c66affSColin Finck     ExpCopyLookasideInformation(&Info,
2211c2c66affSColin Finck                                 &Remaining,
2212c2c66affSColin Finck                                 &ExpPagedLookasideListHead,
2213c2c66affSColin Finck                                 TRUE);
2214c2c66affSColin Finck 
2215c2c66affSColin Finck     /* Release spinlock for ExpPagedLookasideListHead */
2216c2c66affSColin Finck     KeReleaseSpinLock(&ExpPagedLookasideListLock, OldIrql);
2217c2c66affSColin Finck 
2218c2c66affSColin Finck Leave:
2219c2c66affSColin Finck 
2220c2c66affSColin Finck     /* Release the locked user buffer */
2221c2c66affSColin Finck     ExUnlockUserBuffer(Mdl);
2222c2c66affSColin Finck 
2223c2c66affSColin Finck     /* Return the size of the actually written data */
2224c2c66affSColin Finck     *ReqSize = (MaxCount - Remaining) * sizeof(SYSTEM_LOOKASIDE_INFORMATION);
2225c2c66affSColin Finck     return STATUS_SUCCESS;
2226c2c66affSColin Finck }
2227c2c66affSColin Finck 
2228c2c66affSColin Finck 
2229c2c66affSColin Finck /* Class 46 - Set time slip event */
2230c2c66affSColin Finck SSI_DEF(SystemTimeSlipNotification)
2231c2c66affSColin Finck {
2232c2c66affSColin Finck     /* FIXME */
2233c2c66affSColin Finck     DPRINT1("NtSetSystemInformation - SystemTimeSlipNotification not implemented\n");
2234c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2235c2c66affSColin Finck }
2236c2c66affSColin Finck 
2237c2c66affSColin Finck NTSTATUS
2238c2c66affSColin Finck NTAPI
2239c2c66affSColin Finck MmSessionCreate(OUT PULONG SessionId);
2240c2c66affSColin Finck 
2241c2c66affSColin Finck NTSTATUS
2242c2c66affSColin Finck NTAPI
2243c2c66affSColin Finck MmSessionDelete(IN ULONG SessionId);
2244c2c66affSColin Finck 
2245c2c66affSColin Finck /* Class 47 - Create a new session (TSE) */
2246c2c66affSColin Finck SSI_DEF(SystemSessionCreate)
2247c2c66affSColin Finck {
2248c2c66affSColin Finck     ULONG SessionId;
2249c2c66affSColin Finck     KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
2250c2c66affSColin Finck     NTSTATUS Status;
2251c2c66affSColin Finck 
2252c2c66affSColin Finck     if (Size != sizeof(ULONG)) return STATUS_INFO_LENGTH_MISMATCH;
2253c2c66affSColin Finck 
2254c2c66affSColin Finck     if (PreviousMode != KernelMode)
2255c2c66affSColin Finck     {
2256c2c66affSColin Finck         if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege, PreviousMode))
2257c2c66affSColin Finck         {
2258c2c66affSColin Finck             return STATUS_PRIVILEGE_NOT_HELD;
2259c2c66affSColin Finck         }
2260c2c66affSColin Finck 
2261c2c66affSColin Finck         ProbeForWriteUlong(Buffer);
2262c2c66affSColin Finck     }
2263c2c66affSColin Finck 
2264c2c66affSColin Finck     Status = MmSessionCreate(&SessionId);
2265c2c66affSColin Finck     if (NT_SUCCESS(Status)) *(PULONG)Buffer = SessionId;
2266c2c66affSColin Finck 
2267c2c66affSColin Finck     return Status;
2268c2c66affSColin Finck }
2269c2c66affSColin Finck 
2270c2c66affSColin Finck 
2271c2c66affSColin Finck /* Class 48 - Delete an existing session (TSE) */
2272c2c66affSColin Finck SSI_DEF(SystemSessionDetach)
2273c2c66affSColin Finck {
2274c2c66affSColin Finck     ULONG SessionId;
2275c2c66affSColin Finck     KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
2276c2c66affSColin Finck 
2277c2c66affSColin Finck     if (Size != sizeof(ULONG)) return STATUS_INFO_LENGTH_MISMATCH;
2278c2c66affSColin Finck 
2279c2c66affSColin Finck     if (PreviousMode != KernelMode)
2280c2c66affSColin Finck     {
2281c2c66affSColin Finck         if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege, PreviousMode))
2282c2c66affSColin Finck         {
2283c2c66affSColin Finck             return STATUS_PRIVILEGE_NOT_HELD;
2284c2c66affSColin Finck         }
2285c2c66affSColin Finck     }
2286c2c66affSColin Finck 
2287c2c66affSColin Finck     SessionId = *(PULONG)Buffer;
2288c2c66affSColin Finck 
2289c2c66affSColin Finck     return MmSessionDelete(SessionId);
2290c2c66affSColin Finck }
2291c2c66affSColin Finck 
2292c2c66affSColin Finck 
2293c2c66affSColin Finck /* Class 49 - UNKNOWN */
2294c2c66affSColin Finck QSI_DEF(SystemSessionInformation)
2295c2c66affSColin Finck {
2296c2c66affSColin Finck     /* FIXME */
2297c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemSessionInformation not implemented\n");
2298c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2299c2c66affSColin Finck }
2300c2c66affSColin Finck 
2301c2c66affSColin Finck 
2302c2c66affSColin Finck /* Class 50 - System range start address */
2303c2c66affSColin Finck QSI_DEF(SystemRangeStartInformation)
2304c2c66affSColin Finck {
2305c2c66affSColin Finck     /* Check user buffer's size */
2306c2c66affSColin Finck     if (Size != sizeof(ULONG_PTR)) return STATUS_INFO_LENGTH_MISMATCH;
2307c2c66affSColin Finck 
2308c2c66affSColin Finck     *(PULONG_PTR)Buffer = (ULONG_PTR)MmSystemRangeStart;
2309c2c66affSColin Finck 
2310c2c66affSColin Finck     if (ReqSize) *ReqSize = sizeof(ULONG_PTR);
2311c2c66affSColin Finck 
2312c2c66affSColin Finck     return STATUS_SUCCESS;
2313c2c66affSColin Finck }
2314c2c66affSColin Finck 
2315c2c66affSColin Finck /* Class 51 - Driver verifier information */
2316c2c66affSColin Finck QSI_DEF(SystemVerifierInformation)
2317c2c66affSColin Finck {
2318c2c66affSColin Finck     /* FIXME */
2319c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemVerifierInformation not implemented\n");
2320c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2321c2c66affSColin Finck }
2322c2c66affSColin Finck 
2323c2c66affSColin Finck 
2324c2c66affSColin Finck SSI_DEF(SystemVerifierInformation)
2325c2c66affSColin Finck {
2326c2c66affSColin Finck     /* FIXME */
2327c2c66affSColin Finck     DPRINT1("NtSetSystemInformation - SystemVerifierInformation not implemented\n");
2328c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2329c2c66affSColin Finck }
2330c2c66affSColin Finck 
2331c2c66affSColin Finck 
2332c2c66affSColin Finck /* Class 52 */
2333c2c66affSColin Finck SSI_DEF(SystemVerifierThunkExtend)
2334c2c66affSColin Finck {
2335c2c66affSColin Finck     /* FIXME */
2336c2c66affSColin Finck     DPRINT1("NtSetSystemInformation - SystemVerifierThunkExtend not implemented\n");
2337c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2338c2c66affSColin Finck }
2339c2c66affSColin Finck 
2340c2c66affSColin Finck 
2341c2c66affSColin Finck /* Class 53 - A session's processes  */
2342c2c66affSColin Finck QSI_DEF(SystemSessionProcessesInformation)
2343c2c66affSColin Finck {
2344c2c66affSColin Finck     /* FIXME */
2345c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemSessionProcessInformation not implemented\n");
2346c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2347c2c66affSColin Finck }
2348c2c66affSColin Finck 
2349c2c66affSColin Finck 
2350c2c66affSColin Finck /* Class 54 - Load & map in system space */
2351c2c66affSColin Finck SSI_DEF(SystemLoadGdiDriverInSystemSpaceInformation)
2352c2c66affSColin Finck {
2353c2c66affSColin Finck     /* FIXME */
2354c2c66affSColin Finck     DPRINT1("NtSetSystemInformation - SystemLoadGdiDriverInSystemSpaceInformation not implemented\n");
2355c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2356c2c66affSColin Finck }
2357c2c66affSColin Finck 
2358c2c66affSColin Finck 
2359c2c66affSColin Finck /* Class 55 - NUMA processor information  */
2360c2c66affSColin Finck QSI_DEF(SystemNumaProcessorMap)
2361c2c66affSColin Finck {
2362c2c66affSColin Finck     ULONG MaxEntries, Node;
2363c2c66affSColin Finck     PSYSTEM_NUMA_INFORMATION NumaInformation = (PSYSTEM_NUMA_INFORMATION)Buffer;
2364c2c66affSColin Finck 
2365c2c66affSColin Finck     /* Validate input size */
2366c2c66affSColin Finck     if (Size < sizeof(ULONG))
2367c2c66affSColin Finck     {
2368c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
2369c2c66affSColin Finck     }
2370c2c66affSColin Finck 
2371c2c66affSColin Finck     /* Return highest node */
2372c2c66affSColin Finck     NumaInformation->HighestNodeNumber = KeNumberNodes - 1;
2373c2c66affSColin Finck 
2374c2c66affSColin Finck     /* Compute how much entries we will be able to put in output structure */
2375c2c66affSColin Finck     MaxEntries = (Size - FIELD_OFFSET(SYSTEM_NUMA_INFORMATION, ActiveProcessorsAffinityMask)) / sizeof(ULONGLONG);
2376c2c66affSColin Finck     /* Make sure we don't overflow KeNodeBlock */
2377c2c66affSColin Finck     if (MaxEntries > KeNumberNodes)
2378c2c66affSColin Finck     {
2379c2c66affSColin Finck         MaxEntries = KeNumberNodes;
2380c2c66affSColin Finck     }
2381c2c66affSColin Finck 
2382c2c66affSColin Finck     /* If we have entries to write, and room for it */
2383c2c66affSColin Finck     if (Size >= FIELD_OFFSET(SYSTEM_NUMA_INFORMATION, ActiveProcessorsAffinityMask) &&
2384c2c66affSColin Finck         MaxEntries != 0)
2385c2c66affSColin Finck     {
2386c2c66affSColin Finck         /* Already set size we return */
2387c2c66affSColin Finck         *ReqSize = FIELD_OFFSET(SYSTEM_NUMA_INFORMATION, ActiveProcessorsAffinityMask) +
2388c2c66affSColin Finck                    MaxEntries * sizeof(ULONGLONG);
2389c2c66affSColin Finck 
2390c2c66affSColin Finck         /* For each node, return processor mask */
2391c2c66affSColin Finck         for (Node = 0; Node < MaxEntries; ++Node)
2392c2c66affSColin Finck         {
2393c2c66affSColin Finck             NumaInformation->ActiveProcessorsAffinityMask[Node] = KeNodeBlock[Node]->ProcessorMask;
2394c2c66affSColin Finck         }
2395c2c66affSColin Finck     }
2396c2c66affSColin Finck     else
2397c2c66affSColin Finck     {
2398c2c66affSColin Finck         /* We only returned highest node number */
2399c2c66affSColin Finck         *ReqSize = sizeof(ULONG);
2400c2c66affSColin Finck     }
2401c2c66affSColin Finck 
2402c2c66affSColin Finck     return STATUS_SUCCESS;
2403c2c66affSColin Finck }
2404c2c66affSColin Finck 
2405c2c66affSColin Finck 
2406c2c66affSColin Finck /* Class 56 - Prefetcher information  */
2407c2c66affSColin Finck QSI_DEF(SystemPrefetcherInformation)
2408c2c66affSColin Finck {
2409c2c66affSColin Finck     /* FIXME */
2410c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemPrefetcherInformation not implemented\n");
2411c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2412c2c66affSColin Finck }
2413c2c66affSColin Finck 
2414c2c66affSColin Finck 
2415c2c66affSColin Finck /* Class 57 - Extended process information  */
2416c2c66affSColin Finck QSI_DEF(SystemExtendedProcessInformation)
2417c2c66affSColin Finck {
2418c2c66affSColin Finck     /* FIXME */
2419c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemExtendedProcessInformation not implemented\n");
2420c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2421c2c66affSColin Finck }
2422c2c66affSColin Finck 
2423c2c66affSColin Finck 
2424c2c66affSColin Finck /* Class 58 - Recommended shared ata alignment  */
2425c2c66affSColin Finck QSI_DEF(SystemRecommendedSharedDataAlignment)
2426c2c66affSColin Finck {
2427c2c66affSColin Finck     /* FIXME */
2428c2c66affSColin Finck     DPRINT1("NtQuerySystemInformation - SystemRecommendedSharedDataAlignment not implemented\n");
2429c2c66affSColin Finck     return STATUS_NOT_IMPLEMENTED;
2430c2c66affSColin Finck }
2431c2c66affSColin Finck 
2432c2c66affSColin Finck 
2433c2c66affSColin Finck /* Class 60 - NUMA memory information  */
2434c2c66affSColin Finck QSI_DEF(SystemNumaAvailableMemory)
2435c2c66affSColin Finck {
2436c2c66affSColin Finck     ULONG MaxEntries, Node;
2437c2c66affSColin Finck     PSYSTEM_NUMA_INFORMATION NumaInformation = (PSYSTEM_NUMA_INFORMATION)Buffer;
2438c2c66affSColin Finck 
2439c2c66affSColin Finck     /* Validate input size */
2440c2c66affSColin Finck     if (Size < sizeof(ULONG))
2441c2c66affSColin Finck     {
2442c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
2443c2c66affSColin Finck     }
2444c2c66affSColin Finck 
2445c2c66affSColin Finck     /* Return highest node */
2446c2c66affSColin Finck     NumaInformation->HighestNodeNumber = KeNumberNodes - 1;
2447c2c66affSColin Finck 
2448c2c66affSColin Finck     /* Compute how much entries we will be able to put in output structure */
2449c2c66affSColin Finck     MaxEntries = (Size - FIELD_OFFSET(SYSTEM_NUMA_INFORMATION, AvailableMemory)) / sizeof(ULONGLONG);
2450c2c66affSColin Finck     /* Make sure we don't overflow KeNodeBlock */
2451c2c66affSColin Finck     if (MaxEntries > KeNumberNodes)
2452c2c66affSColin Finck     {
2453c2c66affSColin Finck         MaxEntries = KeNumberNodes;
2454c2c66affSColin Finck     }
2455c2c66affSColin Finck 
2456c2c66affSColin Finck     /* If we have entries to write, and room for it */
2457c2c66affSColin Finck     if (Size >= FIELD_OFFSET(SYSTEM_NUMA_INFORMATION, AvailableMemory) &&
2458c2c66affSColin Finck         MaxEntries != 0)
2459c2c66affSColin Finck     {
2460c2c66affSColin Finck         /* Already set size we return */
2461c2c66affSColin Finck         *ReqSize = FIELD_OFFSET(SYSTEM_NUMA_INFORMATION, AvailableMemory) +
2462c2c66affSColin Finck                    MaxEntries * sizeof(ULONGLONG);
2463c2c66affSColin Finck 
2464c2c66affSColin Finck         /* If we have a single entry (us), directly return MM information */
2465c2c66affSColin Finck         if (MaxEntries == 1)
2466c2c66affSColin Finck         {
2467c2c66affSColin Finck             NumaInformation->AvailableMemory[0] = MmAvailablePages << PAGE_SHIFT;
2468c2c66affSColin Finck         }
2469c2c66affSColin Finck         else
2470c2c66affSColin Finck         {
2471c2c66affSColin Finck             /* Otherwise, for each node, return available bytes */
2472c2c66affSColin Finck             for (Node = 0; Node < MaxEntries; ++Node)
2473c2c66affSColin Finck             {
2474c2c66affSColin Finck                 NumaInformation->AvailableMemory[Node] = (KeNodeBlock[Node]->FreeCount[0] + KeNodeBlock[Node]->FreeCount[1]) << PAGE_SHIFT;
2475c2c66affSColin Finck             }
2476c2c66affSColin Finck         }
2477c2c66affSColin Finck     }
2478c2c66affSColin Finck     else
2479c2c66affSColin Finck     {
2480c2c66affSColin Finck         /* We only returned highest node number */
2481c2c66affSColin Finck         *ReqSize = sizeof(ULONG);
2482c2c66affSColin Finck     }
2483c2c66affSColin Finck 
2484c2c66affSColin Finck     return STATUS_SUCCESS;
2485c2c66affSColin Finck }
2486c2c66affSColin Finck 
2487c2c66affSColin Finck /* Class 64 - Extended handle information  */
2488c2c66affSColin Finck QSI_DEF(SystemExtendedHandleInformation)
2489c2c66affSColin Finck {
2490c2c66affSColin Finck     PSYSTEM_HANDLE_INFORMATION_EX HandleInformation;
2491c2c66affSColin Finck     PLIST_ENTRY NextTableEntry;
2492c2c66affSColin Finck     PHANDLE_TABLE HandleTable;
2493c2c66affSColin Finck     PHANDLE_TABLE_ENTRY HandleTableEntry;
2494c2c66affSColin Finck     EXHANDLE Handle;
2495c2c66affSColin Finck     ULONG Index = 0;
2496c2c66affSColin Finck     NTSTATUS Status;
2497c2c66affSColin Finck     PMDL Mdl;
2498c2c66affSColin Finck     PAGED_CODE();
2499c2c66affSColin Finck 
2500c2c66affSColin Finck     DPRINT("NtQuerySystemInformation - SystemExtendedHandleInformation\n");
2501c2c66affSColin Finck 
2502c2c66affSColin Finck     /* Set initial required buffer size */
2503c2c66affSColin Finck     *ReqSize = FIELD_OFFSET(SYSTEM_HANDLE_INFORMATION_EX, Handle);
2504c2c66affSColin Finck 
2505c2c66affSColin Finck     /* Check user's buffer size */
2506c2c66affSColin Finck     if (Size < *ReqSize)
2507c2c66affSColin Finck     {
2508c2c66affSColin Finck         return STATUS_INFO_LENGTH_MISMATCH;
2509c2c66affSColin Finck     }
2510c2c66affSColin Finck 
2511c2c66affSColin Finck     /* We need to lock down the memory */
2512c2c66affSColin Finck     Status = ExLockUserBuffer(Buffer,
2513c2c66affSColin Finck                               Size,
2514c2c66affSColin Finck                               ExGetPreviousMode(),
2515c2c66affSColin Finck                               IoWriteAccess,
2516c2c66affSColin Finck                               (PVOID*)&HandleInformation,
2517c2c66affSColin Finck                               &Mdl);
2518c2c66affSColin Finck     if (!NT_SUCCESS(Status))
2519c2c66affSColin Finck     {
2520c2c66affSColin Finck         DPRINT1("Failed to lock the user buffer: 0x%lx\n", Status);
2521c2c66affSColin Finck         return Status;
2522c2c66affSColin Finck     }
2523c2c66affSColin Finck 
2524c2c66affSColin Finck     /* Reset of count of handles */
2525c2c66affSColin Finck     HandleInformation->Count = 0;
2526c2c66affSColin Finck 
2527c2c66affSColin Finck     /* Enter a critical region */
2528c2c66affSColin Finck     KeEnterCriticalRegion();
2529c2c66affSColin Finck 
2530c2c66affSColin Finck     /* Acquire the handle table lock */
2531c2c66affSColin Finck     ExAcquirePushLockShared(&HandleTableListLock);
2532c2c66affSColin Finck 
2533c2c66affSColin Finck     /* Enumerate all system handles */
2534c2c66affSColin Finck     for (NextTableEntry = HandleTableListHead.Flink;
2535c2c66affSColin Finck          NextTableEntry != &HandleTableListHead;
2536c2c66affSColin Finck          NextTableEntry = NextTableEntry->Flink)
2537c2c66affSColin Finck     {
2538c2c66affSColin Finck         /* Get current handle table */
2539c2c66affSColin Finck         HandleTable = CONTAINING_RECORD(NextTableEntry, HANDLE_TABLE, HandleTableList);
2540c2c66affSColin Finck 
2541c2c66affSColin Finck         /* Set the initial value and loop the entries */
2542c2c66affSColin Finck         Handle.Value = 0;
2543c2c66affSColin Finck         while ((HandleTableEntry = ExpLookupHandleTableEntry(HandleTable, Handle)))
2544c2c66affSColin Finck         {
2545c2c66affSColin Finck             /* Validate the entry */
2546c2c66affSColin Finck             if ((HandleTableEntry->Object) &&
2547c2c66affSColin Finck                 (HandleTableEntry->NextFreeTableEntry != -2))
2548c2c66affSColin Finck             {
2549c2c66affSColin Finck                 /* Increase of count of handles */
2550c2c66affSColin Finck                 ++HandleInformation->Count;
2551c2c66affSColin Finck 
2552c2c66affSColin Finck                 /* Lock the entry */
2553c2c66affSColin Finck                 if (ExpLockHandleTableEntry(HandleTable, HandleTableEntry))
2554c2c66affSColin Finck                 {
2555c2c66affSColin Finck                     /* Increase required buffer size */
2556c2c66affSColin Finck                     *ReqSize += sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX);
2557c2c66affSColin Finck 
2558c2c66affSColin Finck                     /* Check user's buffer size */
2559c2c66affSColin Finck                     if (*ReqSize > Size)
2560c2c66affSColin Finck                     {
2561c2c66affSColin Finck                         Status = STATUS_INFO_LENGTH_MISMATCH;
2562c2c66affSColin Finck                     }
2563c2c66affSColin Finck                     else
2564c2c66affSColin Finck                     {
2565c2c66affSColin Finck                         POBJECT_HEADER ObjectHeader = ObpGetHandleObject(HandleTableEntry);
2566c2c66affSColin Finck 
2567c2c66affSColin Finck                         /* Filling handle information */
2568c2c66affSColin Finck                         HandleInformation->Handle[Index].UniqueProcessId =
2569c2c66affSColin Finck                             (USHORT)(ULONG_PTR) HandleTable->UniqueProcessId;
2570c2c66affSColin Finck 
2571c2c66affSColin Finck                         HandleInformation->Handle[Index].CreatorBackTraceIndex = 0;
2572c2c66affSColin Finck 
2573c2c66affSColin Finck #if 0 /* FIXME!!! Type field currupted */
2574c2c66affSColin Finck                         HandleInformation->Handles[Index].ObjectTypeIndex =
2575c2c66affSColin Finck                             (UCHAR) ObjectHeader->Type->Index;
2576c2c66affSColin Finck #else
2577c2c66affSColin Finck                         HandleInformation->Handle[Index].ObjectTypeIndex = 0;
2578c2c66affSColin Finck #endif
2579c2c66affSColin Finck 
2580c2c66affSColin Finck                         HandleInformation->Handle[Index].HandleAttributes =
2581c2c66affSColin Finck                             HandleTableEntry->ObAttributes & OBJ_HANDLE_ATTRIBUTES;
2582c2c66affSColin Finck 
2583c2c66affSColin Finck                         HandleInformation->Handle[Index].HandleValue =
2584c2c66affSColin Finck                             (USHORT)(ULONG_PTR) Handle.GenericHandleOverlay;
2585c2c66affSColin Finck 
2586c2c66affSColin Finck                         HandleInformation->Handle[Index].Object = &ObjectHeader->Body;
2587c2c66affSColin Finck 
2588c2c66affSColin Finck                         HandleInformation->Handle[Index].GrantedAccess =
2589c2c66affSColin Finck                             HandleTableEntry->GrantedAccess;
2590c2c66affSColin Finck 
2591c2c66affSColin Finck                         HandleInformation->Handle[Index].Reserved = 0;
2592c2c66affSColin Finck 
2593c2c66affSColin Finck                         ++Index;
2594c2c66affSColin Finck                     }
2595c2c66affSColin Finck 
2596c2c66affSColin Finck                     /* Unlock it */
2597c2c66affSColin Finck                     ExUnlockHandleTableEntry(HandleTable, HandleTableEntry);
2598c2c66affSColin Finck                 }
2599c2c66affSColin Finck             }
2600c2c66affSColin Finck 
2601c2c66affSColin Finck             /* Go to the next entry */
2602c2c66affSColin Finck             Handle.Value += sizeof(HANDLE);
2603c2c66affSColin Finck         }
2604c2c66affSColin Finck     }
2605c2c66affSColin Finck 
2606c2c66affSColin Finck     /* Release the lock */
2607c2c66affSColin Finck     ExReleasePushLockShared(&HandleTableListLock);
2608c2c66affSColin Finck 
2609c2c66affSColin Finck     /* Leave the critical region */
2610c2c66affSColin Finck     KeLeaveCriticalRegion();
2611c2c66affSColin Finck 
2612c2c66affSColin Finck     /* Release the locked user buffer */
2613c2c66affSColin Finck     ExUnlockUserBuffer(Mdl);
2614c2c66affSColin Finck 
2615c2c66affSColin Finck     return Status;
2616c2c66affSColin Finck }
2617c2c66affSColin Finck 
2618d033fe9bSStanislav Motylkov /* Class 76 - System firmware table information  */
2619d033fe9bSStanislav Motylkov QSI_DEF(SystemFirmwareTableInformation)
2620d033fe9bSStanislav Motylkov {
2621d033fe9bSStanislav Motylkov     PSYSTEM_FIRMWARE_TABLE_INFORMATION SysFirmwareInfo = (PSYSTEM_FIRMWARE_TABLE_INFORMATION)Buffer;
2622d033fe9bSStanislav Motylkov     NTSTATUS Status = STATUS_SUCCESS;
2623d033fe9bSStanislav Motylkov     ULONG InputBufSize;
2624d033fe9bSStanislav Motylkov     ULONG DataSize = 0;
2625d033fe9bSStanislav Motylkov     ULONG TableCount = 0;
2626d033fe9bSStanislav Motylkov 
2627d033fe9bSStanislav Motylkov     DPRINT("NtQuerySystemInformation - SystemFirmwareTableInformation\n");
2628d033fe9bSStanislav Motylkov 
2629d033fe9bSStanislav Motylkov     /* Set initial required buffer size */
2630d033fe9bSStanislav Motylkov     *ReqSize = FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION, TableBuffer);
2631d033fe9bSStanislav Motylkov 
2632d033fe9bSStanislav Motylkov     /* Check user's buffer size */
2633d033fe9bSStanislav Motylkov     if (Size < *ReqSize)
2634d033fe9bSStanislav Motylkov     {
2635d033fe9bSStanislav Motylkov         return STATUS_INFO_LENGTH_MISMATCH;
2636d033fe9bSStanislav Motylkov     }
2637d033fe9bSStanislav Motylkov 
2638d033fe9bSStanislav Motylkov     InputBufSize = SysFirmwareInfo->TableBufferLength;
2639d033fe9bSStanislav Motylkov     switch (SysFirmwareInfo->ProviderSignature)
2640d033fe9bSStanislav Motylkov     {
2641d033fe9bSStanislav Motylkov         /*
2642d033fe9bSStanislav Motylkov          * ExpFirmwareTableResource and ExpFirmwareTableProviderListHead
2643d033fe9bSStanislav Motylkov          * variables should be used there somehow...
2644d033fe9bSStanislav Motylkov          */
2645d033fe9bSStanislav Motylkov         case SIG_ACPI:
2646d033fe9bSStanislav Motylkov         {
2647d033fe9bSStanislav Motylkov             /* FIXME: Not implemented yet */
2648d033fe9bSStanislav Motylkov             DPRINT1("ACPI provider not implemented\n");
2649d033fe9bSStanislav Motylkov             Status = STATUS_NOT_IMPLEMENTED;
2650d033fe9bSStanislav Motylkov             break;
2651d033fe9bSStanislav Motylkov         }
2652d033fe9bSStanislav Motylkov         case SIG_FIRM:
2653d033fe9bSStanislav Motylkov         {
2654d033fe9bSStanislav Motylkov             /* FIXME: Not implemented yet */
2655d033fe9bSStanislav Motylkov             DPRINT1("FIRM provider not implemented\n");
2656d033fe9bSStanislav Motylkov             Status = STATUS_NOT_IMPLEMENTED;
2657d033fe9bSStanislav Motylkov             break;
2658d033fe9bSStanislav Motylkov         }
2659d033fe9bSStanislav Motylkov         case SIG_RSMB:
2660d033fe9bSStanislav Motylkov         {
2661d033fe9bSStanislav Motylkov             Status = ExpGetRawSMBiosTable(NULL, &DataSize, 0);
2662d033fe9bSStanislav Motylkov             if (DataSize > 0)
2663d033fe9bSStanislav Motylkov             {
2664d033fe9bSStanislav Motylkov                 TableCount = 1;
2665d033fe9bSStanislav Motylkov                 if (SysFirmwareInfo->Action == SystemFirmwareTable_Enumerate)
2666d033fe9bSStanislav Motylkov                 {
2667d033fe9bSStanislav Motylkov                     DataSize = TableCount * sizeof(ULONG);
2668d033fe9bSStanislav Motylkov                     if (DataSize <= InputBufSize)
2669d033fe9bSStanislav Motylkov                     {
2670d033fe9bSStanislav Motylkov                         *(ULONG *)SysFirmwareInfo->TableBuffer = 0;
2671d033fe9bSStanislav Motylkov                     }
2672d033fe9bSStanislav Motylkov                 }
2673d033fe9bSStanislav Motylkov                 else if (SysFirmwareInfo->Action == SystemFirmwareTable_Get
2674d033fe9bSStanislav Motylkov                          && DataSize <= InputBufSize)
2675d033fe9bSStanislav Motylkov                 {
2676d033fe9bSStanislav Motylkov                     Status = ExpGetRawSMBiosTable(SysFirmwareInfo->TableBuffer, &DataSize, InputBufSize);
2677d033fe9bSStanislav Motylkov                 }
2678d033fe9bSStanislav Motylkov                 SysFirmwareInfo->TableBufferLength = DataSize;
2679d033fe9bSStanislav Motylkov             }
2680d033fe9bSStanislav Motylkov             break;
2681d033fe9bSStanislav Motylkov         }
2682d033fe9bSStanislav Motylkov         default:
2683d033fe9bSStanislav Motylkov         {
2684d033fe9bSStanislav Motylkov             DPRINT1("SystemFirmwareTableInformation: Unsupported provider (0x%x)\n",
2685d033fe9bSStanislav Motylkov                     SysFirmwareInfo->ProviderSignature);
2686d033fe9bSStanislav Motylkov             Status = STATUS_ILLEGAL_FUNCTION;
2687d033fe9bSStanislav Motylkov         }
2688d033fe9bSStanislav Motylkov     }
2689d033fe9bSStanislav Motylkov 
2690d033fe9bSStanislav Motylkov     if (NT_SUCCESS(Status))
2691d033fe9bSStanislav Motylkov     {
2692d033fe9bSStanislav Motylkov         switch (SysFirmwareInfo->Action)
2693d033fe9bSStanislav Motylkov         {
2694d033fe9bSStanislav Motylkov             case SystemFirmwareTable_Enumerate:
2695d033fe9bSStanislav Motylkov             case SystemFirmwareTable_Get:
2696d033fe9bSStanislav Motylkov             {
2697d033fe9bSStanislav Motylkov                 if (SysFirmwareInfo->TableBufferLength > InputBufSize)
2698d033fe9bSStanislav Motylkov                 {
2699d033fe9bSStanislav Motylkov                     Status = STATUS_BUFFER_TOO_SMALL;
2700d033fe9bSStanislav Motylkov                 }
2701d033fe9bSStanislav Motylkov                 break;
2702d033fe9bSStanislav Motylkov             }
2703d033fe9bSStanislav Motylkov             default:
2704d033fe9bSStanislav Motylkov             {
2705d033fe9bSStanislav Motylkov                 DPRINT1("SystemFirmwareTableInformation: Unsupported action (0x%x)\n",
2706d033fe9bSStanislav Motylkov                         SysFirmwareInfo->Action);
2707d033fe9bSStanislav Motylkov                 Status = STATUS_ILLEGAL_FUNCTION;
2708d033fe9bSStanislav Motylkov             }
2709d033fe9bSStanislav Motylkov         }
2710d033fe9bSStanislav Motylkov     }
2711d033fe9bSStanislav Motylkov     else
2712d033fe9bSStanislav Motylkov     {
2713d033fe9bSStanislav Motylkov         SysFirmwareInfo->TableBufferLength = 0;
2714d033fe9bSStanislav Motylkov     }
2715d033fe9bSStanislav Motylkov     return Status;
2716d033fe9bSStanislav Motylkov }
2717d033fe9bSStanislav Motylkov 
2718c2c66affSColin Finck /* Query/Set Calls Table */
2719c2c66affSColin Finck typedef
2720c2c66affSColin Finck struct _QSSI_CALLS
2721c2c66affSColin Finck {
2722c2c66affSColin Finck     NTSTATUS (* Query) (PVOID,ULONG,PULONG);
2723c2c66affSColin Finck     NTSTATUS (* Set) (PVOID,ULONG);
2724c2c66affSColin Finck } QSSI_CALLS;
2725c2c66affSColin Finck 
2726c2c66affSColin Finck // QS    Query & Set
2727c2c66affSColin Finck // QX    Query
2728c2c66affSColin Finck // XS    Set
2729c2c66affSColin Finck // XX    unknown behaviour
2730c2c66affSColin Finck //
2731c2c66affSColin Finck #define SI_QS(n) {QSI_USE(n),SSI_USE(n)}
2732c2c66affSColin Finck #define SI_QX(n) {QSI_USE(n),NULL}
2733c2c66affSColin Finck #define SI_XS(n) {NULL,SSI_USE(n)}
2734c2c66affSColin Finck #define SI_XX(n) {NULL,NULL}
2735c2c66affSColin Finck 
2736c2c66affSColin Finck static
2737c2c66affSColin Finck QSSI_CALLS
2738c2c66affSColin Finck CallQS [] =
2739c2c66affSColin Finck {
2740c2c66affSColin Finck     SI_QX(SystemBasicInformation),
2741c2c66affSColin Finck     SI_QX(SystemProcessorInformation),
2742c2c66affSColin Finck     SI_QX(SystemPerformanceInformation),
2743c2c66affSColin Finck     SI_QX(SystemTimeOfDayInformation),
2744c2c66affSColin Finck     SI_QX(SystemPathInformation), /* should be SI_XX */
2745c2c66affSColin Finck     SI_QX(SystemProcessInformation),
2746c2c66affSColin Finck     SI_QX(SystemCallCountInformation),
2747c2c66affSColin Finck     SI_QX(SystemDeviceInformation),
2748c2c66affSColin Finck     SI_QX(SystemProcessorPerformanceInformation),
2749c2c66affSColin Finck     SI_QS(SystemFlagsInformation),
2750c2c66affSColin Finck     SI_QX(SystemCallTimeInformation), /* should be SI_XX */
2751c2c66affSColin Finck     SI_QX(SystemModuleInformation),
2752c2c66affSColin Finck     SI_QX(SystemLocksInformation),
2753c2c66affSColin Finck     SI_QX(SystemStackTraceInformation), /* should be SI_XX */
2754c2c66affSColin Finck     SI_QX(SystemPagedPoolInformation), /* should be SI_XX */
2755c2c66affSColin Finck     SI_QX(SystemNonPagedPoolInformation), /* should be SI_XX */
2756c2c66affSColin Finck     SI_QX(SystemHandleInformation),
2757c2c66affSColin Finck     SI_QX(SystemObjectInformation),
2758c2c66affSColin Finck     SI_QX(SystemPageFileInformation),
2759c2c66affSColin Finck     SI_QX(SystemVdmInstemulInformation),
2760c2c66affSColin Finck     SI_QX(SystemVdmBopInformation), /* it should be SI_XX */
2761c2c66affSColin Finck     SI_QS(SystemFileCacheInformation),
2762c2c66affSColin Finck     SI_QX(SystemPoolTagInformation),
2763c2c66affSColin Finck     SI_QX(SystemInterruptInformation),
2764c2c66affSColin Finck     SI_QS(SystemDpcBehaviourInformation),
2765c2c66affSColin Finck     SI_QX(SystemFullMemoryInformation), /* it should be SI_XX */
2766c2c66affSColin Finck     SI_XS(SystemLoadGdiDriverInformation),
2767c2c66affSColin Finck     SI_XS(SystemUnloadGdiDriverInformation),
2768c2c66affSColin Finck     SI_QS(SystemTimeAdjustmentInformation),
2769c2c66affSColin Finck     SI_QX(SystemSummaryMemoryInformation), /* it should be SI_XX */
2770c2c66affSColin Finck     SI_QX(SystemNextEventIdInformation), /* it should be SI_XX */
2771c2c66affSColin Finck     SI_QX(SystemPerformanceTraceInformation), /* it should be SI_XX */
2772c2c66affSColin Finck     SI_QX(SystemCrashDumpInformation),
2773c2c66affSColin Finck     SI_QX(SystemExceptionInformation),
2774c2c66affSColin Finck     SI_QX(SystemCrashDumpStateInformation),
2775c2c66affSColin Finck     SI_QX(SystemKernelDebuggerInformation),
2776c2c66affSColin Finck     SI_QX(SystemContextSwitchInformation),
2777c2c66affSColin Finck     SI_QS(SystemRegistryQuotaInformation),
2778c2c66affSColin Finck     SI_XS(SystemExtendServiceTableInformation),
2779c2c66affSColin Finck     SI_XS(SystemPrioritySeperation),
2780c2c66affSColin Finck     SI_QX(SystemVerifierAddDriverInformation), /* it should be SI_XX */
2781c2c66affSColin Finck     SI_QX(SystemVerifierRemoveDriverInformation), /* it should be SI_XX */
2782c2c66affSColin Finck     SI_QX(SystemProcessorIdleInformation), /* it should be SI_XX */
2783c2c66affSColin Finck     SI_QX(SystemLegacyDriverInformation), /* it should be SI_XX */
2784c2c66affSColin Finck     SI_QS(SystemCurrentTimeZoneInformation), /* it should be SI_QX */
2785c2c66affSColin Finck     SI_QX(SystemLookasideInformation),
2786c2c66affSColin Finck     SI_XS(SystemTimeSlipNotification),
2787c2c66affSColin Finck     SI_XS(SystemSessionCreate),
2788c2c66affSColin Finck     SI_XS(SystemSessionDetach),
2789c2c66affSColin Finck     SI_QX(SystemSessionInformation), /* it should be SI_XX */
2790c2c66affSColin Finck     SI_QX(SystemRangeStartInformation),
2791c2c66affSColin Finck     SI_QS(SystemVerifierInformation),
2792c2c66affSColin Finck     SI_XS(SystemVerifierThunkExtend),
2793c2c66affSColin Finck     SI_QX(SystemSessionProcessesInformation),
2794c2c66affSColin Finck     SI_XS(SystemLoadGdiDriverInSystemSpaceInformation),
2795c2c66affSColin Finck     SI_QX(SystemNumaProcessorMap),
2796c2c66affSColin Finck     SI_QX(SystemPrefetcherInformation),
2797c2c66affSColin Finck     SI_QX(SystemExtendedProcessInformation),
2798c2c66affSColin Finck     SI_QX(SystemRecommendedSharedDataAlignment),
2799c2c66affSColin Finck     SI_XX(SystemComPlusPackage),
2800c2c66affSColin Finck     SI_QX(SystemNumaAvailableMemory),
2801c2c66affSColin Finck     SI_XX(SystemProcessorPowerInformation), /* FIXME: not implemented */
2802c2c66affSColin Finck     SI_XX(SystemEmulationBasicInformation), /* FIXME: not implemented */
2803c2c66affSColin Finck     SI_XX(SystemEmulationProcessorInformation), /* FIXME: not implemented */
2804c2c66affSColin Finck     SI_QX(SystemExtendedHandleInformation),
2805d033fe9bSStanislav Motylkov     SI_XX(SystemLostDelayedWriteInformation), /* FIXME: not implemented */
2806d033fe9bSStanislav Motylkov     SI_XX(SystemBigPoolInformation), /* FIXME: not implemented */
2807d033fe9bSStanislav Motylkov     SI_XX(SystemSessionPoolTagInformation), /* FIXME: not implemented */
2808d033fe9bSStanislav Motylkov     SI_XX(SystemSessionMappedViewInformation), /* FIXME: not implemented */
2809d033fe9bSStanislav Motylkov     SI_XX(SystemHotpatchInformation), /* FIXME: not implemented */
2810d033fe9bSStanislav Motylkov     SI_XX(SystemObjectSecurityMode), /* FIXME: not implemented */
2811d033fe9bSStanislav Motylkov     SI_XX(SystemWatchdogTimerHandler), /* FIXME: not implemented */
2812d033fe9bSStanislav Motylkov     SI_XX(SystemWatchdogTimerInformation), /* FIXME: not implemented */
2813d033fe9bSStanislav Motylkov     SI_XX(SystemLogicalProcessorInformation), /* FIXME: not implemented */
2814d033fe9bSStanislav Motylkov     SI_XX(SystemWow64SharedInformation), /* FIXME: not implemented */
2815d033fe9bSStanislav Motylkov     SI_XX(SystemRegisterFirmwareTableInformationHandler), /* FIXME: not implemented */
2816d033fe9bSStanislav Motylkov     SI_QX(SystemFirmwareTableInformation),
2817c2c66affSColin Finck };
2818c2c66affSColin Finck 
2819c2c66affSColin Finck C_ASSERT(SystemBasicInformation == 0);
2820c2c66affSColin Finck #define MIN_SYSTEM_INFO_CLASS (SystemBasicInformation)
2821c2c66affSColin Finck #define MAX_SYSTEM_INFO_CLASS (sizeof(CallQS) / sizeof(CallQS[0]))
2822c2c66affSColin Finck 
2823c2c66affSColin Finck /*
2824c2c66affSColin Finck  * @implemented
2825c2c66affSColin Finck  */
2826c2c66affSColin Finck __kernel_entry
2827c2c66affSColin Finck NTSTATUS
2828c2c66affSColin Finck NTAPI
2829c2c66affSColin Finck NtQuerySystemInformation(
2830c2c66affSColin Finck     _In_ SYSTEM_INFORMATION_CLASS SystemInformationClass,
2831c2c66affSColin Finck     _Out_writes_bytes_to_opt_(SystemInformationLength, *ReturnLength) PVOID SystemInformation,
2832c2c66affSColin Finck     _In_ ULONG Length,
2833c2c66affSColin Finck     _Out_opt_ PULONG UnsafeResultLength)
2834c2c66affSColin Finck {
2835c2c66affSColin Finck     KPROCESSOR_MODE PreviousMode;
2836c2c66affSColin Finck     ULONG ResultLength = 0;
2837c2c66affSColin Finck     ULONG Alignment = TYPE_ALIGNMENT(ULONG);
2838c2c66affSColin Finck     NTSTATUS FStatus = STATUS_NOT_IMPLEMENTED;
2839c2c66affSColin Finck 
2840c2c66affSColin Finck     PAGED_CODE();
2841c2c66affSColin Finck 
2842c2c66affSColin Finck     PreviousMode = ExGetPreviousMode();
2843c2c66affSColin Finck 
2844c2c66affSColin Finck     _SEH2_TRY
2845c2c66affSColin Finck     {
2846c2c66affSColin Finck #if (NTDDI_VERSION >= NTDDI_VISTA)
2847c2c66affSColin Finck         /*
2848c2c66affSColin Finck          * Check if the request is valid.
2849c2c66affSColin Finck          */
2850*63977328SThomas Faber         if (SystemInformationClass < MIN_SYSTEM_INFO_CLASS ||
2851*63977328SThomas Faber             SystemInformationClass >= MAX_SYSTEM_INFO_CLASS)
2852c2c66affSColin Finck         {
2853c2c66affSColin Finck             _SEH2_YIELD(return STATUS_INVALID_INFO_CLASS);
2854c2c66affSColin Finck         }
2855c2c66affSColin Finck #endif
2856c2c66affSColin Finck 
2857c2c66affSColin Finck         if (PreviousMode != KernelMode)
2858c2c66affSColin Finck         {
2859c2c66affSColin Finck             /* SystemKernelDebuggerInformation needs only BOOLEAN alignment */
2860c2c66affSColin Finck             if (SystemInformationClass == SystemKernelDebuggerInformation)
2861c2c66affSColin Finck                 Alignment = TYPE_ALIGNMENT(BOOLEAN);
2862c2c66affSColin Finck 
2863c2c66affSColin Finck             ProbeForWrite(SystemInformation, Length, Alignment);
2864c2c66affSColin Finck             if (UnsafeResultLength != NULL)
2865c2c66affSColin Finck                 ProbeForWriteUlong(UnsafeResultLength);
2866c2c66affSColin Finck         }
2867c2c66affSColin Finck 
2868c2c66affSColin Finck         if (UnsafeResultLength)
2869c2c66affSColin Finck             *UnsafeResultLength = 0;
2870c2c66affSColin Finck 
2871c2c66affSColin Finck #if (NTDDI_VERSION < NTDDI_VISTA)
2872c2c66affSColin Finck         /*
2873c2c66affSColin Finck          * Check if the request is valid.
2874c2c66affSColin Finck          */
2875*63977328SThomas Faber         if (SystemInformationClass < MIN_SYSTEM_INFO_CLASS ||
2876*63977328SThomas Faber             SystemInformationClass >= MAX_SYSTEM_INFO_CLASS)
2877c2c66affSColin Finck         {
2878c2c66affSColin Finck             _SEH2_YIELD(return STATUS_INVALID_INFO_CLASS);
2879c2c66affSColin Finck         }
2880c2c66affSColin Finck #endif
2881c2c66affSColin Finck 
2882c2c66affSColin Finck         if (NULL != CallQS [SystemInformationClass].Query)
2883c2c66affSColin Finck         {
2884c2c66affSColin Finck             /*
2885c2c66affSColin Finck              * Hand the request to a subhandler.
2886c2c66affSColin Finck              */
2887c2c66affSColin Finck             FStatus = CallQS [SystemInformationClass].Query(SystemInformation,
2888c2c66affSColin Finck                                                             Length,
2889c2c66affSColin Finck                                                             &ResultLength);
2890c2c66affSColin Finck 
2891c2c66affSColin Finck             /* Save the result length to the caller */
2892c2c66affSColin Finck             if (UnsafeResultLength)
2893c2c66affSColin Finck                 *UnsafeResultLength = ResultLength;
2894c2c66affSColin Finck         }
2895c2c66affSColin Finck     }
2896c2c66affSColin Finck     _SEH2_EXCEPT(ExSystemExceptionFilter())
2897c2c66affSColin Finck     {
2898c2c66affSColin Finck         FStatus = _SEH2_GetExceptionCode();
2899c2c66affSColin Finck     }
2900c2c66affSColin Finck     _SEH2_END;
2901c2c66affSColin Finck 
2902c2c66affSColin Finck     return FStatus;
2903c2c66affSColin Finck }
2904c2c66affSColin Finck 
2905c2c66affSColin Finck 
2906c2c66affSColin Finck NTSTATUS
2907c2c66affSColin Finck NTAPI
2908c2c66affSColin Finck NtSetSystemInformation (IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
2909c2c66affSColin Finck                         IN PVOID SystemInformation,
2910c2c66affSColin Finck                         IN ULONG SystemInformationLength)
2911c2c66affSColin Finck {
2912c2c66affSColin Finck     NTSTATUS Status = STATUS_INVALID_INFO_CLASS;
2913c2c66affSColin Finck     KPROCESSOR_MODE PreviousMode;
2914c2c66affSColin Finck 
2915c2c66affSColin Finck     PAGED_CODE();
2916c2c66affSColin Finck 
2917c2c66affSColin Finck     PreviousMode = ExGetPreviousMode();
2918c2c66affSColin Finck 
2919c2c66affSColin Finck     _SEH2_TRY
2920c2c66affSColin Finck     {
2921c2c66affSColin Finck         /*
2922c2c66affSColin Finck          * If called from user mode, check
2923c2c66affSColin Finck          * possible unsafe arguments.
2924c2c66affSColin Finck          */
2925c2c66affSColin Finck         if (PreviousMode != KernelMode)
2926c2c66affSColin Finck         {
2927c2c66affSColin Finck             ProbeForRead(SystemInformation, SystemInformationLength, sizeof(ULONG));
2928c2c66affSColin Finck         }
2929c2c66affSColin Finck 
2930c2c66affSColin Finck         /*
2931c2c66affSColin Finck          * Check the request is valid.
2932c2c66affSColin Finck          */
2933c2c66affSColin Finck         if ((SystemInformationClass >= MIN_SYSTEM_INFO_CLASS) &&
2934c2c66affSColin Finck             (SystemInformationClass < MAX_SYSTEM_INFO_CLASS))
2935c2c66affSColin Finck         {
2936c2c66affSColin Finck             if (NULL != CallQS [SystemInformationClass].Set)
2937c2c66affSColin Finck             {
2938c2c66affSColin Finck                 /*
2939c2c66affSColin Finck                  * Hand the request to a subhandler.
2940c2c66affSColin Finck                  */
2941c2c66affSColin Finck                 Status = CallQS [SystemInformationClass].Set(SystemInformation,
2942c2c66affSColin Finck                                                              SystemInformationLength);
2943c2c66affSColin Finck             }
2944c2c66affSColin Finck         }
2945c2c66affSColin Finck     }
2946c2c66affSColin Finck     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
2947c2c66affSColin Finck     {
2948c2c66affSColin Finck         Status = _SEH2_GetExceptionCode();
2949c2c66affSColin Finck     }
2950c2c66affSColin Finck     _SEH2_END;
2951c2c66affSColin Finck 
2952c2c66affSColin Finck     return Status;
2953c2c66affSColin Finck }
2954c2c66affSColin Finck 
2955c2c66affSColin Finck ULONG
2956c2c66affSColin Finck NTAPI
2957c2c66affSColin Finck NtGetCurrentProcessorNumber(VOID)
2958c2c66affSColin Finck {
2959c2c66affSColin Finck     /* Just use Ke */
2960c2c66affSColin Finck     return KeGetCurrentProcessorNumber();
2961c2c66affSColin Finck }
2962c2c66affSColin Finck 
2963c2c66affSColin Finck #undef ExGetPreviousMode
2964c2c66affSColin Finck KPROCESSOR_MODE
2965c2c66affSColin Finck NTAPI
2966c2c66affSColin Finck ExGetPreviousMode(VOID)
2967c2c66affSColin Finck {
2968c2c66affSColin Finck     /* Just use Ke */
2969c2c66affSColin Finck     return KeGetPreviousMode();
2970c2c66affSColin Finck }
2971