b9dc72c3e8eaddf832313797e02aac131628d3c8
[reactos.git] / reactos / ntoskrnl / ex / sysinfo.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ex/sysinfo.c
6 * PURPOSE: System information functions
7 *
8 * PROGRAMMERS: David Welch (welch@mcmail.com)
9 * Aleksey Bragin (aleksey@studiocerebral.com)
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ntoskrnl.h>
15 #define NDEBUG
16 #include <internal/debug.h>
17
18 extern PEPROCESS PsIdleProcess;
19 extern ULONG NtGlobalFlag; /* FIXME: it should go in a ddk/?.h */
20 ULONGLONG STDCALL KeQueryInterruptTime(VOID);
21
22 VOID MmPrintMemoryStatistic(VOID);
23
24 /* FUNCTIONS *****************************************************************/
25
26 /*
27 * @unimplemented
28 */
29 VOID
30 STDCALL
31 ExEnumHandleTable (
32 PULONG HandleTable,
33 PVOID Callback,
34 PVOID Param,
35 PHANDLE Handle OPTIONAL
36 )
37 {
38 UNIMPLEMENTED;
39 }
40
41 /*
42 * @implemented
43 */
44 VOID
45 STDCALL
46 ExGetCurrentProcessorCpuUsage (
47 PULONG CpuUsage
48 )
49 {
50 PKPRCB Prcb;
51 ULONG TotalTime;
52 ULONGLONG ScaledIdle;
53
54 Prcb = KeGetCurrentPrcb();
55
56 ScaledIdle = Prcb->IdleThread->KernelTime * 100;
57 TotalTime = Prcb->KernelTime + Prcb->UserTime;
58 if (TotalTime != 0)
59 *CpuUsage = 100 - (ScaledIdle / TotalTime);
60 else
61 *CpuUsage = 0;
62 }
63
64 /*
65 * @implemented
66 */
67 VOID
68 STDCALL
69 ExGetCurrentProcessorCounts (
70 PULONG ThreadKernelTime,
71 PULONG TotalCpuTime,
72 PULONG ProcessorNumber
73 )
74 {
75 PKPRCB Prcb;
76
77 Prcb = KeGetCurrentPrcb();
78
79 *ThreadKernelTime = Prcb->KernelTime + Prcb->UserTime;
80 *TotalCpuTime = Prcb->CurrentThread->KernelTime;
81 *ProcessorNumber = KeGetCurrentProcessorNumber();
82 }
83
84 /*
85 * @implemented
86 */
87 BOOLEAN
88 STDCALL
89 ExIsProcessorFeaturePresent(IN ULONG ProcessorFeature)
90 {
91 /* Quick check to see if it exists at all */
92 if (ProcessorFeature >= PROCESSOR_FEATURE_MAX) return(FALSE);
93
94 /* Return our support for it */
95 return(SharedUserData->ProcessorFeatures[ProcessorFeature]);
96 }
97
98 /*
99 * @implemented
100 */
101 BOOLEAN
102 STDCALL
103 ExVerifySuite(SUITE_TYPE SuiteType)
104 {
105 if (SuiteType == Personal) return TRUE;
106 return FALSE;
107 }
108
109 NTSTATUS STDCALL
110 NtQuerySystemEnvironmentValue (IN PUNICODE_STRING VariableName,
111 OUT PWSTR ValueBuffer,
112 IN ULONG ValueBufferLength,
113 IN OUT PULONG ReturnLength OPTIONAL)
114 {
115 ANSI_STRING AName;
116 UNICODE_STRING WName;
117 BOOLEAN Result;
118 PCH Value;
119 ANSI_STRING AValue;
120 UNICODE_STRING WValue;
121 KPROCESSOR_MODE PreviousMode;
122 NTSTATUS Status = STATUS_SUCCESS;
123
124 PAGED_CODE();
125
126 PreviousMode = ExGetPreviousMode();
127
128 if(PreviousMode != KernelMode)
129 {
130 _SEH_TRY
131 {
132 ProbeForRead(VariableName,
133 sizeof(UNICODE_STRING),
134 sizeof(ULONG));
135 ProbeForWrite(ValueBuffer,
136 ValueBufferLength,
137 sizeof(WCHAR));
138 if(ReturnLength != NULL)
139 {
140 ProbeForWriteUlong(ReturnLength);
141 }
142 }
143 _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
144 {
145 Status = _SEH_GetExceptionCode();
146 }
147 _SEH_END;
148
149 if(!NT_SUCCESS(Status))
150 {
151 return Status;
152 }
153 }
154
155 /*
156 * Copy the name to kernel space if necessary and convert it to ANSI.
157 */
158 Status = ProbeAndCaptureUnicodeString(&WName,
159 PreviousMode,
160 VariableName);
161 if(NT_SUCCESS(Status))
162 {
163 /*
164 * according to ntinternals the SeSystemEnvironmentName privilege is required!
165 */
166 if(!SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege,
167 PreviousMode))
168 {
169 ReleaseCapturedUnicodeString(&WName,
170 PreviousMode);
171 DPRINT1("NtQuerySystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
172 return STATUS_PRIVILEGE_NOT_HELD;
173 }
174
175 /*
176 * convert the value name to ansi
177 */
178 Status = RtlUnicodeStringToAnsiString(&AName, &WName, TRUE);
179 ReleaseCapturedUnicodeString(&WName,
180 PreviousMode);
181 if(!NT_SUCCESS(Status))
182 {
183 return Status;
184 }
185
186 /*
187 * Create a temporary buffer for the value
188 */
189 Value = ExAllocatePool(NonPagedPool, ValueBufferLength);
190 if (Value == NULL)
191 {
192 RtlFreeAnsiString(&AName);
193 return STATUS_INSUFFICIENT_RESOURCES;
194 }
195
196 /*
197 * Get the environment variable
198 */
199 Result = HalGetEnvironmentVariable(AName.Buffer, ValueBufferLength, Value);
200 if(!Result)
201 {
202 RtlFreeAnsiString(&AName);
203 ExFreePool(Value);
204 return STATUS_UNSUCCESSFUL;
205 }
206
207 /*
208 * Convert the result to UNICODE, protect with SEH in case the value buffer
209 * isn't NULL-terminated!
210 */
211 _SEH_TRY
212 {
213 RtlInitAnsiString(&AValue, Value);
214 Status = RtlAnsiStringToUnicodeString(&WValue, &AValue, TRUE);
215 }
216 _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
217 {
218 Status = _SEH_GetExceptionCode();
219 }
220 _SEH_END;
221
222 if(NT_SUCCESS(Status))
223 {
224 /*
225 * Copy the result back to the caller.
226 */
227 _SEH_TRY
228 {
229 RtlCopyMemory(ValueBuffer, WValue.Buffer, WValue.Length);
230 ValueBuffer[WValue.Length / sizeof(WCHAR)] = L'\0';
231 if(ReturnLength != NULL)
232 {
233 *ReturnLength = WValue.Length + sizeof(WCHAR);
234 }
235
236 Status = STATUS_SUCCESS;
237 }
238 _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
239 {
240 Status = _SEH_GetExceptionCode();
241 }
242 _SEH_END;
243 }
244
245 /*
246 * Cleanup allocated resources.
247 */
248 RtlFreeAnsiString(&AName);
249 ExFreePool(Value);
250 }
251
252 return Status;
253 }
254
255
256 NTSTATUS STDCALL
257 NtSetSystemEnvironmentValue (IN PUNICODE_STRING VariableName,
258 IN PUNICODE_STRING Value)
259 {
260 UNICODE_STRING CapturedName, CapturedValue;
261 ANSI_STRING AName, AValue;
262 KPROCESSOR_MODE PreviousMode;
263 NTSTATUS Status;
264
265 PAGED_CODE();
266
267 PreviousMode = ExGetPreviousMode();
268
269 /*
270 * Copy the strings to kernel space if necessary
271 */
272 Status = ProbeAndCaptureUnicodeString(&CapturedName,
273 PreviousMode,
274 VariableName);
275 if(NT_SUCCESS(Status))
276 {
277 Status = ProbeAndCaptureUnicodeString(&CapturedValue,
278 PreviousMode,
279 Value);
280 if(NT_SUCCESS(Status))
281 {
282 /*
283 * according to ntinternals the SeSystemEnvironmentName privilege is required!
284 */
285 if(SeSinglePrivilegeCheck(SeSystemEnvironmentPrivilege,
286 PreviousMode))
287 {
288 /*
289 * convert the strings to ANSI
290 */
291 Status = RtlUnicodeStringToAnsiString(&AName,
292 &CapturedName,
293 TRUE);
294 if(NT_SUCCESS(Status))
295 {
296 Status = RtlUnicodeStringToAnsiString(&AValue,
297 &CapturedValue,
298 TRUE);
299 if(NT_SUCCESS(Status))
300 {
301 BOOLEAN Result = HalSetEnvironmentVariable(AName.Buffer,
302 AValue.Buffer);
303
304 Status = (Result ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
305 }
306 }
307 }
308 else
309 {
310 DPRINT1("NtSetSystemEnvironmentValue: Caller requires the SeSystemEnvironmentPrivilege privilege!\n");
311 Status = STATUS_PRIVILEGE_NOT_HELD;
312 }
313
314 ReleaseCapturedUnicodeString(&CapturedValue,
315 PreviousMode);
316 }
317
318 ReleaseCapturedUnicodeString(&CapturedName,
319 PreviousMode);
320 }
321
322 return Status;
323 }
324
325
326 /* --- Query/Set System Information --- */
327
328 /*
329 * NOTE: QSI_DEF(n) and SSI_DEF(n) define _cdecl function symbols
330 * so the stack is popped only in one place on x86 platform.
331 */
332 #define QSI_USE(n) QSI##n
333 #define QSI_DEF(n) \
334 static NTSTATUS QSI_USE(n) (PVOID Buffer, ULONG Size, PULONG ReqSize)
335
336 #define SSI_USE(n) SSI##n
337 #define SSI_DEF(n) \
338 static NTSTATUS SSI_USE(n) (PVOID Buffer, ULONG Size)
339
340
341 /* Class 0 - Basic Information */
342 QSI_DEF(SystemBasicInformation)
343 {
344 PSYSTEM_BASIC_INFORMATION Sbi
345 = (PSYSTEM_BASIC_INFORMATION) Buffer;
346
347 *ReqSize = sizeof (SYSTEM_BASIC_INFORMATION);
348 /*
349 * Check user buffer's size
350 */
351 if (Size != sizeof (SYSTEM_BASIC_INFORMATION))
352 {
353 return (STATUS_INFO_LENGTH_MISMATCH);
354 }
355 Sbi->Reserved = 0;
356 Sbi->TimerResolution = KeMaximumIncrement;
357 Sbi->PageSize = PAGE_SIZE;
358 Sbi->NumberOfPhysicalPages = MmStats.NrTotalPages;
359 Sbi->LowestPhysicalPageNumber = 0; /* FIXME */
360 Sbi->HighestPhysicalPageNumber = MmStats.NrTotalPages; /* FIXME */
361 Sbi->AllocationGranularity = MM_VIRTMEM_GRANULARITY; /* hard coded on Intel? */
362 Sbi->MinimumUserModeAddress = 0x10000; /* Top of 64k */
363 Sbi->MaximumUserModeAddress = (ULONG_PTR)MmHighestUserAddress;
364 Sbi->ActiveProcessorsAffinityMask = KeActiveProcessors;
365 Sbi->NumberOfProcessors = KeNumberProcessors;
366 return (STATUS_SUCCESS);
367 }
368
369 /* Class 1 - Processor Information */
370 QSI_DEF(SystemProcessorInformation)
371 {
372 PSYSTEM_PROCESSOR_INFORMATION Spi
373 = (PSYSTEM_PROCESSOR_INFORMATION) Buffer;
374 PKPRCB Prcb;
375 *ReqSize = sizeof (SYSTEM_PROCESSOR_INFORMATION);
376 /*
377 * Check user buffer's size
378 */
379 if (Size < sizeof (SYSTEM_PROCESSOR_INFORMATION))
380 {
381 return (STATUS_INFO_LENGTH_MISMATCH);
382 }
383 Prcb = KeGetCurrentPrcb();
384 Spi->ProcessorArchitecture = 0; /* Intel Processor */
385 Spi->ProcessorLevel = Prcb->CpuType;
386 Spi->ProcessorRevision = Prcb->CpuStep;
387 Spi->Reserved = 0;
388 Spi->ProcessorFeatureBits = Prcb->FeatureBits;
389
390 DPRINT("Arch %d Level %d Rev 0x%x\n", Spi->ProcessorArchitecture,
391 Spi->ProcessorLevel, Spi->ProcessorRevision);
392
393 return (STATUS_SUCCESS);
394 }
395
396 /* Class 2 - Performance Information */
397 QSI_DEF(SystemPerformanceInformation)
398 {
399 PSYSTEM_PERFORMANCE_INFORMATION Spi
400 = (PSYSTEM_PERFORMANCE_INFORMATION) Buffer;
401
402 PEPROCESS TheIdleProcess;
403
404 *ReqSize = sizeof (SYSTEM_PERFORMANCE_INFORMATION);
405 /*
406 * Check user buffer's size
407 */
408 if (Size < sizeof (SYSTEM_PERFORMANCE_INFORMATION))
409 {
410 return (STATUS_INFO_LENGTH_MISMATCH);
411 }
412
413 TheIdleProcess = PsIdleProcess;
414
415 Spi->IdleProcessTime.QuadPart = TheIdleProcess->Pcb.KernelTime * 100000LL;
416
417 Spi->IoReadTransferCount = IoReadTransferCount;
418 Spi->IoWriteTransferCount = IoWriteTransferCount;
419 Spi->IoOtherTransferCount = IoOtherTransferCount;
420 Spi->IoReadOperationCount = IoReadOperationCount;
421 Spi->IoWriteOperationCount = IoWriteOperationCount;
422 Spi->IoOtherOperationCount = IoOtherOperationCount;
423
424 Spi->AvailablePages = MmStats.NrFreePages;
425 /*
426 Add up all the used "Commitied" memory + pagefile.
427 Not sure this is right. 8^\
428 */
429 Spi->CommittedPages = MiMemoryConsumers[MC_PPOOL].PagesUsed +
430 MiMemoryConsumers[MC_NPPOOL].PagesUsed+
431 MiMemoryConsumers[MC_CACHE].PagesUsed+
432 MiMemoryConsumers[MC_USER].PagesUsed+
433 MiUsedSwapPages;
434 /*
435 Add up the full system total + pagefile.
436 All this make Taskmgr happy but not sure it is the right numbers.
437 This too, fixes some of GlobalMemoryStatusEx numbers.
438 */
439 Spi->CommitLimit = MmStats.NrTotalPages + MiFreeSwapPages +
440 MiUsedSwapPages;
441
442 Spi->PeakCommitment = 0; /* FIXME */
443 Spi->PageFaultCount = 0; /* FIXME */
444 Spi->CopyOnWriteCount = 0; /* FIXME */
445 Spi->TransitionCount = 0; /* FIXME */
446 Spi->CacheTransitionCount = 0; /* FIXME */
447 Spi->DemandZeroCount = 0; /* FIXME */
448 Spi->PageReadCount = 0; /* FIXME */
449 Spi->PageReadIoCount = 0; /* FIXME */
450 Spi->CacheReadCount = 0; /* FIXME */
451 Spi->CacheIoCount = 0; /* FIXME */
452 Spi->DirtyPagesWriteCount = 0; /* FIXME */
453 Spi->DirtyWriteIoCount = 0; /* FIXME */
454 Spi->MappedPagesWriteCount = 0; /* FIXME */
455 Spi->MappedWriteIoCount = 0; /* FIXME */
456
457 Spi->PagedPoolPages = MiMemoryConsumers[MC_PPOOL].PagesUsed;
458 Spi->PagedPoolAllocs = 0; /* FIXME */
459 Spi->PagedPoolFrees = 0; /* FIXME */
460 Spi->NonPagedPoolPages = MiMemoryConsumers[MC_NPPOOL].PagesUsed;
461 Spi->NonPagedPoolAllocs = 0; /* FIXME */
462 Spi->NonPagedPoolFrees = 0; /* FIXME */
463
464 Spi->FreeSystemPtes = 0; /* FIXME */
465
466 Spi->ResidentSystemCodePage = MmStats.NrSystemPages; /* FIXME */
467
468 Spi->TotalSystemDriverPages = 0; /* FIXME */
469 Spi->TotalSystemCodePages = 0; /* FIXME */
470 Spi->NonPagedPoolLookasideHits = 0; /* FIXME */
471 Spi->PagedPoolLookasideHits = 0; /* FIXME */
472 Spi->Spare3Count = 0; /* FIXME */
473
474 Spi->ResidentSystemCachePage = MiMemoryConsumers[MC_CACHE].PagesUsed;
475 Spi->ResidentPagedPoolPage = MmPagedPoolSize; /* FIXME */
476
477 Spi->ResidentSystemDriverPage = 0; /* FIXME */
478 Spi->CcFastReadNoWait = 0; /* FIXME */
479 Spi->CcFastReadWait = 0; /* FIXME */
480 Spi->CcFastReadResourceMiss = 0; /* FIXME */
481 Spi->CcFastReadNotPossible = 0; /* FIXME */
482
483 Spi->CcFastMdlReadNoWait = 0; /* FIXME */
484 Spi->CcFastMdlReadWait = 0; /* FIXME */
485 Spi->CcFastMdlReadResourceMiss = 0; /* FIXME */
486 Spi->CcFastMdlReadNotPossible = 0; /* FIXME */
487
488 Spi->CcMapDataNoWait = 0; /* FIXME */
489 Spi->CcMapDataWait = 0; /* FIXME */
490 Spi->CcMapDataNoWaitMiss = 0; /* FIXME */
491 Spi->CcMapDataWaitMiss = 0; /* FIXME */
492
493 Spi->CcPinMappedDataCount = 0; /* FIXME */
494 Spi->CcPinReadNoWait = 0; /* FIXME */
495 Spi->CcPinReadWait = 0; /* FIXME */
496 Spi->CcPinReadNoWaitMiss = 0; /* FIXME */
497 Spi->CcPinReadWaitMiss = 0; /* FIXME */
498 Spi->CcCopyReadNoWait = 0; /* FIXME */
499 Spi->CcCopyReadWait = 0; /* FIXME */
500 Spi->CcCopyReadNoWaitMiss = 0; /* FIXME */
501 Spi->CcCopyReadWaitMiss = 0; /* FIXME */
502
503 Spi->CcMdlReadNoWait = 0; /* FIXME */
504 Spi->CcMdlReadWait = 0; /* FIXME */
505 Spi->CcMdlReadNoWaitMiss = 0; /* FIXME */
506 Spi->CcMdlReadWaitMiss = 0; /* FIXME */
507 Spi->CcReadAheadIos = 0; /* FIXME */
508 Spi->CcLazyWriteIos = 0; /* FIXME */
509 Spi->CcLazyWritePages = 0; /* FIXME */
510 Spi->CcDataFlushes = 0; /* FIXME */
511 Spi->CcDataPages = 0; /* FIXME */
512 Spi->ContextSwitches = 0; /* FIXME */
513 Spi->FirstLevelTbFills = 0; /* FIXME */
514 Spi->SecondLevelTbFills = 0; /* FIXME */
515 Spi->SystemCalls = 0; /* FIXME */
516
517 return (STATUS_SUCCESS);
518 }
519
520 /* Class 3 - Time Of Day Information */
521 QSI_DEF(SystemTimeOfDayInformation)
522 {
523 PSYSTEM_TIMEOFDAY_INFORMATION Sti;
524 LARGE_INTEGER CurrentTime;
525
526 Sti = (PSYSTEM_TIMEOFDAY_INFORMATION)Buffer;
527 *ReqSize = sizeof (SYSTEM_TIMEOFDAY_INFORMATION);
528
529 /* Check user buffer's size */
530 if (Size != sizeof (SYSTEM_TIMEOFDAY_INFORMATION))
531 {
532 return STATUS_INFO_LENGTH_MISMATCH;
533 }
534
535 KeQuerySystemTime(&CurrentTime);
536
537 Sti->BootTime= SystemBootTime;
538 Sti->CurrentTime = CurrentTime;
539 Sti->TimeZoneBias.QuadPart = ExpTimeZoneBias.QuadPart;
540 Sti->TimeZoneId = ExpTimeZoneId;
541 Sti->Reserved = 0;
542
543 return STATUS_SUCCESS;
544 }
545
546 /* Class 4 - Path Information */
547 QSI_DEF(SystemPathInformation)
548 {
549 /* FIXME: QSI returns STATUS_BREAKPOINT. Why? */
550 DPRINT1("NtQuerySystemInformation - SystemPathInformation not implemented\n");
551
552 return (STATUS_BREAKPOINT);
553 }
554
555 /* Class 5 - Process Information */
556 QSI_DEF(SystemProcessInformation)
557 {
558 ULONG ovlSize = 0, nThreads;
559 PEPROCESS pr = NULL, syspr;
560 unsigned char *pCur;
561 NTSTATUS Status = STATUS_SUCCESS;
562
563 _SEH_TRY
564 {
565 /* scan the process list */
566
567 PSYSTEM_PROCESS_INFORMATION Spi
568 = (PSYSTEM_PROCESS_INFORMATION) Buffer;
569
570 *ReqSize = sizeof(SYSTEM_PROCESS_INFORMATION);
571
572 if (Size < sizeof(SYSTEM_PROCESS_INFORMATION))
573 {
574 return (STATUS_INFO_LENGTH_MISMATCH); // in case buffer size is too small
575 }
576
577 syspr = PsGetNextProcess(NULL);
578 pr = syspr;
579 pCur = (unsigned char *)Spi;
580
581 do
582 {
583 PSYSTEM_PROCESS_INFORMATION SpiCur;
584 int curSize;
585 ANSI_STRING imgName;
586 int inLen=32; // image name len in bytes
587 PLIST_ENTRY current_entry;
588 PETHREAD current;
589 PSYSTEM_THREAD_INFORMATION ThreadInfo;
590
591 SpiCur = (PSYSTEM_PROCESS_INFORMATION)pCur;
592
593 nThreads = 0;
594 current_entry = pr->ThreadListHead.Flink;
595 while (current_entry != &pr->ThreadListHead)
596 {
597 nThreads++;
598 current_entry = current_entry->Flink;
599 }
600
601 // size of the structure for every process
602 curSize = sizeof(SYSTEM_PROCESS_INFORMATION)+sizeof(SYSTEM_THREAD_INFORMATION)*nThreads;
603 ovlSize += curSize+inLen;
604
605 if (ovlSize > Size)
606 {
607 *ReqSize = ovlSize;
608 ObDereferenceObject(pr);
609
610 return (STATUS_INFO_LENGTH_MISMATCH); // in case buffer size is too small
611 }
612
613 // fill system information
614 SpiCur->NextEntryOffset = curSize+inLen; // relative offset to the beginnnig of the next structure
615 SpiCur->NumberOfThreads = nThreads;
616 SpiCur->CreateTime = pr->CreateTime;
617 SpiCur->UserTime.QuadPart = pr->Pcb.UserTime * 100000LL;
618 SpiCur->KernelTime.QuadPart = pr->Pcb.KernelTime * 100000LL;
619 SpiCur->ImageName.Length = strlen(pr->ImageFileName) * sizeof(WCHAR);
620 SpiCur->ImageName.MaximumLength = inLen;
621 SpiCur->ImageName.Buffer = (void*)(pCur+curSize);
622
623 // copy name to the end of the struct
624 if(pr != PsIdleProcess)
625 {
626 RtlInitAnsiString(&imgName, pr->ImageFileName);
627 RtlAnsiStringToUnicodeString(&SpiCur->ImageName, &imgName, FALSE);
628 }
629 else
630 {
631 RtlInitUnicodeString(&SpiCur->ImageName, NULL);
632 }
633
634 SpiCur->BasePriority = pr->Pcb.BasePriority;
635 SpiCur->UniqueProcessId = pr->UniqueProcessId;
636 SpiCur->InheritedFromUniqueProcessId = pr->InheritedFromUniqueProcessId;
637 SpiCur->HandleCount = (pr->ObjectTable ? ObpGetHandleCountByHandleTable(pr->ObjectTable) : 0);
638 SpiCur->PeakVirtualSize = pr->PeakVirtualSize;
639 SpiCur->VirtualSize = pr->VirtualSize;
640 SpiCur->PageFaultCount = pr->Vm.PageFaultCount;
641 SpiCur->PeakWorkingSetSize = pr->Vm.PeakWorkingSetSize;
642 SpiCur->WorkingSetSize = pr->Vm.WorkingSetSize;
643 SpiCur->QuotaPeakPagedPoolUsage = pr->QuotaPeak[0];
644 SpiCur->QuotaPagedPoolUsage = pr->QuotaUsage[0];
645 SpiCur->QuotaPeakNonPagedPoolUsage = pr->QuotaPeak[1];
646 SpiCur->QuotaNonPagedPoolUsage = pr->QuotaUsage[1];
647 SpiCur->PagefileUsage = pr->QuotaUsage[3];
648 SpiCur->PeakPagefileUsage = pr->QuotaPeak[3];
649 SpiCur->PrivatePageCount = pr->CommitCharge;
650 ThreadInfo = (PSYSTEM_THREAD_INFORMATION)(SpiCur + 1);
651
652 current_entry = pr->ThreadListHead.Flink;
653 while (current_entry != &pr->ThreadListHead)
654 {
655 current = CONTAINING_RECORD(current_entry, ETHREAD,
656 ThreadListEntry);
657
658
659 ThreadInfo->KernelTime.QuadPart = current->Tcb.KernelTime * 100000LL;
660 ThreadInfo->UserTime.QuadPart = current->Tcb.UserTime * 100000LL;
661 // SpiCur->TH[i].CreateTime = current->CreateTime;
662 ThreadInfo->WaitTime = current->Tcb.WaitTime;
663 ThreadInfo->StartAddress = (PVOID) current->StartAddress;
664 ThreadInfo->ClientId = current->Cid;
665 ThreadInfo->Priority = current->Tcb.Priority;
666 ThreadInfo->BasePriority = current->Tcb.BasePriority;
667 ThreadInfo->ContextSwitches = current->Tcb.ContextSwitches;
668 ThreadInfo->ThreadState = current->Tcb.State;
669 ThreadInfo->WaitReason = current->Tcb.WaitReason;
670 ThreadInfo++;
671 current_entry = current_entry->Flink;
672 }
673
674 pr = PsGetNextProcess(pr);
675 nThreads = 0;
676 if ((pr == syspr) || (pr == NULL))
677 {
678 SpiCur->NextEntryOffset = 0;
679 break;
680 }
681 else
682 pCur = pCur + curSize + inLen;
683 } while ((pr != syspr) && (pr != NULL));
684
685 if(pr != NULL)
686 ObDereferenceObject(pr);
687 Status = STATUS_SUCCESS;
688 }
689 _SEH_HANDLE
690 {
691 if(pr != NULL)
692 ObDereferenceObject(pr);
693 Status = _SEH_GetExceptionCode();
694 }
695 _SEH_END
696
697 *ReqSize = ovlSize;
698 return Status;
699 }
700
701 /* Class 6 - Call Count Information */
702 QSI_DEF(SystemCallCountInformation)
703 {
704 /* FIXME */
705 DPRINT1("NtQuerySystemInformation - SystemCallCountInformation not implemented\n");
706 return (STATUS_NOT_IMPLEMENTED);
707 }
708
709 /* Class 7 - Device Information */
710 QSI_DEF(SystemDeviceInformation)
711 {
712 PSYSTEM_DEVICE_INFORMATION Sdi
713 = (PSYSTEM_DEVICE_INFORMATION) Buffer;
714 PCONFIGURATION_INFORMATION ConfigInfo;
715
716 *ReqSize = sizeof (SYSTEM_DEVICE_INFORMATION);
717 /*
718 * Check user buffer's size
719 */
720 if (Size < sizeof (SYSTEM_DEVICE_INFORMATION))
721 {
722 return (STATUS_INFO_LENGTH_MISMATCH);
723 }
724
725 ConfigInfo = IoGetConfigurationInformation ();
726
727 Sdi->NumberOfDisks = ConfigInfo->DiskCount;
728 Sdi->NumberOfFloppies = ConfigInfo->FloppyCount;
729 Sdi->NumberOfCdRoms = ConfigInfo->CdRomCount;
730 Sdi->NumberOfTapes = ConfigInfo->TapeCount;
731 Sdi->NumberOfSerialPorts = ConfigInfo->SerialCount;
732 Sdi->NumberOfParallelPorts = ConfigInfo->ParallelCount;
733
734 return (STATUS_SUCCESS);
735 }
736
737 /* Class 8 - Processor Performance Information */
738 QSI_DEF(SystemProcessorPerformanceInformation)
739 {
740 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION Spi
741 = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) Buffer;
742
743 LONG i;
744 LARGE_INTEGER CurrentTime;
745 PKPRCB Prcb;
746
747 *ReqSize = KeNumberProcessors * sizeof (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
748 /*
749 * Check user buffer's size
750 */
751 if (Size < KeNumberProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION))
752 {
753 return (STATUS_INFO_LENGTH_MISMATCH);
754 }
755
756 CurrentTime.QuadPart = KeQueryInterruptTime();
757 Prcb = ((PKPCR)KPCR_BASE)->Prcb;
758 for (i = 0; i < KeNumberProcessors; i++)
759 {
760 Spi->IdleTime.QuadPart = (Prcb->IdleThread->KernelTime + Prcb->IdleThread->UserTime) * 100000LL; // IdleTime
761 Spi->KernelTime.QuadPart = Prcb->KernelTime * 100000LL; // KernelTime
762 Spi->UserTime.QuadPart = Prcb->UserTime * 100000LL;
763 Spi->DpcTime.QuadPart = Prcb->DpcTime * 100000LL;
764 Spi->InterruptTime.QuadPart = Prcb->InterruptTime * 100000LL;
765 Spi->InterruptCount = Prcb->InterruptCount; // Interrupt Count
766 Spi++;
767 Prcb = (PKPRCB)((ULONG_PTR)Prcb + PAGE_SIZE);
768 }
769
770 return (STATUS_SUCCESS);
771 }
772
773 /* Class 9 - Flags Information */
774 QSI_DEF(SystemFlagsInformation)
775 {
776 if (sizeof (SYSTEM_FLAGS_INFORMATION) != Size)
777 {
778 * ReqSize = sizeof (SYSTEM_FLAGS_INFORMATION);
779 return (STATUS_INFO_LENGTH_MISMATCH);
780 }
781 ((PSYSTEM_FLAGS_INFORMATION) Buffer)->Flags = NtGlobalFlag;
782 return (STATUS_SUCCESS);
783 }
784
785 SSI_DEF(SystemFlagsInformation)
786 {
787 if (sizeof (SYSTEM_FLAGS_INFORMATION) != Size)
788 {
789 return (STATUS_INFO_LENGTH_MISMATCH);
790 }
791 NtGlobalFlag = ((PSYSTEM_FLAGS_INFORMATION) Buffer)->Flags;
792 return (STATUS_SUCCESS);
793 }
794
795 /* Class 10 - Call Time Information */
796 QSI_DEF(SystemCallTimeInformation)
797 {
798 /* FIXME */
799 DPRINT1("NtQuerySystemInformation - SystemCallTimeInformation not implemented\n");
800 return (STATUS_NOT_IMPLEMENTED);
801 }
802
803 /* Class 11 - Module Information */
804 QSI_DEF(SystemModuleInformation)
805 {
806 return LdrpQueryModuleInformation(Buffer, Size, ReqSize);
807 }
808
809 /* Class 12 - Locks Information */
810 QSI_DEF(SystemLocksInformation)
811 {
812 /* FIXME */
813 DPRINT1("NtQuerySystemInformation - SystemLocksInformation not implemented\n");
814 return (STATUS_NOT_IMPLEMENTED);
815 }
816
817 /* Class 13 - Stack Trace Information */
818 QSI_DEF(SystemStackTraceInformation)
819 {
820 /* FIXME */
821 DPRINT1("NtQuerySystemInformation - SystemStackTraceInformation not implemented\n");
822 return (STATUS_NOT_IMPLEMENTED);
823 }
824
825 /* Class 14 - Paged Pool Information */
826 QSI_DEF(SystemPagedPoolInformation)
827 {
828 /* FIXME */
829 DPRINT1("NtQuerySystemInformation - SystemPagedPoolInformation not implemented\n");
830 return (STATUS_NOT_IMPLEMENTED);
831 }
832
833 /* Class 15 - Non Paged Pool Information */
834 QSI_DEF(SystemNonPagedPoolInformation)
835 {
836 /* FIXME */
837 DPRINT1("NtQuerySystemInformation - SystemNonPagedPoolInformation not implemented\n");
838 return (STATUS_NOT_IMPLEMENTED);
839 }
840
841
842 /* Class 16 - Handle Information */
843 QSI_DEF(SystemHandleInformation)
844 {
845 PEPROCESS pr, syspr;
846 ULONG curSize, i = 0;
847 ULONG hCount = 0;
848
849 PSYSTEM_HANDLE_INFORMATION Shi =
850 (PSYSTEM_HANDLE_INFORMATION) Buffer;
851
852 DPRINT("NtQuerySystemInformation - SystemHandleInformation\n");
853
854 if (Size < sizeof (SYSTEM_HANDLE_INFORMATION))
855 {
856 * ReqSize = sizeof (SYSTEM_HANDLE_INFORMATION);
857 return (STATUS_INFO_LENGTH_MISMATCH);
858 }
859
860 DPRINT("SystemHandleInformation 1\n");
861
862 /* First Calc Size from Count. */
863 syspr = PsGetNextProcess(NULL);
864 pr = syspr;
865
866 do
867 {
868 hCount = hCount + (pr->ObjectTable ? ObpGetHandleCountByHandleTable(pr->ObjectTable) : 0);
869 pr = PsGetNextProcess(pr);
870
871 if ((pr == syspr) || (pr == NULL))
872 break;
873 } while ((pr != syspr) && (pr != NULL));
874
875 if(pr != NULL)
876 {
877 ObDereferenceObject(pr);
878 }
879
880 DPRINT("SystemHandleInformation 2\n");
881
882 curSize = sizeof(SYSTEM_HANDLE_INFORMATION)+
883 ( (sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO) * hCount) -
884 (sizeof(SYSTEM_HANDLE_TABLE_ENTRY_INFO) ));
885
886 Shi->NumberOfHandles = hCount;
887
888 if (curSize > Size)
889 {
890 *ReqSize = curSize;
891 return (STATUS_INFO_LENGTH_MISMATCH);
892 }
893
894 DPRINT("SystemHandleInformation 3\n");
895
896 /* Now get Handles from all processs. */
897 syspr = PsGetNextProcess(NULL);
898 pr = syspr;
899
900 do
901 {
902 int Count = 0, HandleCount;
903
904 HandleCount = (pr->ObjectTable ? ObpGetHandleCountByHandleTable(pr->ObjectTable) : 0);
905
906 for (Count = 0; HandleCount > 0 ; HandleCount--)
907 {
908 Shi->Handles[i].UniqueProcessId = (ULONG)pr->UniqueProcessId;
909 Count++;
910 i++;
911 }
912
913 pr = PsGetNextProcess(pr);
914
915 if ((pr == syspr) || (pr == NULL))
916 break;
917 } while ((pr != syspr) && (pr != NULL));
918
919 if(pr != NULL)
920 {
921 ObDereferenceObject(pr);
922 }
923
924 DPRINT("SystemHandleInformation 4\n");
925 return (STATUS_SUCCESS);
926
927 }
928 /*
929 SSI_DEF(SystemHandleInformation)
930 {
931
932 return (STATUS_SUCCESS);
933 }
934 */
935
936 /* Class 17 - Information */
937 QSI_DEF(SystemObjectInformation)
938 {
939 /* FIXME */
940 DPRINT1("NtQuerySystemInformation - SystemObjectInformation not implemented\n");
941 return (STATUS_NOT_IMPLEMENTED);
942 }
943
944 /* Class 18 - Information */
945 QSI_DEF(SystemPageFileInformation)
946 {
947 UNICODE_STRING FileName; /* FIXME */
948 SYSTEM_PAGEFILE_INFORMATION *Spfi = (SYSTEM_PAGEFILE_INFORMATION *) Buffer;
949
950 if (Size < sizeof (SYSTEM_PAGEFILE_INFORMATION))
951 {
952 * ReqSize = sizeof (SYSTEM_PAGEFILE_INFORMATION);
953 return (STATUS_INFO_LENGTH_MISMATCH);
954 }
955
956 RtlInitUnicodeString(&FileName, NULL); /* FIXME */
957
958 /* FIXME */
959 Spfi->NextEntryOffset = 0;
960
961 Spfi->TotalSize = MiFreeSwapPages + MiUsedSwapPages;
962 Spfi->TotalInUse = MiUsedSwapPages;
963 Spfi->PeakUsage = MiUsedSwapPages; /* FIXME */
964 Spfi->PageFileName = FileName;
965 return (STATUS_SUCCESS);
966 }
967
968 /* Class 19 - Vdm Instemul Information */
969 QSI_DEF(SystemVdmInstemulInformation)
970 {
971 /* FIXME */
972 DPRINT1("NtQuerySystemInformation - SystemVdmInstemulInformation not implemented\n");
973 return (STATUS_NOT_IMPLEMENTED);
974 }
975
976 /* Class 20 - Vdm Bop Information */
977 QSI_DEF(SystemVdmBopInformation)
978 {
979 /* FIXME */
980 DPRINT1("NtQuerySystemInformation - SystemVdmBopInformation not implemented\n");
981 return (STATUS_NOT_IMPLEMENTED);
982 }
983
984 /* Class 21 - File Cache Information */
985 QSI_DEF(SystemFileCacheInformation)
986 {
987 SYSTEM_FILECACHE_INFORMATION *Sci = (SYSTEM_FILECACHE_INFORMATION *) Buffer;
988
989 if (Size < sizeof (SYSTEM_FILECACHE_INFORMATION))
990 {
991 * ReqSize = sizeof (SYSTEM_FILECACHE_INFORMATION);
992 return (STATUS_INFO_LENGTH_MISMATCH);
993 }
994
995 RtlZeroMemory(Sci, sizeof(SYSTEM_FILECACHE_INFORMATION));
996
997 /* Return the Byte size not the page size. */
998 Sci->CurrentSize =
999 MiMemoryConsumers[MC_CACHE].PagesUsed * PAGE_SIZE;
1000 Sci->PeakSize =
1001 MiMemoryConsumers[MC_CACHE].PagesUsed * PAGE_SIZE; /* FIXME */
1002
1003 Sci->PageFaultCount = 0; /* FIXME */
1004 Sci->MinimumWorkingSet = 0; /* FIXME */
1005 Sci->MaximumWorkingSet = 0; /* FIXME */
1006
1007 return (STATUS_SUCCESS);
1008 }
1009
1010 SSI_DEF(SystemFileCacheInformation)
1011 {
1012 if (Size < sizeof (SYSTEM_FILECACHE_INFORMATION))
1013 {
1014 return (STATUS_INFO_LENGTH_MISMATCH);
1015 }
1016 /* FIXME */
1017 DPRINT1("NtSetSystemInformation - SystemFileCacheInformation not implemented\n");
1018 return (STATUS_NOT_IMPLEMENTED);
1019 }
1020
1021 /* Class 22 - Pool Tag Information */
1022 QSI_DEF(SystemPoolTagInformation)
1023 {
1024 /* FIXME */
1025 DPRINT1("NtQuerySystemInformation - SystemPoolTagInformation not implemented\n");
1026 return (STATUS_NOT_IMPLEMENTED);
1027 }
1028
1029 /* Class 23 - Interrupt Information for all processors */
1030 QSI_DEF(SystemInterruptInformation)
1031 {
1032 PKPRCB Prcb;
1033 LONG i;
1034 ULONG ti;
1035 PSYSTEM_INTERRUPT_INFORMATION sii = (PSYSTEM_INTERRUPT_INFORMATION)Buffer;
1036
1037 if(Size < KeNumberProcessors * sizeof(SYSTEM_INTERRUPT_INFORMATION))
1038 {
1039 return (STATUS_INFO_LENGTH_MISMATCH);
1040 }
1041
1042 ti = KeQueryTimeIncrement();
1043
1044 Prcb = ((PKPCR)KPCR_BASE)->Prcb;
1045 for (i = 0; i < KeNumberProcessors; i++)
1046 {
1047 sii->ContextSwitches = Prcb->KeContextSwitches;
1048 sii->DpcCount = 0; /* FIXME */
1049 sii->DpcRate = 0; /* FIXME */
1050 sii->TimeIncrement = ti;
1051 sii->DpcBypassCount = 0; /* FIXME */
1052 sii->ApcBypassCount = 0; /* FIXME */
1053 sii++;
1054 Prcb = (PKPRCB)((ULONG_PTR)Prcb + PAGE_SIZE);
1055 }
1056
1057 return STATUS_SUCCESS;
1058 }
1059
1060 /* Class 24 - DPC Behaviour Information */
1061 QSI_DEF(SystemDpcBehaviourInformation)
1062 {
1063 /* FIXME */
1064 DPRINT1("NtQuerySystemInformation - SystemDpcBehaviourInformation not implemented\n");
1065 return (STATUS_NOT_IMPLEMENTED);
1066 }
1067
1068 SSI_DEF(SystemDpcBehaviourInformation)
1069 {
1070 /* FIXME */
1071 DPRINT1("NtSetSystemInformation - SystemDpcBehaviourInformation not implemented\n");
1072 return (STATUS_NOT_IMPLEMENTED);
1073 }
1074
1075 /* Class 25 - Full Memory Information */
1076 QSI_DEF(SystemFullMemoryInformation)
1077 {
1078 PULONG Spi = (PULONG) Buffer;
1079
1080 PEPROCESS TheIdleProcess;
1081
1082 * ReqSize = sizeof (ULONG);
1083
1084 if (sizeof (ULONG) != Size)
1085 {
1086 return (STATUS_INFO_LENGTH_MISMATCH);
1087 }
1088 DPRINT("SystemFullMemoryInformation\n");
1089
1090 TheIdleProcess = PsIdleProcess;
1091
1092 DPRINT("PID: %d, KernelTime: %u PFFree: %d PFUsed: %d\n",
1093 TheIdleProcess->UniqueProcessId,
1094 TheIdleProcess->Pcb.KernelTime,
1095 MiFreeSwapPages,
1096 MiUsedSwapPages);
1097
1098 #ifndef NDEBUG
1099 MmPrintMemoryStatistic();
1100 #endif
1101
1102 *Spi = MiMemoryConsumers[MC_USER].PagesUsed;
1103
1104 return (STATUS_SUCCESS);
1105 }
1106
1107 /* Class 26 - Load Image */
1108 SSI_DEF(SystemLoadImage)
1109 {
1110 PSYSTEM_GDI_DRIVER_INFORMATION Sli = (PSYSTEM_GDI_DRIVER_INFORMATION)Buffer;
1111
1112 if (sizeof(SYSTEM_GDI_DRIVER_INFORMATION) != Size)
1113 {
1114 return(STATUS_INFO_LENGTH_MISMATCH);
1115 }
1116
1117 return(LdrpLoadImage(&Sli->DriverName,
1118 &Sli->ImageAddress,
1119 &Sli->SectionPointer,
1120 &Sli->EntryPoint,
1121 (PVOID)&Sli->ExportSectionPointer));
1122 }
1123
1124 /* Class 27 - Unload Image */
1125 SSI_DEF(SystemUnloadImage)
1126 {
1127 PVOID Sui = (PVOID)Buffer;
1128
1129 if (sizeof(PVOID) != Size)
1130 {
1131 return(STATUS_INFO_LENGTH_MISMATCH);
1132 }
1133
1134 return(LdrpUnloadImage(Sui));
1135 }
1136
1137 /* Class 28 - Time Adjustment Information */
1138 QSI_DEF(SystemTimeAdjustmentInformation)
1139 {
1140 if (sizeof (SYSTEM_SET_TIME_ADJUST_INFORMATION) > Size)
1141 {
1142 * ReqSize = sizeof (SYSTEM_SET_TIME_ADJUST_INFORMATION);
1143 return (STATUS_INFO_LENGTH_MISMATCH);
1144 }
1145 /* FIXME: */
1146 DPRINT1("NtQuerySystemInformation - SystemTimeAdjustmentInformation not implemented\n");
1147 return (STATUS_NOT_IMPLEMENTED);
1148 }
1149
1150 SSI_DEF(SystemTimeAdjustmentInformation)
1151 {
1152 if (sizeof (SYSTEM_SET_TIME_ADJUST_INFORMATION) > Size)
1153 {
1154 return (STATUS_INFO_LENGTH_MISMATCH);
1155 }
1156 /* FIXME: */
1157 DPRINT1("NtSetSystemInformation - SystemTimeAdjustmentInformation not implemented\n");
1158 return (STATUS_NOT_IMPLEMENTED);
1159 }
1160
1161 /* Class 29 - Summary Memory Information */
1162 QSI_DEF(SystemSummaryMemoryInformation)
1163 {
1164 /* FIXME */
1165 DPRINT1("NtQuerySystemInformation - SystemSummaryMemoryInformation not implemented\n");
1166 return (STATUS_NOT_IMPLEMENTED);
1167 }
1168
1169 /* Class 30 - Next Event Id Information */
1170 QSI_DEF(SystemNextEventIdInformation)
1171 {
1172 /* FIXME */
1173 DPRINT1("NtQuerySystemInformation - SystemNextEventIdInformation not implemented\n");
1174 return (STATUS_NOT_IMPLEMENTED);
1175 }
1176
1177 /* Class 31 - Event Ids Information */
1178 QSI_DEF(SystemEventIdsInformation)
1179 {
1180 /* FIXME */
1181 DPRINT1("NtQuerySystemInformation - SystemEventIdsInformation not implemented\n");
1182 return (STATUS_NOT_IMPLEMENTED);
1183 }
1184
1185 /* Class 32 - Crash Dump Information */
1186 QSI_DEF(SystemCrashDumpInformation)
1187 {
1188 /* FIXME */
1189 DPRINT1("NtQuerySystemInformation - SystemCrashDumpInformation not implemented\n");
1190 return (STATUS_NOT_IMPLEMENTED);
1191 }
1192
1193 /* Class 33 - Exception Information */
1194 QSI_DEF(SystemExceptionInformation)
1195 {
1196 /* FIXME */
1197 DPRINT1("NtQuerySystemInformation - SystemExceptionInformation not implemented\n");
1198 return (STATUS_NOT_IMPLEMENTED);
1199 }
1200
1201 /* Class 34 - Crash Dump State Information */
1202 QSI_DEF(SystemCrashDumpStateInformation)
1203 {
1204 /* FIXME */
1205 DPRINT1("NtQuerySystemInformation - SystemCrashDumpStateInformation not implemented\n");
1206 return (STATUS_NOT_IMPLEMENTED);
1207 }
1208
1209 /* Class 35 - Kernel Debugger Information */
1210 QSI_DEF(SystemKernelDebuggerInformation)
1211 {
1212 PSYSTEM_KERNEL_DEBUGGER_INFORMATION skdi = (PSYSTEM_KERNEL_DEBUGGER_INFORMATION) Buffer;
1213
1214 *ReqSize = sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION);
1215 if (Size < sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION))
1216 {
1217 return STATUS_INFO_LENGTH_MISMATCH;
1218 }
1219
1220 skdi->KernelDebuggerEnabled = KD_DEBUGGER_ENABLED;
1221 skdi->KernelDebuggerNotPresent = KD_DEBUGGER_NOT_PRESENT;
1222
1223 return STATUS_SUCCESS;
1224 }
1225
1226 /* Class 36 - Context Switch Information */
1227 QSI_DEF(SystemContextSwitchInformation)
1228 {
1229 /* FIXME */
1230 DPRINT1("NtQuerySystemInformation - SystemContextSwitchInformation not implemented\n");
1231 return (STATUS_NOT_IMPLEMENTED);
1232 }
1233
1234 /* Class 37 - Registry Quota Information */
1235 QSI_DEF(SystemRegistryQuotaInformation)
1236 {
1237 PSYSTEM_REGISTRY_QUOTA_INFORMATION srqi = (PSYSTEM_REGISTRY_QUOTA_INFORMATION) Buffer;
1238
1239 *ReqSize = sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION);
1240 if (Size < sizeof(SYSTEM_REGISTRY_QUOTA_INFORMATION))
1241 {
1242 return STATUS_INFO_LENGTH_MISMATCH;
1243 }
1244
1245 DPRINT1("Faking max registry size of 32 MB\n");
1246 srqi->RegistryQuotaAllowed = 0x2000000;
1247 srqi->RegistryQuotaUsed = 0x200000;
1248 srqi->PagedPoolSize = 0x200000;
1249
1250 return STATUS_SUCCESS;
1251 }
1252
1253 SSI_DEF(SystemRegistryQuotaInformation)
1254 {
1255 /* FIXME */
1256 DPRINT1("NtSetSystemInformation - SystemRegistryQuotaInformation not implemented\n");
1257 return (STATUS_NOT_IMPLEMENTED);
1258 }
1259
1260 /* Class 38 - Load And Call Image */
1261 SSI_DEF(SystemLoadAndCallImage)
1262 {
1263 PUNICODE_STRING Slci = (PUNICODE_STRING)Buffer;
1264
1265 if (sizeof(UNICODE_STRING) != Size)
1266 {
1267 return(STATUS_INFO_LENGTH_MISMATCH);
1268 }
1269
1270 return(LdrpLoadAndCallImage(Slci));
1271 }
1272
1273 /* Class 39 - Priority Separation */
1274 SSI_DEF(SystemPrioritySeperation)
1275 {
1276 /* FIXME */
1277 DPRINT1("NtSetSystemInformation - SystemPrioritySeperation not implemented\n");
1278 return (STATUS_NOT_IMPLEMENTED);
1279 }
1280
1281 /* Class 40 - Plug Play Bus Information */
1282 QSI_DEF(SystemPlugPlayBusInformation)
1283 {
1284 /* FIXME */
1285 DPRINT1("NtQuerySystemInformation - SystemPlugPlayBusInformation not implemented\n");
1286 return (STATUS_NOT_IMPLEMENTED);
1287 }
1288
1289 /* Class 41 - Dock Information */
1290 QSI_DEF(SystemDockInformation)
1291 {
1292 /* FIXME */
1293 DPRINT1("NtQuerySystemInformation - SystemDockInformation not implemented\n");
1294 return (STATUS_NOT_IMPLEMENTED);
1295 }
1296
1297 /* Class 42 - Power Information */
1298 QSI_DEF(SystemPowerInformation)
1299 {
1300 /* FIXME */
1301 DPRINT1("NtQuerySystemInformation - SystemPowerInformation not implemented\n");
1302 return (STATUS_NOT_IMPLEMENTED);
1303 }
1304
1305 /* Class 43 - Processor Speed Information */
1306 QSI_DEF(SystemProcessorSpeedInformation)
1307 {
1308 /* FIXME */
1309 DPRINT1("NtQuerySystemInformation - SystemProcessorSpeedInformation not implemented\n");
1310 return (STATUS_NOT_IMPLEMENTED);
1311 }
1312
1313 /* Class 44 - Current Time Zone Information */
1314 QSI_DEF(SystemCurrentTimeZoneInformation)
1315 {
1316 * ReqSize = sizeof (TIME_ZONE_INFORMATION);
1317
1318 if (sizeof (TIME_ZONE_INFORMATION) != Size)
1319 {
1320 return STATUS_INFO_LENGTH_MISMATCH;
1321 }
1322
1323 /* Copy the time zone information struct */
1324 memcpy(Buffer,
1325 &ExpTimeZoneInfo,
1326 sizeof(TIME_ZONE_INFORMATION));
1327
1328 return STATUS_SUCCESS;
1329 }
1330
1331
1332 SSI_DEF(SystemCurrentTimeZoneInformation)
1333 {
1334 /* Check user buffer's size */
1335 if (Size < sizeof (TIME_ZONE_INFORMATION))
1336 {
1337 return STATUS_INFO_LENGTH_MISMATCH;
1338 }
1339
1340 return ExpSetTimeZoneInformation((PTIME_ZONE_INFORMATION)Buffer);
1341 }
1342
1343
1344 /* Class 45 - Lookaside Information */
1345 QSI_DEF(SystemLookasideInformation)
1346 {
1347 /* FIXME */
1348 DPRINT1("NtQuerySystemInformation - SystemLookasideInformation not implemented\n");
1349 return (STATUS_NOT_IMPLEMENTED);
1350 }
1351
1352
1353 /* Class 46 - Set time slip event */
1354 SSI_DEF(SystemSetTimeSlipEvent)
1355 {
1356 /* FIXME */
1357 DPRINT1("NtSetSystemInformation - SystemSetTimSlipEvent not implemented\n");
1358 return (STATUS_NOT_IMPLEMENTED);
1359 }
1360
1361
1362 /* Class 47 - Create a new session (TSE) */
1363 SSI_DEF(SystemCreateSession)
1364 {
1365 /* FIXME */
1366 DPRINT1("NtSetSystemInformation - SystemCreateSession not implemented\n");
1367 return (STATUS_NOT_IMPLEMENTED);
1368 }
1369
1370
1371 /* Class 48 - Delete an existing session (TSE) */
1372 SSI_DEF(SystemDeleteSession)
1373 {
1374 /* FIXME */
1375 DPRINT1("NtSetSystemInformation - SystemDeleteSession not implemented\n");
1376 return (STATUS_NOT_IMPLEMENTED);
1377 }
1378
1379
1380 /* Class 49 - UNKNOWN */
1381 QSI_DEF(SystemInvalidInfoClass4)
1382 {
1383 /* FIXME */
1384 DPRINT1("NtQuerySystemInformation - SystemInvalidInfoClass4 not implemented\n");
1385 return (STATUS_NOT_IMPLEMENTED);
1386 }
1387
1388
1389 /* Class 50 - System range start address */
1390 QSI_DEF(SystemRangeStartInformation)
1391 {
1392 /* FIXME */
1393 DPRINT1("NtQuerySystemInformation - SystemRangeStartInformation not implemented\n");
1394 return (STATUS_NOT_IMPLEMENTED);
1395 }
1396
1397
1398 /* Class 51 - Driver verifier information */
1399 QSI_DEF(SystemVerifierInformation)
1400 {
1401 /* FIXME */
1402 DPRINT1("NtQuerySystemInformation - SystemVerifierInformation not implemented\n");
1403 return (STATUS_NOT_IMPLEMENTED);
1404 }
1405
1406
1407 SSI_DEF(SystemVerifierInformation)
1408 {
1409 /* FIXME */
1410 DPRINT1("NtSetSystemInformation - SystemVerifierInformation not implemented\n");
1411 return (STATUS_NOT_IMPLEMENTED);
1412 }
1413
1414
1415 /* Class 52 - Add a driver verifier */
1416 SSI_DEF(SystemAddVerifier)
1417 {
1418 /* FIXME */
1419 DPRINT1("NtSetSystemInformation - SystemAddVerifier not implemented\n");
1420 return (STATUS_NOT_IMPLEMENTED);
1421 }
1422
1423
1424 /* Class 53 - A session's processes */
1425 QSI_DEF(SystemSessionProcessesInformation)
1426 {
1427 /* FIXME */
1428 DPRINT1("NtQuerySystemInformation - SystemSessionProcessInformation not implemented\n");
1429 return (STATUS_NOT_IMPLEMENTED);
1430 }
1431
1432
1433 /* Query/Set Calls Table */
1434 typedef
1435 struct _QSSI_CALLS
1436 {
1437 NTSTATUS (* Query) (PVOID,ULONG,PULONG);
1438 NTSTATUS (* Set) (PVOID,ULONG);
1439
1440 } QSSI_CALLS;
1441
1442 // QS Query & Set
1443 // QX Query
1444 // XS Set
1445 // XX unknown behaviour
1446 //
1447 #define SI_QS(n) {QSI_USE(n),SSI_USE(n)}
1448 #define SI_QX(n) {QSI_USE(n),NULL}
1449 #define SI_XS(n) {NULL,SSI_USE(n)}
1450 #define SI_XX(n) {NULL,NULL}
1451
1452 static
1453 QSSI_CALLS
1454 CallQS [] =
1455 {
1456 SI_QX(SystemBasicInformation),
1457 SI_QX(SystemProcessorInformation),
1458 SI_QX(SystemPerformanceInformation),
1459 SI_QX(SystemTimeOfDayInformation),
1460 SI_QX(SystemPathInformation), /* should be SI_XX */
1461 SI_QX(SystemProcessInformation),
1462 SI_QX(SystemCallCountInformation),
1463 SI_QX(SystemDeviceInformation),
1464 SI_QX(SystemProcessorPerformanceInformation),
1465 SI_QS(SystemFlagsInformation),
1466 SI_QX(SystemCallTimeInformation), /* should be SI_XX */
1467 SI_QX(SystemModuleInformation),
1468 SI_QX(SystemLocksInformation),
1469 SI_QX(SystemStackTraceInformation), /* should be SI_XX */
1470 SI_QX(SystemPagedPoolInformation), /* should be SI_XX */
1471 SI_QX(SystemNonPagedPoolInformation), /* should be SI_XX */
1472 SI_QX(SystemHandleInformation),
1473 SI_QX(SystemObjectInformation),
1474 SI_QX(SystemPageFileInformation),
1475 SI_QX(SystemVdmInstemulInformation),
1476 SI_QX(SystemVdmBopInformation), /* it should be SI_XX */
1477 SI_QS(SystemFileCacheInformation),
1478 SI_QX(SystemPoolTagInformation),
1479 SI_QX(SystemInterruptInformation),
1480 SI_QS(SystemDpcBehaviourInformation),
1481 SI_QX(SystemFullMemoryInformation), /* it should be SI_XX */
1482 SI_XS(SystemLoadImage),
1483 SI_XS(SystemUnloadImage),
1484 SI_QS(SystemTimeAdjustmentInformation),
1485 SI_QX(SystemSummaryMemoryInformation), /* it should be SI_XX */
1486 SI_QX(SystemNextEventIdInformation), /* it should be SI_XX */
1487 SI_QX(SystemEventIdsInformation), /* it should be SI_XX */
1488 SI_QX(SystemCrashDumpInformation),
1489 SI_QX(SystemExceptionInformation),
1490 SI_QX(SystemCrashDumpStateInformation),
1491 SI_QX(SystemKernelDebuggerInformation),
1492 SI_QX(SystemContextSwitchInformation),
1493 SI_QS(SystemRegistryQuotaInformation),
1494 SI_XS(SystemLoadAndCallImage),
1495 SI_XS(SystemPrioritySeperation),
1496 SI_QX(SystemPlugPlayBusInformation), /* it should be SI_XX */
1497 SI_QX(SystemDockInformation), /* it should be SI_XX */
1498 SI_QX(SystemPowerInformation), /* it should be SI_XX */
1499 SI_QX(SystemProcessorSpeedInformation), /* it should be SI_XX */
1500 SI_QS(SystemCurrentTimeZoneInformation), /* it should be SI_QX */
1501 SI_QX(SystemLookasideInformation),
1502 SI_XS(SystemSetTimeSlipEvent),
1503 SI_XS(SystemCreateSession),
1504 SI_XS(SystemDeleteSession),
1505 SI_QX(SystemInvalidInfoClass4), /* it should be SI_XX */
1506 SI_QX(SystemRangeStartInformation),
1507 SI_QS(SystemVerifierInformation),
1508 SI_XS(SystemAddVerifier),
1509 SI_QX(SystemSessionProcessesInformation)
1510 };
1511
1512
1513 /*
1514 * @implemented
1515 */
1516 NTSTATUS STDCALL
1517 NtQuerySystemInformation (IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
1518 OUT PVOID SystemInformation,
1519 IN ULONG Length,
1520 OUT PULONG UnsafeResultLength)
1521 {
1522 KPROCESSOR_MODE PreviousMode;
1523 ULONG ResultLength;
1524 NTSTATUS FStatus = STATUS_NOT_IMPLEMENTED;
1525
1526 PAGED_CODE();
1527
1528 PreviousMode = ExGetPreviousMode();
1529
1530 _SEH_TRY
1531 {
1532 if (PreviousMode != KernelMode)
1533 {
1534 /* SystemKernelDebuggerInformation needs only BOOLEAN alignment */
1535 ProbeForWrite(SystemInformation, Length, 1);
1536 if (UnsafeResultLength != NULL)
1537 ProbeForWriteUlong(UnsafeResultLength);
1538 }
1539
1540 /* Clear user buffer. */
1541 RtlZeroMemory(SystemInformation, Length);
1542
1543 /*
1544 * Check the request is valid.
1545 */
1546 if (SystemInformationClass >= MaxSystemInfoClass)
1547 {
1548 return (STATUS_INVALID_INFO_CLASS);
1549 }
1550
1551 if (NULL != CallQS [SystemInformationClass].Query)
1552 {
1553 /*
1554 * Hand the request to a subhandler.
1555 */
1556 FStatus = CallQS [SystemInformationClass].Query(SystemInformation,
1557 Length,
1558 &ResultLength);
1559 if (UnsafeResultLength != NULL)
1560 {
1561 if (PreviousMode != KernelMode)
1562 {
1563 _SEH_TRY
1564 {
1565 *UnsafeResultLength = ResultLength;
1566 }
1567 _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
1568 {
1569 FStatus = _SEH_GetExceptionCode();
1570 }
1571 _SEH_END;
1572 }
1573 else
1574 {
1575 *UnsafeResultLength = ResultLength;
1576 }
1577 }
1578 }
1579 }
1580 _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
1581 {
1582 FStatus = _SEH_GetExceptionCode();
1583 }
1584 _SEH_END;
1585
1586 return (FStatus);
1587 }
1588
1589
1590 NTSTATUS
1591 STDCALL
1592 NtSetSystemInformation (
1593 IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
1594 IN PVOID SystemInformation,
1595 IN ULONG SystemInformationLength
1596 )
1597 {
1598 PAGED_CODE();
1599
1600 /*
1601 * If called from user mode, check
1602 * possible unsafe arguments.
1603 */
1604 #if 0
1605 if (KernelMode != KeGetPreviousMode())
1606 {
1607 // Check arguments
1608 //ProbeForWrite(
1609 // SystemInformation,
1610 // Length
1611 // );
1612 //ProbeForWrite(
1613 // ResultLength,
1614 // sizeof (ULONG)
1615 // );
1616 }
1617 #endif
1618 /*
1619 * Check the request is valid.
1620 */
1621 if ( (SystemInformationClass >= SystemBasicInformation)
1622 && (SystemInformationClass < MaxSystemInfoClass)
1623 )
1624 {
1625 if (NULL != CallQS [SystemInformationClass].Set)
1626 {
1627 /*
1628 * Hand the request to a subhandler.
1629 */
1630 return CallQS [SystemInformationClass].Set (
1631 SystemInformation,
1632 SystemInformationLength
1633 );
1634 }
1635 }
1636 return (STATUS_INVALID_INFO_CLASS);
1637 }
1638
1639
1640 NTSTATUS
1641 STDCALL
1642 NtFlushInstructionCache (
1643 IN HANDLE ProcessHandle,
1644 IN PVOID BaseAddress,
1645 IN ULONG NumberOfBytesToFlush
1646 )
1647 {
1648 PAGED_CODE();
1649
1650 __asm__("wbinvd\n");
1651 return STATUS_SUCCESS;
1652 }
1653
1654
1655 /* EOF */