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