- Use the KiProcessorBlock array to loop the PRCBs in a portable way
[reactos.git] / reactos / ntoskrnl / ex / sysinfo.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ex/sysinfo.c
5 * PURPOSE: System information functions
6 *
7 * PROGRAMMERS: David Welch (welch@mcmail.com)
8 * Aleksey Bragin (aleksey@reactos.org)
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ntoskrnl.h>
14 #define NDEBUG
15 #include <debug.h>
16
17 VOID MmPrintMemoryStatistic(VOID);
18
19 FAST_MUTEX ExpEnvironmentLock;
20 ERESOURCE ExpFirmwareTableResource;
21 LIST_ENTRY ExpFirmwareTableProviderListHead;
22
23 NTSTATUS
24 NTAPI
25 ExpQueryModuleInformation(IN PLIST_ENTRY KernelModeList,
26 IN PLIST_ENTRY UserModeList,
27 OUT PRTL_PROCESS_MODULES Modules,
28 IN ULONG Length,
29 OUT PULONG ReturnLength)
30 {
31 NTSTATUS Status = STATUS_SUCCESS;
32 ULONG RequiredLength;
33 PRTL_PROCESS_MODULE_INFORMATION ModuleInfo;
34 PLDR_DATA_TABLE_ENTRY LdrEntry;
35 ANSI_STRING ModuleName;
36 ULONG ModuleCount = 0;
37 PLIST_ENTRY NextEntry;
38 PCHAR p;
39
40 /* Setup defaults */
41 RequiredLength = FIELD_OFFSET(RTL_PROCESS_MODULES, Modules);
42 ModuleInfo = &Modules->Modules[0];
43
44 /* Loop the kernel list */
45 NextEntry = KernelModeList->Flink;
46 while (NextEntry != KernelModeList)
47 {
48 /* Get the entry */
49 LdrEntry = CONTAINING_RECORD(NextEntry,
50 LDR_DATA_TABLE_ENTRY,
51 InLoadOrderLinks);
52
53 /* Update size and check if we can manage one more entry */
54 RequiredLength += sizeof(RTL_PROCESS_MODULE_INFORMATION);
55 if (Length >= RequiredLength)
56 {
57 /* Fill it out */
58 ModuleInfo->MappedBase = NULL;
59 ModuleInfo->ImageBase = LdrEntry->DllBase;
60 ModuleInfo->ImageSize = LdrEntry->SizeOfImage;
61 ModuleInfo->Flags = LdrEntry->Flags;
62 ModuleInfo->LoadCount = LdrEntry->LoadCount;
63 ModuleInfo->LoadOrderIndex = (USHORT)ModuleCount;
64 ModuleInfo->InitOrderIndex = 0;
65
66 /* Setup name */
67 RtlInitEmptyAnsiString(&ModuleName,
68 ModuleInfo->FullPathName,
69 sizeof(ModuleInfo->FullPathName));
70
71 /* Convert it */
72 Status = RtlUnicodeStringToAnsiString(&ModuleName,
73 &LdrEntry->FullDllName,
74 FALSE);
75 if ((NT_SUCCESS(Status)) || (Status == STATUS_BUFFER_OVERFLOW))
76 {
77 /* Calculate offset to name */
78 p = ModuleName.Buffer + ModuleName.Length;
79 while ((p > ModuleName.Buffer) && (*--p))
80 {
81 /* Check if we found the separator */
82 if (*p == OBJ_NAME_PATH_SEPARATOR)
83 {
84 /* We did, break out */
85 p++;
86 break;
87 }
88 }
89
90 /* Set the offset */
91 ModuleInfo->OffsetToFileName = p - ModuleName.Buffer;
92 }
93 else
94 {
95 /* Return empty name */
96 ModuleInfo->FullPathName[0] = ANSI_NULL;
97 ModuleInfo->OffsetToFileName = 0;
98 }
99
100 /* Go to the next module */
101 ModuleInfo++;
102 }
103 else
104 {
105 /* Set error code */
106 Status = STATUS_INFO_LENGTH_MISMATCH;
107 }
108
109 /* Update count and move to next entry */
110 ModuleCount++;
111 NextEntry = NextEntry->Flink;
112 }
113
114 /* Check if caller also wanted user modules */
115 if (UserModeList)
116 {
117 /* FIXME: TODO */
118 DPRINT1("User-mode list not yet supported in ReactOS!\n");
119 }
120
121 /* Update return length */
122 if (ReturnLength) *ReturnLength = RequiredLength;
123
124 /* Validate the length again */
125 if (Length >= FIELD_OFFSET(RTL_PROCESS_MODULES, Modules))
126 {
127 /* Set the final count */
128 Modules->NumberOfModules = ModuleCount;
129 }
130 else
131 {
132 /* Otherwise, we failed */
133 Status = STATUS_INFO_LENGTH_MISMATCH;
134 }
135
136 /* Done */
137 return Status;
138 }
139
140 /* FUNCTIONS *****************************************************************/
141
142 /*
143 * @implemented
144 */
145 #undef ExGetPreviousMode
146 KPROCESSOR_MODE
147 NTAPI
148 ExGetPreviousMode (VOID)
149 {
150 return KeGetPreviousMode();
151 }
152
153 /*
154 * @implemented
155 */
156 VOID
157 NTAPI
158 ExGetCurrentProcessorCpuUsage(PULONG CpuUsage)
159 {
160 PKPRCB Prcb;
161 ULONG TotalTime;
162 ULONGLONG ScaledIdle;
163
164 Prcb = KeGetCurrentPrcb();
165
166 ScaledIdle = Prcb->IdleThread->KernelTime * 100;
167 TotalTime = Prcb->KernelTime + Prcb->UserTime;
168 if (TotalTime != 0)
169 *CpuUsage = (ULONG)(100 - (ScaledIdle / TotalTime));
170 else
171 *CpuUsage = 0;
172 }
173
174 /*
175 * @implemented
176 */
177 VOID
178 NTAPI
179 ExGetCurrentProcessorCounts(PULONG ThreadKernelTime,
180 PULONG TotalCpuTime,
181 PULONG ProcessorNumber)
182 {
183 PKPRCB Prcb;
184
185 Prcb = KeGetCurrentPrcb();
186
187 *ThreadKernelTime = Prcb->KernelTime + Prcb->UserTime;
188 *TotalCpuTime = Prcb->CurrentThread->KernelTime;
189 *ProcessorNumber = KeGetCurrentProcessorNumber();
190 }
191
192 /*
193 * @implemented
194 */
195 BOOLEAN
196 NTAPI
197 ExIsProcessorFeaturePresent(IN ULONG ProcessorFeature)
198 {
199 /* Quick check to see if it exists at all */
200 if (ProcessorFeature >= PROCESSOR_FEATURE_MAX) return(FALSE);
201
202 /* Return our support for it */
203 return(SharedUserData->ProcessorFeatures[ProcessorFeature]);
204 }
205
206 /*
207 * @implemented
208 */
209 BOOLEAN
210 NTAPI
211 ExVerifySuite(SUITE_TYPE SuiteType)
212 {
213 if (SuiteType == Personal) return TRUE;
214 return FALSE;
215 }
216
217 NTSTATUS
218 NTAPI
219 NtQuerySystemEnvironmentValue(IN PUNICODE_STRING VariableName,
220 OUT PWSTR ValueBuffer,
221 IN ULONG ValueBufferLength,
222 IN OUT PULONG ReturnLength OPTIONAL)
223 {
224 ANSI_STRING AName;
225 UNICODE_STRING WName;
226 ARC_STATUS Result;
227 PCH Value;
228 ANSI_STRING AValue;
229 UNICODE_STRING WValue;
230 KPROCESSOR_MODE PreviousMode;
231 NTSTATUS Status = STATUS_SUCCESS;
232
233 PAGED_CODE();
234
235 PreviousMode = ExGetPreviousMode();
236
237 if (PreviousMode != KernelMode)
238 {
239 _SEH2_TRY
240 {
241 ProbeForRead(VariableName,
242 sizeof(UNICODE_STRING),
243 sizeof(ULONG));
244
245 ProbeForWrite(ValueBuffer,
246 ValueBufferLength,
247 sizeof(WCHAR));
248
249 if (ReturnLength != NULL) ProbeForWriteUlong(ReturnLength);
250 }
251 _SEH2_EXCEPT(ExSystemExceptionFilter())
252 {
253 Status = _SEH2_GetExceptionCode();
254 }
255 _SEH2_END;
256
257 if (!NT_SUCCESS(Status)) return Status;
258 }
259
260 /*
261 * Copy the name to kernel space if necessary and convert it to ANSI.
262 */
263 Status = ProbeAndCaptureUnicodeString(&WName,
264 PreviousMode,
265 VariableName);
266 if (NT_SUCCESS(Status))
267 {
268 /*
269 * according to ntinternals the SeSystemEnvironmentName privilege is required!
270 */
271 if (!SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege,
272 PreviousMode))
273 {
274 ReleaseCapturedUnicodeString(&WName, PreviousMode);
275 DPRINT1("NtQuerySystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
276 return STATUS_PRIVILEGE_NOT_HELD;
277 }
278
279 /*
280 * convert the value name to ansi
281 */
282 Status = RtlUnicodeStringToAnsiString(&AName, &WName, TRUE);
283 ReleaseCapturedUnicodeString(&WName, PreviousMode);
284
285 if (!NT_SUCCESS(Status)) return Status;
286
287 /*
288 * Create a temporary buffer for the value
289 */
290 Value = ExAllocatePool(NonPagedPool, ValueBufferLength);
291 if (Value == NULL)
292 {
293 RtlFreeAnsiString(&AName);
294 return STATUS_INSUFFICIENT_RESOURCES;
295 }
296
297 /*
298 * Get the environment variable
299 */
300 Result = HalGetEnvironmentVariable(AName.Buffer,
301 (USHORT)ValueBufferLength,
302 Value);
303 if (!Result)
304 {
305 RtlFreeAnsiString(&AName);
306 ExFreePool(Value);
307 return STATUS_UNSUCCESSFUL;
308 }
309
310 /*
311 * Convert the result to UNICODE, protect with SEH in case the value buffer
312 * isn't NULL-terminated!
313 */
314 _SEH2_TRY
315 {
316 RtlInitAnsiString(&AValue, Value);
317 Status = RtlAnsiStringToUnicodeString(&WValue, &AValue, TRUE);
318 }
319 _SEH2_EXCEPT(ExSystemExceptionFilter())
320 {
321 Status = _SEH2_GetExceptionCode();
322 }
323 _SEH2_END;
324
325 if (NT_SUCCESS(Status))
326 {
327 /*
328 * Copy the result back to the caller.
329 */
330 _SEH2_TRY
331 {
332 RtlCopyMemory(ValueBuffer, WValue.Buffer, WValue.Length);
333 ValueBuffer[WValue.Length / sizeof(WCHAR)] = L'\0';
334 if (ReturnLength != NULL)
335 {
336 *ReturnLength = WValue.Length + sizeof(WCHAR);
337 }
338
339 Status = STATUS_SUCCESS;
340 }
341 _SEH2_EXCEPT(ExSystemExceptionFilter())
342 {
343 Status = _SEH2_GetExceptionCode();
344 }
345 _SEH2_END;
346 }
347
348 /*
349 * Cleanup allocated resources.
350 */
351 RtlFreeAnsiString(&AName);
352 ExFreePool(Value);
353 }
354
355 return Status;
356 }
357
358
359 NTSTATUS
360 NTAPI
361 NtSetSystemEnvironmentValue(IN PUNICODE_STRING VariableName,
362 IN PUNICODE_STRING Value)
363 {
364 UNICODE_STRING CapturedName, CapturedValue;
365 ANSI_STRING AName, AValue;
366 KPROCESSOR_MODE PreviousMode;
367 NTSTATUS Status;
368
369 PAGED_CODE();
370
371 PreviousMode = ExGetPreviousMode();
372
373 /*
374 * Copy the strings to kernel space if necessary
375 */
376 Status = ProbeAndCaptureUnicodeString(&CapturedName,
377 PreviousMode,
378 VariableName);
379 if (NT_SUCCESS(Status))
380 {
381 Status = ProbeAndCaptureUnicodeString(&CapturedValue,
382 PreviousMode,
383 Value);
384 if (NT_SUCCESS(Status))
385 {
386 /*
387 * according to ntinternals the SeSystemEnvironmentName privilege is required!
388 */
389 if (SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege,
390 PreviousMode))
391 {
392 /*
393 * convert the strings to ANSI
394 */
395 Status = RtlUnicodeStringToAnsiString(&AName,
396 &CapturedName,
397 TRUE);
398 if (NT_SUCCESS(Status))
399 {
400 Status = RtlUnicodeStringToAnsiString(&AValue,
401 &CapturedValue,
402 TRUE);
403 if (NT_SUCCESS(Status))
404 {
405 ARC_STATUS Result = HalSetEnvironmentVariable(AName.Buffer,
406 AValue.Buffer);
407
408 Status = (Result ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
409 }
410 }
411 }
412 else
413 {
414 DPRINT1("NtSetSystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
415 Status = STATUS_PRIVILEGE_NOT_HELD;
416 }
417
418 ReleaseCapturedUnicodeString(&CapturedValue,
419 PreviousMode);
420 }
421
422 ReleaseCapturedUnicodeString(&CapturedName,
423 PreviousMode);
424 }
425
426 return Status;
427 }
428
429 NTSTATUS
430 NTAPI
431 NtEnumerateSystemEnvironmentValuesEx(IN ULONG InformationClass,
432 IN PVOID Buffer,
433 IN ULONG BufferLength)
434 {
435 UNIMPLEMENTED;
436 return STATUS_NOT_IMPLEMENTED;
437 }
438
439 NTSTATUS
440 NTAPI
441 NtQuerySystemEnvironmentValueEx(IN PUNICODE_STRING VariableName,
442 IN LPGUID VendorGuid,
443 IN PVOID Value,
444 IN OUT PULONG ReturnLength,
445 IN OUT PULONG Attributes)
446 {
447 UNIMPLEMENTED;
448 return STATUS_NOT_IMPLEMENTED;
449 }
450
451 NTSTATUS
452 NTAPI
453 NtSetSystemEnvironmentValueEx(IN PUNICODE_STRING VariableName,
454 IN LPGUID VendorGuid)
455 {
456 UNIMPLEMENTED;
457 return STATUS_NOT_IMPLEMENTED;
458 }
459
460 /* --- Query/Set System Information --- */
461
462 /*
463 * NOTE: QSI_DEF(n) and SSI_DEF(n) define _cdecl function symbols
464 * so the stack is popped only in one place on x86 platform.
465 */
466 #define QSI_USE(n) QSI##n
467 #define QSI_DEF(n) \
468 static NTSTATUS QSI_USE(n) (PVOID Buffer, ULONG Size, PULONG ReqSize)
469
470 #define SSI_USE(n) SSI##n
471 #define SSI_DEF(n) \
472 static NTSTATUS SSI_USE(n) (PVOID Buffer, ULONG Size)
473
474
475 /* Class 0 - Basic Information */
476 QSI_DEF(SystemBasicInformation)
477 {
478 PSYSTEM_BASIC_INFORMATION Sbi
479 = (PSYSTEM_BASIC_INFORMATION) Buffer;
480
481 *ReqSize = sizeof(SYSTEM_BASIC_INFORMATION);
482
483 /* Check user buffer's size */
484 if (Size != sizeof(SYSTEM_BASIC_INFORMATION))
485 {
486 return STATUS_INFO_LENGTH_MISMATCH;
487 }
488
489 RtlZeroMemory(Sbi, Size);
490 Sbi->Reserved = 0;
491 Sbi->TimerResolution = KeMaximumIncrement;
492 Sbi->PageSize = PAGE_SIZE;
493 Sbi->NumberOfPhysicalPages = MmStats.NrTotalPages;
494 Sbi->LowestPhysicalPageNumber = 0; /* FIXME */
495 Sbi->HighestPhysicalPageNumber = MmStats.NrTotalPages; /* FIXME */
496 Sbi->AllocationGranularity = MM_VIRTMEM_GRANULARITY; /* hard coded on Intel? */
497 Sbi->MinimumUserModeAddress = 0x10000; /* Top of 64k */
498 Sbi->MaximumUserModeAddress = (ULONG_PTR)MmHighestUserAddress;
499 Sbi->ActiveProcessorsAffinityMask = KeActiveProcessors;
500 Sbi->NumberOfProcessors = KeNumberProcessors;
501
502 return STATUS_SUCCESS;
503 }
504
505 /* Class 1 - Processor Information */
506 QSI_DEF(SystemProcessorInformation)
507 {
508 PSYSTEM_PROCESSOR_INFORMATION Spi
509 = (PSYSTEM_PROCESSOR_INFORMATION) Buffer;
510 PKPRCB Prcb;
511
512 *ReqSize = sizeof(SYSTEM_PROCESSOR_INFORMATION);
513
514 /* Check user buffer's size */
515 if (Size < sizeof(SYSTEM_PROCESSOR_INFORMATION))
516 {
517 return STATUS_INFO_LENGTH_MISMATCH;
518 }
519 Prcb = KeGetCurrentPrcb();
520 Spi->ProcessorArchitecture = KeProcessorArchitecture;
521 Spi->ProcessorLevel = KeProcessorLevel;
522 Spi->ProcessorRevision = KeProcessorRevision;
523 Spi->Reserved = 0;
524 Spi->ProcessorFeatureBits = KeFeatureBits;
525
526 DPRINT("Arch %d Level %d Rev 0x%x\n", Spi->ProcessorArchitecture,
527 Spi->ProcessorLevel, Spi->ProcessorRevision);
528
529 return STATUS_SUCCESS;
530 }
531
532 /* Class 2 - Performance Information */
533 QSI_DEF(SystemPerformanceInformation)
534 {
535 ULONG IdleUser, IdleKernel;
536 PSYSTEM_PERFORMANCE_INFORMATION Spi
537 = (PSYSTEM_PERFORMANCE_INFORMATION) Buffer;
538
539 PEPROCESS TheIdleProcess;
540
541 *ReqSize = sizeof(SYSTEM_PERFORMANCE_INFORMATION);
542
543 /* Check user buffer's size */
544 if (Size < sizeof(SYSTEM_PERFORMANCE_INFORMATION))
545 {
546 return STATUS_INFO_LENGTH_MISMATCH;
547 }
548
549 TheIdleProcess = PsIdleProcess;
550
551 IdleKernel = KeQueryRuntimeProcess(&TheIdleProcess->Pcb, &IdleUser);
552 Spi->IdleProcessTime.QuadPart = UInt32x32To64(IdleKernel, KeMaximumIncrement);
553 Spi->IoReadTransferCount = IoReadTransferCount;
554 Spi->IoWriteTransferCount = IoWriteTransferCount;
555 Spi->IoOtherTransferCount = IoOtherTransferCount;
556 Spi->IoReadOperationCount = IoReadOperationCount;
557 Spi->IoWriteOperationCount = IoWriteOperationCount;
558 Spi->IoOtherOperationCount = IoOtherOperationCount;
559
560 Spi->AvailablePages = MmStats.NrFreePages;
561 /*
562 * Add up all the used "Committed" memory + pagefile.
563 * Not sure this is right. 8^\
564 */
565 Spi->CommittedPages = MiMemoryConsumers[MC_PPOOL].PagesUsed +
566 MiMemoryConsumers[MC_NPPOOL].PagesUsed +
567 MiMemoryConsumers[MC_CACHE].PagesUsed +
568 MiMemoryConsumers[MC_USER].PagesUsed +
569 MiUsedSwapPages;
570 /*
571 * Add up the full system total + pagefile.
572 * All this make Taskmgr happy but not sure it is the right numbers.
573 * This too, fixes some of GlobalMemoryStatusEx numbers.
574 */
575 Spi->CommitLimit = MmStats.NrTotalPages + MiFreeSwapPages + MiUsedSwapPages;
576
577 Spi->PeakCommitment = 0; /* FIXME */
578 Spi->PageFaultCount = 0; /* FIXME */
579 Spi->CopyOnWriteCount = 0; /* FIXME */
580 Spi->TransitionCount = 0; /* FIXME */
581 Spi->CacheTransitionCount = 0; /* FIXME */
582 Spi->DemandZeroCount = 0; /* FIXME */
583 Spi->PageReadCount = 0; /* FIXME */
584 Spi->PageReadIoCount = 0; /* FIXME */
585 Spi->CacheReadCount = 0; /* FIXME */
586 Spi->CacheIoCount = 0; /* FIXME */
587 Spi->DirtyPagesWriteCount = 0; /* FIXME */
588 Spi->DirtyWriteIoCount = 0; /* FIXME */
589 Spi->MappedPagesWriteCount = 0; /* FIXME */
590 Spi->MappedWriteIoCount = 0; /* FIXME */
591
592 Spi->PagedPoolPages = MiMemoryConsumers[MC_PPOOL].PagesUsed;
593 Spi->PagedPoolAllocs = 0; /* FIXME */
594 Spi->PagedPoolFrees = 0; /* FIXME */
595 Spi->NonPagedPoolPages = MiMemoryConsumers[MC_NPPOOL].PagesUsed;
596 Spi->NonPagedPoolAllocs = 0; /* FIXME */
597 Spi->NonPagedPoolFrees = 0; /* FIXME */
598
599 Spi->FreeSystemPtes = 0; /* FIXME */
600
601 Spi->ResidentSystemCodePage = MmStats.NrSystemPages; /* FIXME */
602
603 Spi->TotalSystemDriverPages = 0; /* FIXME */
604 Spi->TotalSystemCodePages = 0; /* FIXME */
605 Spi->NonPagedPoolLookasideHits = 0; /* FIXME */
606 Spi->PagedPoolLookasideHits = 0; /* FIXME */
607 Spi->Spare3Count = 0; /* FIXME */
608
609 Spi->ResidentSystemCachePage = MiMemoryConsumers[MC_CACHE].PagesUsed;
610 Spi->ResidentPagedPoolPage = MmPagedPoolSize; /* FIXME */
611
612 Spi->ResidentSystemDriverPage = 0; /* FIXME */
613 Spi->CcFastReadNoWait = 0; /* FIXME */
614 Spi->CcFastReadWait = 0; /* FIXME */
615 Spi->CcFastReadResourceMiss = 0; /* FIXME */
616 Spi->CcFastReadNotPossible = 0; /* FIXME */
617
618 Spi->CcFastMdlReadNoWait = 0; /* FIXME */
619 Spi->CcFastMdlReadWait = 0; /* FIXME */
620 Spi->CcFastMdlReadResourceMiss = 0; /* FIXME */
621 Spi->CcFastMdlReadNotPossible = 0; /* FIXME */
622
623 Spi->CcMapDataNoWait = 0; /* FIXME */
624 Spi->CcMapDataWait = 0; /* FIXME */
625 Spi->CcMapDataNoWaitMiss = 0; /* FIXME */
626 Spi->CcMapDataWaitMiss = 0; /* FIXME */
627
628 Spi->CcPinMappedDataCount = 0; /* FIXME */
629 Spi->CcPinReadNoWait = 0; /* FIXME */
630 Spi->CcPinReadWait = 0; /* FIXME */
631 Spi->CcPinReadNoWaitMiss = 0; /* FIXME */
632 Spi->CcPinReadWaitMiss = 0; /* FIXME */
633 Spi->CcCopyReadNoWait = 0; /* FIXME */
634 Spi->CcCopyReadWait = 0; /* FIXME */
635 Spi->CcCopyReadNoWaitMiss = 0; /* FIXME */
636 Spi->CcCopyReadWaitMiss = 0; /* FIXME */
637
638 Spi->CcMdlReadNoWait = 0; /* FIXME */
639 Spi->CcMdlReadWait = 0; /* FIXME */
640 Spi->CcMdlReadNoWaitMiss = 0; /* FIXME */
641 Spi->CcMdlReadWaitMiss = 0; /* FIXME */
642 Spi->CcReadAheadIos = 0; /* FIXME */
643 Spi->CcLazyWriteIos = 0; /* FIXME */
644 Spi->CcLazyWritePages = 0; /* FIXME */
645 Spi->CcDataFlushes = 0; /* FIXME */
646 Spi->CcDataPages = 0; /* FIXME */
647 Spi->ContextSwitches = 0; /* FIXME */
648 Spi->FirstLevelTbFills = 0; /* FIXME */
649 Spi->SecondLevelTbFills = 0; /* FIXME */
650 Spi->SystemCalls = 0; /* FIXME */
651
652 return STATUS_SUCCESS;
653 }
654
655 /* Class 3 - Time Of Day Information */
656 QSI_DEF(SystemTimeOfDayInformation)
657 {
658 SYSTEM_TIMEOFDAY_INFORMATION Sti;
659 LARGE_INTEGER CurrentTime;
660
661 /* Set amount of written information to 0 */
662 *ReqSize = 0;
663
664 /* Check user buffer's size */
665 if (Size > sizeof(SYSTEM_TIMEOFDAY_INFORMATION))
666 {
667 return STATUS_INFO_LENGTH_MISMATCH;
668 }
669
670 /* Get current time */
671 KeQuerySystemTime(&CurrentTime);
672
673 /* Zero local buffer */
674 RtlZeroMemory(&Sti, sizeof(SYSTEM_TIMEOFDAY_INFORMATION));
675
676 /* Fill local time structure */
677 Sti.BootTime= KeBootTime;
678 Sti.CurrentTime = CurrentTime;
679 Sti.TimeZoneBias.QuadPart = ExpTimeZoneBias.QuadPart;
680 Sti.TimeZoneId = ExpTimeZoneId;
681 Sti.Reserved = 0;
682
683 /* Copy as much as requested by caller */
684 RtlCopyMemory(Buffer, &Sti, Size);
685
686 /* Set amount of information we copied */
687 *ReqSize = Size;
688
689 return STATUS_SUCCESS;
690 }
691
692 /* Class 4 - Path Information */
693 QSI_DEF(SystemPathInformation)
694 {
695 /* FIXME: QSI returns STATUS_BREAKPOINT. Why? */
696 DPRINT1("NtQuerySystemInformation - SystemPathInformation not implemented\n");
697
698 return STATUS_BREAKPOINT;
699 }
700
701 /* Class 5 - Process Information */
702 QSI_DEF(SystemProcessInformation)
703 {
704 PSYSTEM_PROCESS_INFORMATION SpiCurrent;
705 PSYSTEM_THREAD_INFORMATION ThreadInfo;
706 PEPROCESS Process = NULL, SystemProcess;
707 PETHREAD CurrentThread;
708 ANSI_STRING ImageName;
709 ULONG CurrentSize;
710 USHORT ImageNameMaximumLength; // image name len in bytes
711 USHORT ImageNameLength;
712 PLIST_ENTRY CurrentEntry;
713 ULONG TotalSize = 0, ThreadsCount;
714 ULONG TotalUser, TotalKernel;
715 PUCHAR Current;
716 NTSTATUS Status = STATUS_SUCCESS;
717 PUNICODE_STRING ProcessImageName;
718 PWCHAR szSrc;
719 BOOLEAN Overflow = FALSE;
720
721 _SEH2_TRY
722 {
723 /* scan the process list */
724
725 PSYSTEM_PROCESS_INFORMATION Spi
726 = (PSYSTEM_PROCESS_INFORMATION) Buffer;
727
728 *ReqSize = sizeof(SYSTEM_PROCESS_INFORMATION);
729
730 /* Check for overflow */
731 if (Size < sizeof(SYSTEM_PROCESS_INFORMATION))
732 Overflow = TRUE;
733
734 /* Zero user's buffer */
735 if (!Overflow) RtlZeroMemory(Spi, Size);
736
737 SystemProcess = PsIdleProcess;
738 Process = SystemProcess;
739 Current = (PUCHAR) Spi;
740
741 do
742 {
743 SpiCurrent = (PSYSTEM_PROCESS_INFORMATION) Current;
744
745 ThreadsCount = 0;
746 CurrentEntry = Process->ThreadListHead.Flink;
747 while (CurrentEntry != &Process->ThreadListHead)
748 {
749 ThreadsCount++;
750 CurrentEntry = CurrentEntry->Flink;
751 }
752
753 // size of the structure for every process
754 CurrentSize = sizeof(SYSTEM_PROCESS_INFORMATION) + sizeof(SYSTEM_THREAD_INFORMATION) * ThreadsCount;
755 ImageNameLength = 0;
756 Status = SeLocateProcessImageName(Process, &ProcessImageName);
757 szSrc = NULL;
758 if (NT_SUCCESS(Status) && (ProcessImageName->Length > 0))
759 {
760 szSrc = (PWCHAR)((PCHAR)ProcessImageName->Buffer + ProcessImageName->Length);
761 /* Loop the file name*/
762 while (szSrc > ProcessImageName->Buffer)
763 {
764 /* Make sure this isn't a backslash */
765 if (*--szSrc == OBJ_NAME_PATH_SEPARATOR)
766 {
767 szSrc++;
768 break;
769 }
770 else
771 {
772 ImageNameLength += sizeof(WCHAR);
773 }
774 }
775 }
776 if (!ImageNameLength && Process != PsIdleProcess && Process->ImageFileName)
777 {
778 ImageNameLength = strlen(Process->ImageFileName) * sizeof(WCHAR);
779 }
780
781 /* Round up the image name length as NT does */
782 if (ImageNameLength > 0)
783 ImageNameMaximumLength = ROUND_UP(ImageNameLength + sizeof(WCHAR), 8);
784 else
785 ImageNameMaximumLength = 0;
786
787 TotalSize += CurrentSize + ImageNameMaximumLength;
788
789 /* Check for overflow */
790 if (TotalSize > Size)
791 Overflow = TRUE;
792
793 /* Fill system information */
794 if (!Overflow)
795 {
796 SpiCurrent->NextEntryOffset = CurrentSize + ImageNameMaximumLength; // relative offset to the beginnnig of the next structure
797 SpiCurrent->NumberOfThreads = ThreadsCount;
798 SpiCurrent->CreateTime = Process->CreateTime;
799 SpiCurrent->ImageName.Length = ImageNameLength;
800 SpiCurrent->ImageName.MaximumLength = ImageNameMaximumLength;
801 SpiCurrent->ImageName.Buffer = (void*)(Current + CurrentSize);
802
803 /* Copy name to the end of the struct */
804 if(Process != PsIdleProcess)
805 {
806 if (szSrc)
807 {
808 RtlCopyMemory(SpiCurrent->ImageName.Buffer, szSrc, SpiCurrent->ImageName.Length);
809
810 /* Release the memory allocated by SeLocateProcessImageName */
811 ExFreePool(ProcessImageName);
812 }
813 else if (Process->ImageFileName)
814 {
815 RtlInitAnsiString(&ImageName, Process->ImageFileName);
816 RtlAnsiStringToUnicodeString(&SpiCurrent->ImageName, &ImageName, FALSE);
817 }
818 }
819 else
820 {
821 RtlInitUnicodeString(&SpiCurrent->ImageName, NULL);
822 }
823
824 SpiCurrent->BasePriority = Process->Pcb.BasePriority;
825 SpiCurrent->UniqueProcessId = Process->UniqueProcessId;
826 SpiCurrent->InheritedFromUniqueProcessId = Process->InheritedFromUniqueProcessId;
827 SpiCurrent->HandleCount = ObGetProcessHandleCount(Process);
828 SpiCurrent->PeakVirtualSize = Process->PeakVirtualSize;
829 SpiCurrent->VirtualSize = Process->VirtualSize;
830 SpiCurrent->PageFaultCount = Process->Vm.PageFaultCount;
831 SpiCurrent->PeakWorkingSetSize = Process->Vm.PeakWorkingSetSize;
832 SpiCurrent->WorkingSetSize = Process->Vm.WorkingSetSize;
833 SpiCurrent->QuotaPeakPagedPoolUsage = Process->QuotaPeak[0];
834 SpiCurrent->QuotaPagedPoolUsage = Process->QuotaUsage[0];
835 SpiCurrent->QuotaPeakNonPagedPoolUsage = Process->QuotaPeak[1];
836 SpiCurrent->QuotaNonPagedPoolUsage = Process->QuotaUsage[1];
837 SpiCurrent->PagefileUsage = Process->QuotaUsage[2];
838 SpiCurrent->PeakPagefileUsage = Process->QuotaPeak[2];
839 SpiCurrent->PrivatePageCount = Process->CommitCharge;
840 ThreadInfo = (PSYSTEM_THREAD_INFORMATION)(SpiCurrent + 1);
841
842 CurrentEntry = Process->ThreadListHead.Flink;
843 while (CurrentEntry != &Process->ThreadListHead)
844 {
845 CurrentThread = CONTAINING_RECORD(CurrentEntry, ETHREAD,
846 ThreadListEntry);
847
848 ThreadInfo->KernelTime.QuadPart = UInt32x32To64(CurrentThread->Tcb.KernelTime, KeMaximumIncrement);
849 ThreadInfo->UserTime.QuadPart = UInt32x32To64(CurrentThread->Tcb.UserTime, KeMaximumIncrement);
850 ThreadInfo->CreateTime.QuadPart = CurrentThread->CreateTime.QuadPart;
851 ThreadInfo->WaitTime = CurrentThread->Tcb.WaitTime;
852 ThreadInfo->StartAddress = (PVOID) CurrentThread->StartAddress;
853 ThreadInfo->ClientId = CurrentThread->Cid;
854 ThreadInfo->Priority = CurrentThread->Tcb.Priority;
855 ThreadInfo->BasePriority = CurrentThread->Tcb.BasePriority;
856 ThreadInfo->ContextSwitches = CurrentThread->Tcb.ContextSwitches;
857 ThreadInfo->ThreadState = CurrentThread->Tcb.State;
858 ThreadInfo->WaitReason = CurrentThread->Tcb.WaitReason;
859
860 ThreadInfo++;
861 CurrentEntry = CurrentEntry->Flink;
862 }
863
864 /* Query total user/kernel times of a process */
865 TotalKernel = KeQueryRuntimeProcess(&Process->Pcb, &TotalUser);
866 SpiCurrent->UserTime.QuadPart = UInt32x32To64(TotalUser, KeMaximumIncrement);
867 SpiCurrent->KernelTime.QuadPart = UInt32x32To64(TotalKernel, KeMaximumIncrement);
868 }
869
870 /* Handle idle process entry */
871 if (Process == PsIdleProcess) Process = NULL;
872
873 Process = PsGetNextProcess(Process);
874 ThreadsCount = 0;
875 if ((Process == SystemProcess) || (Process == NULL))
876 {
877 if (!Overflow)
878 SpiCurrent->NextEntryOffset = 0;
879 break;
880 }
881 else
882 Current += CurrentSize + ImageNameMaximumLength;
883 } while ((Process != SystemProcess) && (Process != NULL));
884
885 if(Process != NULL)
886 ObDereferenceObject(Process);
887 Status = STATUS_SUCCESS;
888 }
889 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
890 {
891 if(Process != NULL)
892 ObDereferenceObject(Process);
893 Status = _SEH2_GetExceptionCode();
894 }
895 _SEH2_END
896
897 if (Overflow)
898 Status = STATUS_INFO_LENGTH_MISMATCH;
899
900 *ReqSize = TotalSize;
901 return Status;
902 }
903
904 /* Class 6 - Call Count Information */
905 QSI_DEF(SystemCallCountInformation)
906 {
907 /* FIXME */
908 DPRINT1("NtQuerySystemInformation - SystemCallCountInformation not implemented\n");
909 return STATUS_NOT_IMPLEMENTED;
910 }
911
912 /* Class 7 - Device Information */
913 QSI_DEF(SystemDeviceInformation)
914 {
915 PSYSTEM_DEVICE_INFORMATION Sdi
916 = (PSYSTEM_DEVICE_INFORMATION) Buffer;
917 PCONFIGURATION_INFORMATION ConfigInfo;
918
919 *ReqSize = sizeof(SYSTEM_DEVICE_INFORMATION);
920
921 /* Check user buffer's size */
922 if (Size < sizeof(SYSTEM_DEVICE_INFORMATION))
923 {
924 return STATUS_INFO_LENGTH_MISMATCH;
925 }
926
927 ConfigInfo = IoGetConfigurationInformation();
928
929 Sdi->NumberOfDisks = ConfigInfo->DiskCount;
930 Sdi->NumberOfFloppies = ConfigInfo->FloppyCount;
931 Sdi->NumberOfCdRoms = ConfigInfo->CdRomCount;
932 Sdi->NumberOfTapes = ConfigInfo->TapeCount;
933 Sdi->NumberOfSerialPorts = ConfigInfo->SerialCount;
934 Sdi->NumberOfParallelPorts = ConfigInfo->ParallelCount;
935
936 return STATUS_SUCCESS;
937 }
938
939 /* Class 8 - Processor Performance Information */
940 QSI_DEF(SystemProcessorPerformanceInformation)
941 {
942 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION Spi
943 = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) Buffer;
944
945 LONG i;
946 ULONG TotalTime;
947 LARGE_INTEGER CurrentTime;
948 PKPRCB Prcb;
949
950 *ReqSize = KeNumberProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
951
952 /* Check user buffer's size */
953 if (Size < *ReqSize)
954 {
955 return STATUS_INFO_LENGTH_MISMATCH;
956 }
957
958 CurrentTime.QuadPart = KeQueryInterruptTime();
959 for (i = 0; i < KeNumberProcessors; i++)
960 {
961 /* Get the PRCB on this processor */
962 Prcb = KiProcessorBlock[i];
963
964 /* Calculate total user and kernel times */
965 TotalTime = Prcb->IdleThread->KernelTime + Prcb->IdleThread->UserTime;
966 Spi->IdleTime.QuadPart = UInt32x32To64(TotalTime, KeMaximumIncrement);
967 Spi->KernelTime.QuadPart = UInt32x32To64(Prcb->KernelTime, KeMaximumIncrement);
968 Spi->UserTime.QuadPart = UInt32x32To64(Prcb->UserTime, KeMaximumIncrement);
969 Spi->DpcTime.QuadPart = UInt32x32To64(Prcb->DpcTime, KeMaximumIncrement);
970 Spi->InterruptTime.QuadPart = UInt32x32To64(Prcb->InterruptTime, KeMaximumIncrement);
971 Spi->InterruptCount = Prcb->InterruptCount;
972 Spi++;
973 }
974
975 return STATUS_SUCCESS;
976 }
977
978 /* Class 9 - Flags Information */
979 QSI_DEF(SystemFlagsInformation)
980 {
981 if (sizeof(SYSTEM_FLAGS_INFORMATION) != Size)
982 {
983 *ReqSize = sizeof(SYSTEM_FLAGS_INFORMATION);
984 return (STATUS_INFO_LENGTH_MISMATCH);
985 }
986 ((PSYSTEM_FLAGS_INFORMATION) Buffer)->Flags = NtGlobalFlag;
987 return STATUS_SUCCESS;
988 }
989
990 SSI_DEF(SystemFlagsInformation)
991 {
992 if (sizeof(SYSTEM_FLAGS_INFORMATION) != Size)
993 {
994 return STATUS_INFO_LENGTH_MISMATCH;
995 }
996 NtGlobalFlag = ((PSYSTEM_FLAGS_INFORMATION) Buffer)->Flags;
997 return STATUS_SUCCESS;
998 }
999
1000 /* Class 10 - Call Time Information */
1001 QSI_DEF(SystemCallTimeInformation)
1002 {
1003 /* FIXME */
1004 DPRINT1("NtQuerySystemInformation - SystemCallTimeInformation not implemented\n");
1005 return STATUS_NOT_IMPLEMENTED;
1006 }
1007
1008 /* Class 11 - Module Information */
1009 QSI_DEF(SystemModuleInformation)
1010 {
1011 extern LIST_ENTRY PsLoadedModuleList;
1012 return ExpQueryModuleInformation(&PsLoadedModuleList,
1013 NULL,
1014 (PRTL_PROCESS_MODULES)Buffer,
1015 Size,
1016 ReqSize);
1017 }
1018
1019 /* Class 12 - Locks Information */
1020 QSI_DEF(SystemLocksInformation)
1021 {
1022 /* FIXME */
1023 DPRINT1("NtQuerySystemInformation - SystemLocksInformation not implemented\n");
1024 return STATUS_NOT_IMPLEMENTED;
1025 }
1026
1027 /* Class 13 - Stack Trace Information */
1028 QSI_DEF(SystemStackTraceInformation)
1029 {
1030 /* FIXME */
1031 DPRINT1("NtQuerySystemInformation - SystemStackTraceInformation not implemented\n");
1032 return STATUS_NOT_IMPLEMENTED;
1033 }
1034
1035 /* Class 14 - Paged Pool Information */
1036 QSI_DEF(SystemPagedPoolInformation)
1037 {
1038 /* FIXME */
1039 DPRINT1("NtQuerySystemInformation - SystemPagedPoolInformation not implemented\n");
1040 return STATUS_NOT_IMPLEMENTED;
1041 }
1042
1043 /* Class 15 - Non Paged Pool Information */
1044 QSI_DEF(SystemNonPagedPoolInformation)
1045 {
1046 /* FIXME */
1047 DPRINT1("NtQuerySystemInformation - SystemNonPagedPoolInformation not implemented\n");
1048 return STATUS_NOT_IMPLEMENTED;
1049 }
1050
1051
1052 /* Class 16 - Handle Information */
1053 QSI_DEF(SystemHandleInformation)
1054 {
1055 PEPROCESS pr, syspr;
1056 ULONG curSize, i = 0;
1057 ULONG hCount = 0;
1058
1059 PSYSTEM_HANDLE_INFORMATION Shi =
1060 (PSYSTEM_HANDLE_INFORMATION) Buffer;
1061
1062 DPRINT("NtQuerySystemInformation - SystemHandleInformation\n");
1063
1064 if (Size < sizeof(SYSTEM_HANDLE_INFORMATION))
1065 {
1066 *ReqSize = sizeof(SYSTEM_HANDLE_INFORMATION);
1067 return STATUS_INFO_LENGTH_MISMATCH;
1068 }
1069
1070 DPRINT("SystemHandleInformation 1\n");
1071
1072 /* First Calc Size from Count. */
1073 syspr = PsGetNextProcess(NULL);
1074 pr = syspr;
1075
1076 do
1077 {
1078 hCount = hCount + ObGetProcessHandleCount(pr);
1079 pr = PsGetNextProcess(pr);
1080
1081 if ((pr == syspr) || (pr == NULL)) break;
1082 }
1083 while ((pr != syspr) && (pr != NULL));
1084
1085 if(pr != NULL)
1086 {
1087 ObDereferenceObject(pr);
1088 }
1089
1090 DPRINT("SystemHandleInformation 2\n");
1091
1092 curSize = sizeof(SYSTEM_HANDLE_INFORMATION) +
1093 ((sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO) * hCount) -
1094 (sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO)));
1095
1096 Shi->NumberOfHandles = hCount;
1097
1098 if (curSize > Size)
1099 {
1100 *ReqSize = curSize;
1101 return (STATUS_INFO_LENGTH_MISMATCH);
1102 }
1103
1104 DPRINT("SystemHandleInformation 3\n");
1105
1106 /* Now get Handles from all processs. */
1107 syspr = PsGetNextProcess(NULL);
1108 pr = syspr;
1109
1110 do
1111 {
1112 int Count = 0, HandleCount;
1113
1114 HandleCount = ObGetProcessHandleCount(pr);
1115
1116 for (Count = 0; HandleCount > 0 ; HandleCount--)
1117 {
1118 Shi->Handles[i].UniqueProcessId = (USHORT)(ULONG)pr->UniqueProcessId;
1119 Count++;
1120 i++;
1121 }
1122
1123 pr = PsGetNextProcess(pr);
1124
1125 if ((pr == syspr) || (pr == NULL)) break;
1126 }
1127 while ((pr != syspr) && (pr != NULL));
1128
1129 if(pr != NULL) ObDereferenceObject(pr);
1130
1131 DPRINT("SystemHandleInformation 4\n");
1132 return STATUS_SUCCESS;
1133
1134 }
1135 /*
1136 SSI_DEF(SystemHandleInformation)
1137 {
1138
1139 return STATUS_SUCCESS;
1140 }
1141 */
1142
1143 /* Class 17 - Information */
1144 QSI_DEF(SystemObjectInformation)
1145 {
1146 /* FIXME */
1147 DPRINT1("NtQuerySystemInformation - SystemObjectInformation not implemented\n");
1148 return STATUS_NOT_IMPLEMENTED;
1149 }
1150
1151 /* Class 18 - Information */
1152 QSI_DEF(SystemPageFileInformation)
1153 {
1154 UNICODE_STRING FileName; /* FIXME */
1155 SYSTEM_PAGEFILE_INFORMATION *Spfi = (SYSTEM_PAGEFILE_INFORMATION *) Buffer;
1156
1157 if (Size < sizeof(SYSTEM_PAGEFILE_INFORMATION))
1158 {
1159 * ReqSize = sizeof(SYSTEM_PAGEFILE_INFORMATION);
1160 return STATUS_INFO_LENGTH_MISMATCH;
1161 }
1162
1163 RtlInitUnicodeString(&FileName, NULL); /* FIXME */
1164
1165 /* FIXME */
1166 Spfi->NextEntryOffset = 0;
1167
1168 Spfi->TotalSize = MiFreeSwapPages + MiUsedSwapPages;
1169 Spfi->TotalInUse = MiUsedSwapPages;
1170 Spfi->PeakUsage = MiUsedSwapPages; /* FIXME */
1171 Spfi->PageFileName = FileName;
1172 return STATUS_SUCCESS;
1173 }
1174
1175 /* Class 19 - Vdm Instemul Information */
1176 QSI_DEF(SystemVdmInstemulInformation)
1177 {
1178 /* FIXME */
1179 DPRINT1("NtQuerySystemInformation - SystemVdmInstemulInformation not implemented\n");
1180 return STATUS_NOT_IMPLEMENTED;
1181 }
1182
1183 /* Class 20 - Vdm Bop Information */
1184 QSI_DEF(SystemVdmBopInformation)
1185 {
1186 /* FIXME */
1187 DPRINT1("NtQuerySystemInformation - SystemVdmBopInformation not implemented\n");
1188 return STATUS_NOT_IMPLEMENTED;
1189 }
1190
1191 /* Class 21 - File Cache Information */
1192 QSI_DEF(SystemFileCacheInformation)
1193 {
1194 SYSTEM_FILECACHE_INFORMATION *Sci = (SYSTEM_FILECACHE_INFORMATION *) Buffer;
1195
1196 if (Size < sizeof(SYSTEM_FILECACHE_INFORMATION))
1197 {
1198 *ReqSize = sizeof(SYSTEM_FILECACHE_INFORMATION);
1199 return STATUS_INFO_LENGTH_MISMATCH;
1200 }
1201
1202 RtlZeroMemory(Sci, sizeof(SYSTEM_FILECACHE_INFORMATION));
1203
1204 /* Return the Byte size not the page size. */
1205 Sci->CurrentSize =
1206 MiMemoryConsumers[MC_CACHE].PagesUsed * PAGE_SIZE;
1207 Sci->PeakSize =
1208 MiMemoryConsumers[MC_CACHE].PagesUsed * PAGE_SIZE; /* FIXME */
1209 /* Taskmgr multiplies this one by page size right away */
1210 Sci->CurrentSizeIncludingTransitionInPages =
1211 MiMemoryConsumers[MC_CACHE].PagesUsed; /* FIXME: Should be */
1212 /* system working set and standby pages. */
1213 Sci->PageFaultCount = 0; /* FIXME */
1214 Sci->MinimumWorkingSet = 0; /* FIXME */
1215 Sci->MaximumWorkingSet = 0; /* FIXME */
1216
1217 return STATUS_SUCCESS;
1218 }
1219
1220 SSI_DEF(SystemFileCacheInformation)
1221 {
1222 if (Size < sizeof(SYSTEM_FILECACHE_INFORMATION))
1223 {
1224 return STATUS_INFO_LENGTH_MISMATCH;
1225 }
1226 /* FIXME */
1227 DPRINT1("NtSetSystemInformation - SystemFileCacheInformation not implemented\n");
1228 return STATUS_NOT_IMPLEMENTED;
1229 }
1230
1231 /* Class 22 - Pool Tag Information */
1232 QSI_DEF(SystemPoolTagInformation)
1233 {
1234 /* FIXME */
1235 DPRINT1("NtQuerySystemInformation - SystemPoolTagInformation not implemented\n");
1236 return STATUS_NOT_IMPLEMENTED;
1237 }
1238
1239 /* Class 23 - Interrupt Information for all processors */
1240 QSI_DEF(SystemInterruptInformation)
1241 {
1242 PKPRCB Prcb;
1243 PKPCR Pcr;
1244 LONG i;
1245 ULONG ti;
1246 PSYSTEM_INTERRUPT_INFORMATION sii = (PSYSTEM_INTERRUPT_INFORMATION)Buffer;
1247
1248 if(Size < KeNumberProcessors * sizeof(SYSTEM_INTERRUPT_INFORMATION))
1249 {
1250 return STATUS_INFO_LENGTH_MISMATCH;
1251 }
1252
1253 ti = KeQueryTimeIncrement();
1254
1255 for (i = 0; i < KeNumberProcessors; i++)
1256 {
1257 Prcb = KiProcessorBlock[i];
1258 Pcr = CONTAINING_RECORD(Prcb, KPCR, Prcb);
1259 #ifdef _M_ARM // This code should probably be done differently
1260 sii->ContextSwitches = Pcr->ContextSwitches;
1261 #else
1262 sii->ContextSwitches = ((PKIPCR)Pcr)->ContextSwitches;
1263 #endif
1264 sii->DpcCount = Prcb->DpcData[0].DpcCount;
1265 sii->DpcRate = Prcb->DpcRequestRate;
1266 sii->TimeIncrement = ti;
1267 sii->DpcBypassCount = 0;
1268 sii->ApcBypassCount = 0;
1269 sii++;
1270 }
1271
1272 return STATUS_SUCCESS;
1273 }
1274
1275 /* Class 24 - DPC Behaviour Information */
1276 QSI_DEF(SystemDpcBehaviourInformation)
1277 {
1278 /* FIXME */
1279 DPRINT1("NtQuerySystemInformation - SystemDpcBehaviourInformation not implemented\n");
1280 return STATUS_NOT_IMPLEMENTED;
1281 }
1282
1283 SSI_DEF(SystemDpcBehaviourInformation)
1284 {
1285 /* FIXME */
1286 DPRINT1("NtSetSystemInformation - SystemDpcBehaviourInformation not implemented\n");
1287 return STATUS_NOT_IMPLEMENTED;
1288 }
1289
1290 /* Class 25 - Full Memory Information */
1291 QSI_DEF(SystemFullMemoryInformation)
1292 {
1293 PULONG Spi = (PULONG) Buffer;
1294
1295 PEPROCESS TheIdleProcess;
1296
1297 *ReqSize = sizeof(ULONG);
1298
1299 if (sizeof(ULONG) != Size)
1300 {
1301 return STATUS_INFO_LENGTH_MISMATCH;
1302 }
1303
1304 DPRINT("SystemFullMemoryInformation\n");
1305
1306 TheIdleProcess = PsIdleProcess;
1307
1308 DPRINT("PID: %d, KernelTime: %u PFFree: %d PFUsed: %d\n",
1309 TheIdleProcess->UniqueProcessId,
1310 TheIdleProcess->Pcb.KernelTime,
1311 MiFreeSwapPages,
1312 MiUsedSwapPages);
1313
1314 #ifndef NDEBUG
1315 MmPrintMemoryStatistic();
1316 #endif
1317
1318 *Spi = MiMemoryConsumers[MC_USER].PagesUsed;
1319
1320 return STATUS_SUCCESS;
1321 }
1322
1323 /* Class 26 - Load Image */
1324 SSI_DEF(SystemLoadGdiDriverInformation)
1325 {
1326 PSYSTEM_GDI_DRIVER_INFORMATION DriverInfo = (PVOID)Buffer;
1327 KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
1328 UNICODE_STRING ImageName;
1329 PVOID ImageBase;
1330 PLDR_DATA_TABLE_ENTRY ModuleObject;
1331 ULONG_PTR EntryPoint;
1332 NTSTATUS Status;
1333 ULONG DirSize;
1334 PIMAGE_NT_HEADERS NtHeader;
1335
1336 /* Validate size */
1337 if (Size != sizeof(SYSTEM_GDI_DRIVER_INFORMATION))
1338 {
1339 /* Incorrect buffer length, fail */
1340 return STATUS_INFO_LENGTH_MISMATCH;
1341 }
1342
1343 /* Only kernel-mode can call this function */
1344 if (PreviousMode != KernelMode) return STATUS_PRIVILEGE_NOT_HELD;
1345
1346 /* Load the driver */
1347 ImageName = DriverInfo->DriverName;
1348 Status = MmLoadSystemImage(&ImageName,
1349 NULL,
1350 NULL,
1351 0,
1352 (PVOID)&ModuleObject,
1353 &ImageBase);
1354 if (!NT_SUCCESS(Status)) return Status;
1355
1356 /* Return the export pointer */
1357 DriverInfo->ExportSectionPointer =
1358 RtlImageDirectoryEntryToData(ImageBase,
1359 TRUE,
1360 IMAGE_DIRECTORY_ENTRY_EXPORT,
1361 &DirSize);
1362
1363 /* Get the entrypoint */
1364 NtHeader = RtlImageNtHeader(ImageBase);
1365 EntryPoint = NtHeader->OptionalHeader.AddressOfEntryPoint;
1366 EntryPoint += (ULONG_PTR)ImageBase;
1367
1368 /* Save other data */
1369 DriverInfo->ImageAddress = ImageBase;
1370 DriverInfo->SectionPointer = NULL;
1371 DriverInfo->EntryPoint = (PVOID)EntryPoint;
1372 DriverInfo->ImageLength = NtHeader->OptionalHeader.SizeOfImage;
1373
1374 /* All is good */
1375 return STATUS_SUCCESS;
1376 }
1377
1378 /* Class 27 - Unload Image */
1379 SSI_DEF(SystemUnloadGdiDriverInformation)
1380 {
1381 PLDR_DATA_TABLE_ENTRY LdrEntry;
1382 PLIST_ENTRY NextEntry;
1383 PVOID BaseAddr = *((PVOID*)Buffer);
1384
1385 if(Size != sizeof(PVOID))
1386 return STATUS_INFO_LENGTH_MISMATCH;
1387
1388 if(KeGetPreviousMode() != KernelMode)
1389 return STATUS_PRIVILEGE_NOT_HELD;
1390
1391 // Scan the module list
1392 NextEntry = PsLoadedModuleList.Flink;
1393 while(NextEntry != &PsLoadedModuleList)
1394 {
1395 LdrEntry = CONTAINING_RECORD(NextEntry,
1396 LDR_DATA_TABLE_ENTRY,
1397 InLoadOrderLinks);
1398
1399 if (LdrEntry->DllBase == BaseAddr)
1400 {
1401 // Found it.
1402 break;
1403 }
1404
1405 NextEntry = NextEntry->Flink;
1406 }
1407
1408 // Check if we found the image
1409 if(NextEntry != &PsLoadedModuleList)
1410 {
1411 return MmUnloadSystemImage(LdrEntry);
1412 }
1413 else
1414 {
1415 DPRINT1("Image 0x%x not found.\n", BaseAddr);
1416 return STATUS_DLL_NOT_FOUND;
1417 }
1418
1419 }
1420
1421 /* Class 28 - Time Adjustment Information */
1422 QSI_DEF(SystemTimeAdjustmentInformation)
1423 {
1424 PSYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfo =
1425 (PSYSTEM_QUERY_TIME_ADJUST_INFORMATION)Buffer;
1426
1427 /* Check if enough storage was provided */
1428 if (sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION) > Size)
1429 {
1430 * ReqSize = sizeof(SYSTEM_QUERY_TIME_ADJUST_INFORMATION);
1431 return STATUS_INFO_LENGTH_MISMATCH;
1432 }
1433
1434 /* Give time values to our caller */
1435 TimeInfo->TimeIncrement = KeMaximumIncrement;
1436 TimeInfo->TimeAdjustment = KeTimeAdjustment;
1437 TimeInfo->Enable = TRUE;
1438
1439 return STATUS_SUCCESS;
1440 }
1441
1442 SSI_DEF(SystemTimeAdjustmentInformation)
1443 {
1444 KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
1445 /*PSYSTEM_SET_TIME_ADJUST_INFORMATION TimeInfo =
1446 (PSYSTEM_SET_TIME_ADJUST_INFORMATION)Buffer;*/
1447
1448 /* Check size of a buffer, it must match our expectations */
1449 if (sizeof(SYSTEM_SET_TIME_ADJUST_INFORMATION) != Size)
1450 return STATUS_INFO_LENGTH_MISMATCH;
1451
1452 /* Check who is calling */
1453 if (PreviousMode != KernelMode)
1454 {
1455 /* Check access rights */
1456 if (!SeSinglePrivilegeCheck(SeSystemtimePrivilege, PreviousMode))
1457 {
1458 return STATUS_PRIVILEGE_NOT_HELD;
1459 }
1460 }
1461
1462 /* TODO: Set time adjustment information */
1463 DPRINT1("Setting of SystemTimeAdjustmentInformation is not implemented yet!\n");
1464 return STATUS_NOT_IMPLEMENTED;
1465 }
1466
1467 /* Class 29 - Summary Memory Information */
1468 QSI_DEF(SystemSummaryMemoryInformation)
1469 {
1470 /* FIXME */
1471 DPRINT1("NtQuerySystemInformation - SystemSummaryMemoryInformation not implemented\n");
1472 return STATUS_NOT_IMPLEMENTED;
1473 }
1474
1475 /* Class 30 - Next Event Id Information */
1476 QSI_DEF(SystemNextEventIdInformation)
1477 {
1478 /* FIXME */
1479 DPRINT1("NtQuerySystemInformation - SystemNextEventIdInformation not implemented\n");
1480 return STATUS_NOT_IMPLEMENTED;
1481 }
1482
1483 /* Class 31 - Event Ids Information */
1484 QSI_DEF(SystemEventIdsInformation)
1485 {
1486 /* FIXME */
1487 DPRINT1("NtQuerySystemInformation - SystemEventIdsInformation not implemented\n");
1488 return STATUS_NOT_IMPLEMENTED;
1489 }
1490
1491 /* Class 32 - Crash Dump Information */
1492 QSI_DEF(SystemCrashDumpInformation)
1493 {
1494 /* FIXME */
1495 DPRINT1("NtQuerySystemInformation - SystemCrashDumpInformation not implemented\n");
1496 return STATUS_NOT_IMPLEMENTED;
1497 }
1498
1499 /* Class 33 - Exception Information */
1500 QSI_DEF(SystemExceptionInformation)
1501 {
1502 /* FIXME */
1503 DPRINT1("NtQuerySystemInformation - SystemExceptionInformation not implemented\n");
1504 return STATUS_NOT_IMPLEMENTED;
1505 }
1506
1507 /* Class 34 - Crash Dump State Information */
1508 QSI_DEF(SystemCrashDumpStateInformation)
1509 {
1510 /* FIXME */
1511 DPRINT1("NtQuerySystemInformation - SystemCrashDumpStateInformation not implemented\n");
1512 return STATUS_NOT_IMPLEMENTED;
1513 }
1514
1515 /* Class 35 - Kernel Debugger Information */
1516 QSI_DEF(SystemKernelDebuggerInformation)
1517 {
1518 PSYSTEM_KERNEL_DEBUGGER_INFORMATION skdi = (PSYSTEM_KERNEL_DEBUGGER_INFORMATION) Buffer;
1519
1520 *ReqSize = sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION);
1521 if (Size < sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION))
1522 {
1523 return STATUS_INFO_LENGTH_MISMATCH;
1524 }
1525
1526 skdi->KernelDebuggerEnabled = KD_DEBUGGER_ENABLED;
1527 skdi->KernelDebuggerNotPresent = KD_DEBUGGER_NOT_PRESENT;
1528
1529 return STATUS_SUCCESS;
1530 }
1531
1532 /* Class 36 - Context Switch Information */
1533 QSI_DEF(SystemContextSwitchInformation)
1534 {
1535 /* FIXME */
1536 DPRINT1("NtQuerySystemInformation - SystemContextSwitchInformation not implemented\n");
1537 return STATUS_NOT_IMPLEMENTED;
1538 }
1539
1540 /* Class 37 - Registry Quota Information */
1541 QSI_DEF(SystemRegistryQuotaInformation)
1542 {
1543 PSYSTEM_REGISTRY_QUOTA_INFORMATION srqi = (PSYSTEM_REGISTRY_QUOTA_INFORMATION) Buffer;
1544
1545 *ReqSize = sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION);
1546 if (Size < sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION))
1547 {
1548 return STATUS_INFO_LENGTH_MISMATCH;
1549 }
1550
1551 DPRINT1("Faking max registry size of 32 MB\n");
1552 srqi->RegistryQuotaAllowed = 0x2000000;
1553 srqi->RegistryQuotaUsed = 0x200000;
1554 srqi->PagedPoolSize = 0x200000;
1555
1556 return STATUS_SUCCESS;
1557 }
1558
1559 SSI_DEF(SystemRegistryQuotaInformation)
1560 {
1561 /* FIXME */
1562 DPRINT1("NtSetSystemInformation - SystemRegistryQuotaInformation not implemented\n");
1563 return STATUS_NOT_IMPLEMENTED;
1564 }
1565
1566 /* Class 38 - Load And Call Image */
1567 SSI_DEF(SystemExtendServiceTableInformation)
1568 {
1569 UNICODE_STRING ImageName;
1570 KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
1571 PLDR_DATA_TABLE_ENTRY ModuleObject;
1572 NTSTATUS Status;
1573 PIMAGE_NT_HEADERS NtHeader;
1574 DRIVER_OBJECT Win32k;
1575 PDRIVER_INITIALIZE DriverInit;
1576 PVOID ImageBase;
1577 ULONG_PTR EntryPoint;
1578
1579 /* Validate the size */
1580 if (Size != sizeof(UNICODE_STRING)) return STATUS_INFO_LENGTH_MISMATCH;
1581
1582 /* Check who is calling */
1583 if (PreviousMode != KernelMode)
1584 {
1585 /* Make sure we can load drivers */
1586 if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege, UserMode))
1587 {
1588 /* FIXME: We can't, fail */
1589 //return STATUS_PRIVILEGE_NOT_HELD;
1590 }
1591 }
1592
1593 /* Probe and capture the driver name */
1594 ProbeAndCaptureUnicodeString(&ImageName, PreviousMode, Buffer);
1595
1596 /* Load the image */
1597 Status = MmLoadSystemImage(&ImageName,
1598 NULL,
1599 NULL,
1600 0,
1601 (PVOID)&ModuleObject,
1602 &ImageBase);
1603
1604 /* Release String */
1605 ReleaseCapturedUnicodeString(&ImageName, PreviousMode);
1606
1607 if (!NT_SUCCESS(Status)) return Status;
1608
1609 /* Get the headers */
1610 NtHeader = RtlImageNtHeader(ImageBase);
1611 if (!NtHeader)
1612 {
1613 /* Fail */
1614 MmUnloadSystemImage(ModuleObject);
1615 return STATUS_INVALID_IMAGE_FORMAT;
1616 }
1617
1618 /* Get the entrypoint */
1619 EntryPoint = NtHeader->OptionalHeader.AddressOfEntryPoint;
1620 EntryPoint += (ULONG_PTR)ImageBase;
1621 DriverInit = (PDRIVER_INITIALIZE)EntryPoint;
1622
1623 /* Create a dummy device */
1624 RtlZeroMemory(&Win32k, sizeof(Win32k));
1625 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
1626 Win32k.DriverStart = ImageBase;
1627
1628 /* Call it */
1629 Status = (DriverInit)(&Win32k, NULL);
1630 ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
1631
1632 /* Unload if we failed */
1633 if (!NT_SUCCESS(Status)) MmUnloadSystemImage(ModuleObject);
1634 return Status;
1635 }
1636
1637 /* Class 39 - Priority Separation */
1638 SSI_DEF(SystemPrioritySeperation)
1639 {
1640 /* FIXME */
1641 DPRINT1("NtSetSystemInformation - SystemPrioritySeperation not implemented\n");
1642 return STATUS_NOT_IMPLEMENTED;
1643 }
1644
1645 /* Class 40 - Plug Play Bus Information */
1646 QSI_DEF(SystemPlugPlayBusInformation)
1647 {
1648 /* FIXME */
1649 DPRINT1("NtQuerySystemInformation - SystemPlugPlayBusInformation not implemented\n");
1650 return STATUS_NOT_IMPLEMENTED;
1651 }
1652
1653 /* Class 41 - Dock Information */
1654 QSI_DEF(SystemDockInformation)
1655 {
1656 /* FIXME */
1657 DPRINT1("NtQuerySystemInformation - SystemDockInformation not implemented\n");
1658 return STATUS_NOT_IMPLEMENTED;
1659 }
1660
1661 /* Class 42 - Power Information */
1662 QSI_DEF(SystemPowerInformation)
1663 {
1664 /* FIXME */
1665 DPRINT1("NtQuerySystemInformation - SystemPowerInformation not implemented\n");
1666 return STATUS_NOT_IMPLEMENTED;
1667 }
1668
1669 /* Class 43 - Processor Speed Information */
1670 QSI_DEF(SystemProcessorSpeedInformation)
1671 {
1672 /* FIXME */
1673 DPRINT1("NtQuerySystemInformation - SystemProcessorSpeedInformation not implemented\n");
1674 return STATUS_NOT_IMPLEMENTED;
1675 }
1676
1677 /* Class 44 - Current Time Zone Information */
1678 QSI_DEF(SystemCurrentTimeZoneInformation)
1679 {
1680 *ReqSize = sizeof(TIME_ZONE_INFORMATION);
1681
1682 if (sizeof(TIME_ZONE_INFORMATION) != Size)
1683 {
1684 return STATUS_INFO_LENGTH_MISMATCH;
1685 }
1686
1687 /* Copy the time zone information struct */
1688 memcpy(Buffer,
1689 &ExpTimeZoneInfo,
1690 sizeof(TIME_ZONE_INFORMATION));
1691
1692 return STATUS_SUCCESS;
1693 }
1694
1695
1696 SSI_DEF(SystemCurrentTimeZoneInformation)
1697 {
1698 /* Check user buffer's size */
1699 if (Size < sizeof(TIME_ZONE_INFORMATION))
1700 {
1701 return STATUS_INFO_LENGTH_MISMATCH;
1702 }
1703
1704 return ExpSetTimeZoneInformation((PTIME_ZONE_INFORMATION)Buffer);
1705 }
1706
1707
1708 /* Class 45 - Lookaside Information */
1709 QSI_DEF(SystemLookasideInformation)
1710 {
1711 /* FIXME */
1712 DPRINT1("NtQuerySystemInformation - SystemLookasideInformation not implemented\n");
1713 return STATUS_NOT_IMPLEMENTED;
1714 }
1715
1716
1717 /* Class 46 - Set time slip event */
1718 SSI_DEF(SystemSetTimeSlipEvent)
1719 {
1720 /* FIXME */
1721 DPRINT1("NtSetSystemInformation - SystemSetTimSlipEvent not implemented\n");
1722 return STATUS_NOT_IMPLEMENTED;
1723 }
1724
1725
1726 /* Class 47 - Create a new session (TSE) */
1727 SSI_DEF(SystemCreateSession)
1728 {
1729 /* FIXME */
1730 DPRINT1("NtSetSystemInformation - SystemCreateSession not implemented\n");
1731 return STATUS_NOT_IMPLEMENTED;
1732 }
1733
1734
1735 /* Class 48 - Delete an existing session (TSE) */
1736 SSI_DEF(SystemDeleteSession)
1737 {
1738 /* FIXME */
1739 DPRINT1("NtSetSystemInformation - SystemDeleteSession not implemented\n");
1740 return STATUS_NOT_IMPLEMENTED;
1741 }
1742
1743
1744 /* Class 49 - UNKNOWN */
1745 QSI_DEF(SystemInvalidInfoClass4)
1746 {
1747 /* FIXME */
1748 DPRINT1("NtQuerySystemInformation - SystemInvalidInfoClass4 not implemented\n");
1749 return STATUS_NOT_IMPLEMENTED;
1750 }
1751
1752
1753 /* Class 50 - System range start address */
1754 QSI_DEF(SystemRangeStartInformation)
1755 {
1756 /* FIXME */
1757 DPRINT1("NtQuerySystemInformation - SystemRangeStartInformation not implemented\n");
1758 return STATUS_NOT_IMPLEMENTED;
1759 }
1760
1761
1762 /* Class 51 - Driver verifier information */
1763 QSI_DEF(SystemVerifierInformation)
1764 {
1765 /* FIXME */
1766 DPRINT1("NtQuerySystemInformation - SystemVerifierInformation not implemented\n");
1767 return STATUS_NOT_IMPLEMENTED;
1768 }
1769
1770
1771 SSI_DEF(SystemVerifierInformation)
1772 {
1773 /* FIXME */
1774 DPRINT1("NtSetSystemInformation - SystemVerifierInformation not implemented\n");
1775 return STATUS_NOT_IMPLEMENTED;
1776 }
1777
1778
1779 /* Class 52 - Add a driver verifier */
1780 SSI_DEF(SystemAddVerifier)
1781 {
1782 /* FIXME */
1783 DPRINT1("NtSetSystemInformation - SystemAddVerifier not implemented\n");
1784 return STATUS_NOT_IMPLEMENTED;
1785 }
1786
1787
1788 /* Class 53 - A session's processes */
1789 QSI_DEF(SystemSessionProcessesInformation)
1790 {
1791 /* FIXME */
1792 DPRINT1("NtQuerySystemInformation - SystemSessionProcessInformation not implemented\n");
1793 return STATUS_NOT_IMPLEMENTED;
1794 }
1795
1796
1797 /* Query/Set Calls Table */
1798 typedef
1799 struct _QSSI_CALLS
1800 {
1801 NTSTATUS (* Query) (PVOID,ULONG,PULONG);
1802 NTSTATUS (* Set) (PVOID,ULONG);
1803
1804 } QSSI_CALLS;
1805
1806 // QS Query & Set
1807 // QX Query
1808 // XS Set
1809 // XX unknown behaviour
1810 //
1811 #define SI_QS(n) {QSI_USE(n),SSI_USE(n)}
1812 #define SI_QX(n) {QSI_USE(n),NULL}
1813 #define SI_XS(n) {NULL,SSI_USE(n)}
1814 #define SI_XX(n) {NULL,NULL}
1815
1816 static
1817 QSSI_CALLS
1818 CallQS [] =
1819 {
1820 SI_QX(SystemBasicInformation),
1821 SI_QX(SystemProcessorInformation),
1822 SI_QX(SystemPerformanceInformation),
1823 SI_QX(SystemTimeOfDayInformation),
1824 SI_QX(SystemPathInformation), /* should be SI_XX */
1825 SI_QX(SystemProcessInformation),
1826 SI_QX(SystemCallCountInformation),
1827 SI_QX(SystemDeviceInformation),
1828 SI_QX(SystemProcessorPerformanceInformation),
1829 SI_QS(SystemFlagsInformation),
1830 SI_QX(SystemCallTimeInformation), /* should be SI_XX */
1831 SI_QX(SystemModuleInformation),
1832 SI_QX(SystemLocksInformation),
1833 SI_QX(SystemStackTraceInformation), /* should be SI_XX */
1834 SI_QX(SystemPagedPoolInformation), /* should be SI_XX */
1835 SI_QX(SystemNonPagedPoolInformation), /* should be SI_XX */
1836 SI_QX(SystemHandleInformation),
1837 SI_QX(SystemObjectInformation),
1838 SI_QX(SystemPageFileInformation),
1839 SI_QX(SystemVdmInstemulInformation),
1840 SI_QX(SystemVdmBopInformation), /* it should be SI_XX */
1841 SI_QS(SystemFileCacheInformation),
1842 SI_QX(SystemPoolTagInformation),
1843 SI_QX(SystemInterruptInformation),
1844 SI_QS(SystemDpcBehaviourInformation),
1845 SI_QX(SystemFullMemoryInformation), /* it should be SI_XX */
1846 SI_XS(SystemLoadGdiDriverInformation),
1847 SI_XS(SystemUnloadGdiDriverInformation),
1848 SI_QS(SystemTimeAdjustmentInformation),
1849 SI_QX(SystemSummaryMemoryInformation), /* it should be SI_XX */
1850 SI_QX(SystemNextEventIdInformation), /* it should be SI_XX */
1851 SI_QX(SystemEventIdsInformation), /* it should be SI_XX */
1852 SI_QX(SystemCrashDumpInformation),
1853 SI_QX(SystemExceptionInformation),
1854 SI_QX(SystemCrashDumpStateInformation),
1855 SI_QX(SystemKernelDebuggerInformation),
1856 SI_QX(SystemContextSwitchInformation),
1857 SI_QS(SystemRegistryQuotaInformation),
1858 SI_XS(SystemExtendServiceTableInformation),
1859 SI_XS(SystemPrioritySeperation),
1860 SI_QX(SystemPlugPlayBusInformation), /* it should be SI_XX */
1861 SI_QX(SystemDockInformation), /* it should be SI_XX */
1862 SI_QX(SystemPowerInformation), /* it should be SI_XX */
1863 SI_QX(SystemProcessorSpeedInformation), /* it should be SI_XX */
1864 SI_QS(SystemCurrentTimeZoneInformation), /* it should be SI_QX */
1865 SI_QX(SystemLookasideInformation),
1866 SI_XS(SystemSetTimeSlipEvent),
1867 SI_XS(SystemCreateSession),
1868 SI_XS(SystemDeleteSession),
1869 SI_QX(SystemInvalidInfoClass4), /* it should be SI_XX */
1870 SI_QX(SystemRangeStartInformation),
1871 SI_QS(SystemVerifierInformation),
1872 SI_XS(SystemAddVerifier),
1873 SI_QX(SystemSessionProcessesInformation)
1874 };
1875
1876 C_ASSERT(SystemBasicInformation == 0);
1877 #define MIN_SYSTEM_INFO_CLASS (SystemBasicInformation)
1878 #define MAX_SYSTEM_INFO_CLASS (sizeof(CallQS) / sizeof(CallQS[0]))
1879
1880 /*
1881 * @implemented
1882 */
1883 NTSTATUS NTAPI
1884 NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
1885 OUT PVOID SystemInformation,
1886 IN ULONG Length,
1887 OUT PULONG UnsafeResultLength)
1888 {
1889 KPROCESSOR_MODE PreviousMode;
1890 ULONG ResultLength;
1891 NTSTATUS FStatus = STATUS_NOT_IMPLEMENTED;
1892
1893 PAGED_CODE();
1894
1895 PreviousMode = ExGetPreviousMode();
1896
1897 _SEH2_TRY
1898 {
1899 if (PreviousMode != KernelMode)
1900 {
1901 /* SystemKernelDebuggerInformation needs only BOOLEAN alignment */
1902 ProbeForWrite(SystemInformation, Length, 1);
1903 if (UnsafeResultLength != NULL)
1904 ProbeForWriteUlong(UnsafeResultLength);
1905 }
1906
1907 /*
1908 * Check the request is valid.
1909 */
1910 if (SystemInformationClass >= MAX_SYSTEM_INFO_CLASS)
1911 {
1912 _SEH2_YIELD(return STATUS_INVALID_INFO_CLASS);
1913 }
1914
1915 if (NULL != CallQS [SystemInformationClass].Query)
1916 {
1917 /*
1918 * Hand the request to a subhandler.
1919 */
1920 FStatus = CallQS [SystemInformationClass].Query(SystemInformation,
1921 Length,
1922 &ResultLength);
1923 if (UnsafeResultLength != NULL)
1924 {
1925 if (PreviousMode != KernelMode)
1926 {
1927 *UnsafeResultLength = ResultLength;
1928 }
1929 else
1930 {
1931 *UnsafeResultLength = ResultLength;
1932 }
1933 }
1934 }
1935 }
1936 _SEH2_EXCEPT(ExSystemExceptionFilter())
1937 {
1938 FStatus = _SEH2_GetExceptionCode();
1939 }
1940 _SEH2_END;
1941
1942 return FStatus;
1943 }
1944
1945
1946 NTSTATUS
1947 NTAPI
1948 NtSetSystemInformation (IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
1949 IN PVOID SystemInformation,
1950 IN ULONG SystemInformationLength)
1951 {
1952 PAGED_CODE();
1953
1954 /*
1955 * If called from user mode, check
1956 * possible unsafe arguments.
1957 */
1958 #if 0
1959 if (KernelMode != KeGetPreviousMode())
1960 {
1961 // Check arguments
1962 //ProbeForWrite(
1963 // SystemInformation,
1964 // Length
1965 // );
1966 //ProbeForWrite(
1967 // ResultLength,
1968 // sizeof (ULONG)
1969 // );
1970 }
1971 #endif
1972 /*
1973 * Check the request is valid.
1974 */
1975 if ((SystemInformationClass >= MIN_SYSTEM_INFO_CLASS) &&
1976 (SystemInformationClass < MAX_SYSTEM_INFO_CLASS))
1977 {
1978 if (NULL != CallQS [SystemInformationClass].Set)
1979 {
1980 /*
1981 * Hand the request to a subhandler.
1982 */
1983 return CallQS [SystemInformationClass].Set(SystemInformation,
1984 SystemInformationLength);
1985 }
1986 }
1987
1988 return STATUS_INVALID_INFO_CLASS;
1989 }
1990
1991
1992 NTSTATUS
1993 NTAPI
1994 NtFlushInstructionCache(IN HANDLE ProcessHandle,
1995 IN PVOID BaseAddress,
1996 IN ULONG NumberOfBytesToFlush)
1997 {
1998 PAGED_CODE();
1999
2000 #if defined(_M_IX86)
2001 __wbinvd();
2002 #elif defined(_M_PPC)
2003 __asm__ __volatile__("tlbsync");
2004 #elif defined(_M_MIPS)
2005 DPRINT1("NtFlushInstructionCache() is not implemented\n");
2006 for (;;);
2007 #elif defined(_M_ARM)
2008 __asm__ __volatile__("mov r1, #0; mcr p15, 0, r1, c7, c5, 0");
2009 #else
2010 #error Unknown architecture
2011 #endif
2012 return STATUS_SUCCESS;
2013 }
2014
2015 ULONG
2016 NTAPI
2017 NtGetCurrentProcessorNumber(VOID)
2018 {
2019 /* Just return the CPU */
2020 return KeGetCurrentProcessorNumber();
2021 }
2022
2023 /* EOF */