ReactOS  0.4.13-dev-39-g8b6696f
power.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Kernel
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: ntoskrnl/po/power.c
5  * PURPOSE: Power Manager
6  * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7  * Hervé Poussineau (hpoussin@reactos.com)
8  */
9 
10 /* INCLUDES ******************************************************************/
11 
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* GLOBALS *******************************************************************/
17 
19 {
24 
30 
31 /* PRIVATE FUNCTIONS *********************************************************/
32 
33 static
35 NTAPI
37  IN PIRP Irp,
39 {
40  PIO_STACK_LOCATION Stack;
43 
46 
47  PowerState.DeviceState = (ULONG_PTR)Stack->Parameters.Others.Argument3;
48  CompletionRoutine(Stack->Parameters.Others.Argument1,
49  (UCHAR)(ULONG_PTR)Stack->Parameters.Others.Argument2,
50  PowerState,
51  Stack->Parameters.Others.Argument4,
52  &Irp->IoStatus);
53 
55  IoFreeIrp(Irp);
57 
59 }
60 
61 VOID
62 NTAPI
64 {
65  //UNIMPLEMENTED;
66 }
67 
70 {
71  KEVENT Event;
74  PIRP Irp;
76 
79  FALSE);
80 
83  NULL,
84  0,
85  NULL,
86  &Event,
87  &IoStatusBlock);
89 
92  IrpSp->Parameters.Power.Type = SystemPowerState;
93  IrpSp->Parameters.Power.State.SystemState = SystemState;
94  IrpSp->Parameters.Power.ShutdownType = PowerAction;
95 
97  if (Status == STATUS_PENDING)
98  {
100  Executive,
101  KernelMode,
102  FALSE,
103  NULL);
105  }
106 
107  return Status;
108 }
109 
110 NTSTATUS
112 {
113  KEVENT Event;
116  PIRP Irp;
118 
121  FALSE);
122 
124  DeviceObject,
125  NULL,
126  0,
127  NULL,
128  &Event,
129  &IoStatusBlock);
130  if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
131 
134  IrpSp->Parameters.Power.Type = SystemPowerState;
135  IrpSp->Parameters.Power.State.SystemState = SystemState;
136  IrpSp->Parameters.Power.ShutdownType = PowerAction;
137 
139  if (Status == STATUS_PENDING)
140  {
142  Executive,
143  KernelMode,
144  FALSE,
145  NULL);
147  }
148 
149  return Status;
150 }
151 
152 NTSTATUS
154  PVOID Context)
155 {
156  PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
157  PDEVICE_OBJECT TopDeviceObject;
159 
160  DPRINT("PopQuerySystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
161 
163  return STATUS_SUCCESS;
164 
165  if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
166  return STATUS_SUCCESS;
167 
168  TopDeviceObject = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
169 
170  Status = PopSendQuerySystemPowerState(TopDeviceObject,
171  PowerStateContext->SystemPowerState,
172  PowerStateContext->PowerAction);
173  if (!NT_SUCCESS(Status))
174  {
175  DPRINT1("Device '%wZ' failed IRP_MN_QUERY_POWER\n", &DeviceNode->InstancePath);
176  }
177  ObDereferenceObject(TopDeviceObject);
178 
179 #if 0
180  return Status;
181 #else
182  return STATUS_SUCCESS;
183 #endif
184 }
185 
186 NTSTATUS
188  PVOID Context)
189 {
190  PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
191  PDEVICE_OBJECT TopDeviceObject;
193 
194  DPRINT("PopSetSystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
195 
197  return STATUS_SUCCESS;
198 
199  if (DeviceNode->PhysicalDeviceObject == PowerStateContext->PowerDevice)
200  return STATUS_SUCCESS;
201 
202  if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
203  return STATUS_SUCCESS;
204 
205  TopDeviceObject = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
206  if (TopDeviceObject == PowerStateContext->PowerDevice)
207  {
208  ObDereferenceObject(TopDeviceObject);
209  return STATUS_SUCCESS;
210  }
211 
212  Status = PopSendSetSystemPowerState(TopDeviceObject,
213  PowerStateContext->SystemPowerState,
214  PowerStateContext->PowerAction);
215  if (!NT_SUCCESS(Status))
216  {
217  DPRINT1("Device '%wZ' failed IRP_MN_SET_POWER\n", &DeviceNode->InstancePath);
218  }
219 
220  ObDereferenceObject(TopDeviceObject);
221 
222 #if 0
223  return Status;
224 #else
225  return STATUS_SUCCESS;
226 #endif
227 }
228 
229 NTSTATUS
230 NTAPI
232 {
234  PDEVICE_OBJECT Fdo;
237  POWER_STATE_TRAVERSE_CONTEXT PowerContext;
238 
240  if (!NT_SUCCESS(Status))
241  {
242  DPRINT1("No system power driver available\n");
243  Fdo = NULL;
244  }
245  else
246  {
248  if (Fdo == DeviceObject)
249  {
250  DPRINT("An FDO was not attached\n");
251  return STATUS_UNSUCCESSFUL;
252  }
253  }
254 
255  /* Set up context */
256  PowerContext.PowerAction = PowerAction;
257  PowerContext.SystemPowerState = PowerState;
258  PowerContext.PowerDevice = Fdo;
259 
260  /* Query for system power change */
264  &PowerContext);
265 
267  if (!NT_SUCCESS(Status))
268  {
269  DPRINT1("Query system power state failed; changing state anyway\n");
270  }
271 
272  /* Set system power change */
276  &PowerContext);
277 
279 
281 
282  if (Fdo != NULL)
283  {
284  if (PowerAction != PowerActionShutdownReset)
285  PopSendSetSystemPowerState(Fdo, PowerState, PowerAction);
286 
287  ObDereferenceObject(Fdo);
288  }
289 
290  return Status;
291 }
292 
293 INIT_FUNCTION
294 BOOLEAN
295 NTAPI
297 {
299  PCHAR CommandLine;
300  BOOLEAN ForceAcpiDisable = FALSE;
301 
302  /* Check if this is phase 1 init */
303  if (BootPhase == 1)
304  {
305  /* Register power button notification */
308  (PVOID)&GUID_DEVICE_SYS_BUTTON,
310  PhysicalDeviceObject->DriverObject,
312  NULL,
314 
315  /* Register lid notification */
318  (PVOID)&GUID_DEVICE_LID,
320  PhysicalDeviceObject->DriverObject,
322  NULL,
324  return TRUE;
325  }
326 
327  /* Initialize the power capabilities */
329 
330  /* Get the Command Line */
331  CommandLine = KeLoaderBlock->LoadOptions;
332 
333  /* Upcase it */
334  _strupr(CommandLine);
335 
336  /* Check for ACPI disable */
337  if (strstr(CommandLine, "NOACPI")) ForceAcpiDisable = TRUE;
338 
339  if (ForceAcpiDisable)
340  {
341  /* Set the ACPI State to False if it's been forced that way */
343  }
344  else
345  {
346  /* Otherwise check if the LoaderBlock has a ACPI Table */
348  }
349 
350  /* Enable shutdown by power button */
351  if (PopAcpiPresent)
353 
354  /* Initialize volume support */
357 
358  /* Initialize support for dope */
360 
361  /* Initialize support for shutdown waits and work-items */
363 
364  return TRUE;
365 }
366 
367 VOID
368 NTAPI
370 {
371  DPRINT1("PerfIdle function: %p\n", PowerState);
372 }
373 
374 VOID
375 NTAPI
380 {
381  /* Call the Perf Idle function */
383 }
384 
385 VOID
386 FASTCALL
388 {
389  /* FIXME: Extremly naive implementation */
391 }
392 
393 INIT_FUNCTION
394 VOID
395 NTAPI
397 {
398  /* Initialize the Power State */
399  RtlZeroMemory(&Prcb->PowerState, sizeof(Prcb->PowerState));
400  Prcb->PowerState.Idle0KernelTimeLimit = 0xFFFFFFFF;
401  Prcb->PowerState.CurrentThrottle = 100;
402  Prcb->PowerState.CurrentThrottleIndex = 0;
403  Prcb->PowerState.IdleFunction = PopIdle0;
404 
405  /* Initialize the Perf DPC and Timer */
406  KeInitializeDpc(&Prcb->PowerState.PerfDpc, PopPerfIdleDpc, Prcb);
407  KeSetTargetProcessorDpc(&Prcb->PowerState.PerfDpc, Prcb->Number);
408  KeInitializeTimerEx(&Prcb->PowerState.PerfTimer, SynchronizationTimer);
409 }
410 
411 /* PUBLIC FUNCTIONS **********************************************************/
412 
413 /*
414  * @unimplemented
415  */
416 NTSTATUS
417 NTAPI
419 {
421  return STATUS_NOT_IMPLEMENTED;
422 }
423 
424 /*
425  * @unimplemented
426  */
427 NTSTATUS
428 NTAPI
430  IN ULONG Unknown1,
431  IN ULONG Unknown2,
432  IN ULONG Unknown3,
433  IN PVOID Unknown4,
434  IN PVOID Unknown5)
435 {
437  return STATUS_NOT_IMPLEMENTED;
438 }
439 
440 /*
441  * @unimplemented
442  */
443 VOID
444 NTAPI
446  IN ULONG BugCheckCode,
447  IN ULONG_PTR BugCheckParameter1,
448  IN ULONG_PTR BugCheckParameter2,
449  IN ULONG_PTR BugCheckParameter3,
450  IN ULONG_PTR BugCheckParameter4)
451 {
452  DPRINT1("PoShutdownBugCheck called\n");
453 
454  /* FIXME: Log error if requested */
455  /* FIXME: Initiate a shutdown */
456 
457  /* Bugcheck the system */
458  KeBugCheckEx(BugCheckCode,
459  BugCheckParameter1,
460  BugCheckParameter2,
461  BugCheckParameter3,
462  BugCheckParameter4);
463 }
464 
465 /*
466  * @unimplemented
467  */
468 VOID
469 NTAPI
470 PoSetHiberRange(IN PVOID HiberContext,
471  IN ULONG Flags,
473  IN ULONG Length,
474  IN ULONG PageTag)
475 {
477  return;
478 }
479 
480 /*
481  * @implemented
482  */
483 NTSTATUS
484 NTAPI
486  IN OUT PIRP Irp)
487 {
489 
490  /* Forward to Io -- FIXME! */
492 
493  /* Return status */
494  return Status;
495 }
496 
497 /*
498  * @unimplemented
499  */
500 PULONG
501 NTAPI
506 {
508  return NULL;
509 }
510 
511 /*
512  * @unimplemented
513  */
514 PVOID
515 NTAPI
518 {
520  return NULL;
521 }
522 
523 /*
524  * @implemented
525  */
526 NTSTATUS
527 NTAPI
532  IN PVOID Context,
533  OUT PIRP *pIrp OPTIONAL)
534 {
535  PDEVICE_OBJECT TopDeviceObject;
536  PIO_STACK_LOCATION Stack;
537  PIRP Irp;
538 
543 
544  /* Always call the top of the device stack */
545  TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
546 
547  Irp = IoAllocateIrp(TopDeviceObject->StackSize + 2, FALSE);
548  if (!Irp)
549  {
550  ObDereferenceObject(TopDeviceObject);
552  }
553 
554  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
555  Irp->IoStatus.Information = 0;
556 
558 
560  Stack->Parameters.Others.Argument1 = DeviceObject;
561  Stack->Parameters.Others.Argument2 = (PVOID)(ULONG_PTR)MinorFunction;
562  Stack->Parameters.Others.Argument3 = (PVOID)(ULONG_PTR)PowerState.DeviceState;
563  Stack->Parameters.Others.Argument4 = Context;
564  Stack->DeviceObject = TopDeviceObject;
566 
568  Stack->MajorFunction = IRP_MJ_POWER;
569  Stack->MinorFunction = MinorFunction;
571  {
572  Stack->Parameters.WaitWake.PowerState = PowerState.SystemState;
573  }
574  else
575  {
576  Stack->Parameters.Power.Type = DevicePowerState;
577  Stack->Parameters.Power.State = PowerState;
578  }
579 
580  if (pIrp != NULL)
581  *pIrp = Irp;
582 
584  PoCallDriver(TopDeviceObject, Irp);
585 
586  /* Always return STATUS_PENDING. The completion routine
587  * will call CompletionFunction and complete the Irp.
588  */
589  return STATUS_PENDING;
590 }
591 
592 /*
593  * @unimplemented
594  */
596 NTAPI
600 {
601  POWER_STATE ps;
602 
604 
605  ps.SystemState = PowerSystemWorking; // Fully on
606  ps.DeviceState = PowerDeviceD0; // Fully on
607 
608  return ps;
609 }
610 
611 /*
612  * @unimplemented
613  */
614 VOID
615 NTAPI
617 {
619 }
620 
621 /*
622  * @unimplemented
623  */
624 VOID
625 NTAPI
627 {
629 }
630 
631 /*
632  * @unimplemented
633  */
634 VOID
635 NTAPI
637 {
639 }
640 
641 /*
642  * @unimplemented
643  */
644 NTSTATUS
645 NTAPI
648  IN ULONG Flags,
650 {
652  return STATUS_NOT_IMPLEMENTED;
653 }
654 
655 /*
656  * @unimplemented
657  */
658 NTSTATUS
659 NTAPI
665 {
668 
669  PAGED_CODE();
670 
671  DPRINT("NtPowerInformation(PowerInformationLevel 0x%x, InputBuffer 0x%p, "
672  "InputBufferLength 0x%x, OutputBuffer 0x%p, OutputBufferLength 0x%x)\n",
673  PowerInformationLevel,
676 
677  if (PreviousMode != KernelMode)
678  {
679  _SEH2_TRY
680  {
683  }
685  {
687  }
688  _SEH2_END;
689  }
690 
691  switch (PowerInformationLevel)
692  {
693  case SystemBatteryState:
694  {
696 
697  if (InputBuffer != NULL)
701 
702  _SEH2_TRY
703  {
704  /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
705  RtlZeroMemory(BatteryState, sizeof(SYSTEM_BATTERY_STATE));
706  BatteryState->AcOnLine = TRUE;
707 
709  }
711  {
713  }
714  _SEH2_END;
715 
716  break;
717  }
718 
720  {
722 
723  if (InputBuffer != NULL)
727 
728  _SEH2_TRY
729  {
730  RtlCopyMemory(PowerCapabilities,
732  sizeof(SYSTEM_POWER_CAPABILITIES));
733 
735  }
737  {
739  }
740  _SEH2_END;
741 
742  break;
743  }
744 
746  {
748 
749  if (InputBuffer != NULL)
753 
754  _SEH2_TRY
755  {
756  PowerInformation->Number = 0;
757  PowerInformation->MaxMhz = 1000;
758  PowerInformation->CurrentMhz = 1000;
759  PowerInformation->MhzLimit = 1000;
760  PowerInformation->MaxIdleState = 0;
761  PowerInformation->CurrentIdleState = 0;
762 
764  }
766  {
768  }
769  _SEH2_END;
770 
771  break;
772  }
773 
774  default:
776  DPRINT1("PowerInformationLevel 0x%x is UNIMPLEMENTED! Have a nice day.\n",
777  PowerInformationLevel);
778  break;
779  }
780 
781  return Status;
782 }
783 
784 NTSTATUS
785 NTAPI
788 {
790  return STATUS_NOT_IMPLEMENTED;
791 }
792 
793 BOOLEAN
794 NTAPI
796 {
798  return FALSE;
799 }
800 
801 NTSTATUS
802 NTAPI
804 {
806  return STATUS_NOT_IMPLEMENTED;
807 }
808 
809 NTSTATUS
810 NTAPI
813 {
817  PAGED_CODE();
818 
819  /* Validate flags */
820  if (esFlags & ~(ES_CONTINUOUS | ES_USER_PRESENT))
821  {
822  /* Fail the request */
824  }
825 
826  /* Check for user parameters */
827  if (PreviousMode != KernelMode)
828  {
829  /* Protect the probes */
830  _SEH2_TRY
831  {
832  /* Check if the pointer is valid */
834  }
836  {
837  /* It isn't -- fail */
839  }
840  _SEH2_END;
841  }
842 
843  /* Save the previous state, always masking in the continous flag */
844  PreviousState = Thread->PowerState | ES_CONTINUOUS;
845 
846  /* Check if we need to update the power state */
847  if (esFlags & ES_CONTINUOUS) Thread->PowerState = (UCHAR)esFlags;
848 
849  /* Protect the write back to user mode */
850  _SEH2_TRY
851  {
852  /* Return the previous flags */
854  }
856  {
857  /* Something's wrong, fail */
859  }
860  _SEH2_END;
861 
862  /* All is good */
863  return STATUS_SUCCESS;
864 }
865 
866 NTSTATUS
867 NTAPI
870  IN ULONG Flags)
871 {
873  POP_POWER_ACTION Action = {0};
875  ULONG Dummy;
876 
877  /* Check for invalid parameter combinations */
880  (SystemAction > PowerActionWarmEject) ||
881  (SystemAction < PowerActionReserved) ||
889  {
890  DPRINT1("NtSetSystemPowerState: Bad parameters!\n");
891  DPRINT1(" SystemAction: 0x%x\n", SystemAction);
892  DPRINT1(" MinSystemState: 0x%x\n", MinSystemState);
893  DPRINT1(" Flags: 0x%x\n", Flags);
895  }
896 
897  /* Check for user caller */
898  if (PreviousMode != KernelMode)
899  {
900  /* Check for shutdown permission */
902  {
903  /* Not granted */
904  DPRINT1("ERROR: Privilege not held for shutdown\n");
906  }
907 
908  /* Do it as a kernel-mode caller for consistency with system state */
909  return ZwSetSystemPowerState(SystemAction, MinSystemState, Flags);
910  }
911 
912  /* Read policy settings (partial shutdown vs. full shutdown) */
913  if (SystemAction == PowerActionShutdown) PopReadShutdownPolicy();
914 
915  /* Disable lazy flushing of registry */
916  DPRINT("Stopping lazy flush\n");
918 
919  /* Setup the power action */
920  Action.Action = SystemAction;
921  Action.Flags = Flags;
922 
923  /* Notify callbacks */
924  DPRINT("Notifying callbacks\n");
926 
927  /* Swap in any worker thread stacks */
928  DPRINT("Swapping worker threads\n");
930 
931  /* Make our action global */
932  PopAction = Action;
933 
934  /* Start power loop */
936  while (TRUE)
937  {
938  /* Break out if there's nothing to do */
939  if (Action.Action == PowerActionNone) break;
940 
941  /* Check for first-pass or restart */
942  if (Status == STATUS_CANCELLED)
943  {
944  /* Check for shutdown action */
948  {
949  /* Set the action */
951  }
952 
953  /* Now we are good to go */
955  }
956 
957  /* Check if we're still in an invalid status */
958  if (!NT_SUCCESS(Status)) break;
959 
960 #ifndef NEWCC
961  /* Flush dirty cache pages */
962  /* XXX: Is that still mandatory? As now we'll wait on lazy writer to complete? */
963  CcRosFlushDirtyPages(-1, &Dummy, FALSE, FALSE); //HACK: We really should wait here!
964 #else
965  Dummy = 0;
966 #endif
967 
968  /* Flush all volumes and the registry */
969  DPRINT("Flushing volumes, cache flushed %lu pages\n", Dummy);
971 
972  /* Set IRP for drivers */
974  if (PopAction.Shutdown)
975  {
976  DPRINT("Queueing shutdown thread\n");
977  /* Check if we are running in the system context */
979  {
980  /* We're not, so use a worker thread for shutdown */
983  NULL);
984 
986 
987  /* Spend us -- when we wake up, the system is good to go down */
990  goto Exit;
991 
992  }
993  else
994  {
995  /* Do the shutdown inline */
997  }
998  }
999 
1000  /* You should not have made it this far */
1001  // ASSERTMSG("System is still up and running?!\n", FALSE);
1002  DPRINT1("System is still up and running, you may not have chosen a yet supported power option: %u\n", PopAction.Action);
1003  break;
1004  }
1005 
1006 Exit:
1007  /* We're done, return */
1008  return Status;
1009 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
signed char * PCHAR
Definition: retypes.h:7
NTSTATUS PopQuerySystemPowerStateTraverse(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: power.c:153
PCALLBACK_OBJECT PowerStateCallback
Definition: callback.c:29
#define ASSERT_IRQL_LESS_OR_EQUAL(x)
Definition: debug.h:251
enum _POWER_STATE_TYPE POWER_STATE_TYPE
#define IN
Definition: typedefs.h:38
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
PDEVICE_NODE IopRootDeviceNode
Definition: pnpmgr.c:18
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD Unknown3
Definition: conport.c:35
VOID NTAPI ExSwapinWorkerThreads(IN BOOLEAN AllowSwap)
Definition: work.c:631
Type
Definition: Type.h:6
_In_ PIRP _In_ PDEVICE_OBJECT Device
Definition: fatprocs.h:2020
VOID NTAPI PoShutdownBugCheck(IN BOOLEAN LogError, IN ULONG BugCheckCode, IN ULONG_PTR BugCheckParameter1, IN ULONG_PTR BugCheckParameter2, IN ULONG_PTR BugCheckParameter3, IN ULONG_PTR BugCheckParameter4)
Definition: power.c:445
#define IRP_MN_QUERY_POWER
REQUEST_POWER_COMPLETE * PREQUEST_POWER_COMPLETE
Definition: potypes.h:404
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ ULONG _In_ BOOLEAN LogError
Definition: classpnp.h:1117
NTSTATUS IopTraverseDeviceTree(PDEVICETREE_TRAVERSE_CONTEXT Context)
Definition: pnpmgr.c:1552
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
POWER_ACTION Action
Definition: po.h:216
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
UCHAR IrpMinor
Definition: po.h:220
PLOADER_PARAMETER_EXTENSION Extension
Definition: arc.h:512
#define POWER_ACTION_DISABLE_WAKES
Definition: ntpoapi.h:419
_In_ ULONG ConservationIdleTime
Definition: pofuncs.h:24
#define KeGetPreviousMode()
Definition: ketypes.h:1081
PULONG NTAPI PoRegisterDeviceForIdleDetection(IN PDEVICE_OBJECT DeviceObject, IN ULONG ConservationIdleTime, IN ULONG PerformanceIdleTime, IN DEVICE_POWER_STATE State)
Definition: power.c:502
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
#define POWER_ACTION_LOCK_CONSOLE
Definition: ntpoapi.h:418
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1195
POWER_ACTION PowerAction
Definition: power.c:21
PDEVICE_NODE PopSystemPowerDeviceNode
Definition: power.c:25
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS NTAPI CcRosFlushDirtyPages(ULONG Target, PULONG Count, BOOLEAN Wait, BOOLEAN CalledFromLazy)
Definition: view.c:183
_In_ SYSTEM_POWER_STATE MinSystemState
Definition: ntpoapi.h:303
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FASTCALL
Definition: nt_native.h:50
BOOLEAN PopAcpiPresent
Definition: power.c:26
enum _SYSTEM_POWER_STATE SYSTEM_POWER_STATE
VOID NTAPI PopCleanupPowerState(IN PPOWER_STATE PowerState)
Definition: power.c:63
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
VOID NTAPI PoUnregisterSystemState(IN PVOID StateHandle)
Definition: power.c:636
#define PAGED_CODE()
Definition: video.h:57
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
_SEH2_TRY
Definition: create.c:4250
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
uint32_t ULONG_PTR
Definition: typedefs.h:63
int WINAPI StartPage(_In_ HDC)
NTSTATUS NTAPI PoCancelDeviceNotify(IN PVOID NotifyBlock)
Definition: power.c:418
VOID NTAPI PoSetSystemState(IN EXECUTION_STATE Flags)
Definition: power.c:616
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
ULONG NTAPI KeSuspendThread(PKTHREAD Thread)
Definition: thrdobj.c:610
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_ ULONG _In_opt_ PVOID _In_ PDRIVER_OBJECT _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE _Inout_opt_ __drv_aliasesMem PVOID _Outptr_result_nullonfailure_ _At_ * NotificationEntry(return==0, __drv_allocatesMem(Mem))) PVOID *NotificationEntry
LIST_ENTRY PopVolumeDevices
Definition: povolume.c:27
_In_ SYSTEM_POWER_STATE _In_ ULONG _In_ BOOLEAN Asynchronous
Definition: ntpoapi.h:303
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
struct _POWER_STATE_TRAVERSE_CONTEXT POWER_STATE_TRAVERSE_CONTEXT
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
#define POWER_ACTION_OVERRIDE_APPS
Definition: ntpoapi.h:416
struct SYSTEM_POWER_CAPABILITIES * PSYSTEM_POWER_CAPABILITIES
PRTL_UNICODE_STRING_BUFFER PULONG PULONG Unknown4
NTSTATUS PopSendQuerySystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
Definition: power.c:69
WORK_QUEUE_ITEM PopShutdownWorkItem
Definition: power.c:28
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
unsigned char BOOLEAN
NTSTATUS NTAPI NtInitiatePowerAction(IN POWER_ACTION SystemAction, IN SYSTEM_POWER_STATE MinSystemState, IN ULONG Flags, IN BOOLEAN Asynchronous)
Definition: power.c:646
VOID NTAPI PopReadShutdownPolicy(VOID)
Definition: poshtdwn.c:315
VOID NTAPI PopInitShutdownList(VOID)
Definition: poshtdwn.c:32
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI PoSetHiberRange(IN PVOID HiberContext, IN ULONG Flags, IN OUT PVOID StartPage, IN ULONG Length, IN ULONG PageTag)
Definition: power.c:470
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:462
void DPRINT(...)
Definition: polytest.cpp:61
POP_POWER_ACTION PopAction
Definition: power.c:27
NTSTATUS NTAPI NtSetSystemPowerState(IN POWER_ACTION SystemAction, IN SYSTEM_POWER_STATE MinSystemState, IN ULONG Flags)
Definition: power.c:868
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
KGUARDED_MUTEX PopVolumeLock
Definition: povolume.c:26
void * PVOID
Definition: retypes.h:9
#define POWER_ACTION_CRITICAL
Definition: ntpoapi.h:420
_Out_ EXECUTION_STATE * PreviousFlags
Definition: ntpoapi.h:288
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
VOID NTAPI HalProcessorIdle(VOID)
Definition: processor.c:83
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1405
LATENCY_TIME
Definition: potypes.h:171
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
struct _POWER_STATE_TRAVERSE_CONTEXT * PPOWER_STATE_TRAVERSE_CONTEXT
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:675
#define POWER_ACTION_QUERY_ALLOWED
Definition: ntpoapi.h:414
VOID NTAPI ExNotifyCallback(IN PCALLBACK_OBJECT CallbackObject, IN PVOID Argument1, IN PVOID Argument2)
Definition: callback.c:467
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
_In_ LARGE_INTEGER _In_opt_ PKDPC Dpc
Definition: kefuncs.h:524
enum _DEVICE_POWER_STATE * PDEVICE_POWER_STATE
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define POWER_ACTION_UI_ALLOWED
Definition: ntpoapi.h:415
NTSYSCALLAPI NTSTATUS NTAPI ZwSetSystemPowerState(_In_ POWER_ACTION SystemAction, _In_ SYSTEM_POWER_STATE MinSystemState, _In_ ULONG Flags)
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
NTSTATUS NTAPI NtGetDevicePowerState(IN HANDLE Device, IN PDEVICE_POWER_STATE PowerState)
Definition: power.c:786
INIT_FUNCTION VOID NTAPI PoInitializePrcb(IN PKPRCB Prcb)
Definition: power.c:396
VOID NTAPI CmSetLazyFlushState(IN BOOLEAN Enable)
Definition: cmlazy.c:417
static void Exit(void)
Definition: sock.c:1331
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG Action
Definition: fsrtlfuncs.h:738
BOOLEAN NTAPI NtIsSystemResumeAutomatic(VOID)
Definition: power.c:795
enum _POWER_INFORMATION_LEVEL POWER_INFORMATION_LEVEL
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2866
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
Definition: Node.h:9
NTSTATUS IopGetSystemPowerDeviceObject(IN PDEVICE_OBJECT *DeviceObject)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IRP_MJ_POWER
NTSTATUS PopSendSetSystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
Definition: power.c:111
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
NTSTATUS NTAPI NtRequestWakeupLatency(IN LATENCY_TIME Latency)
Definition: power.c:803
ULONG EXECUTION_STATE
Definition: potypes.h:169
_In_ UCHAR _In_ POWER_STATE _In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction
Definition: pofuncs.h:42
Definition: ketypes.h:687
POWER_ACTION
Definition: ntpoapi.h:122
#define DNF_LEGACY_DRIVER
Definition: iotypes.h:181
VOID NTAPI PopFlushVolumes(IN BOOLEAN ShuttingDown)
Definition: povolume.c:229
NTSTATUS NTAPI IoRegisterPlugPlayNotification(IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN ULONG EventCategoryFlags, IN PVOID EventCategoryData OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Context, OUT PVOID *NotificationEntry)
Definition: pnpnotify.c:250
#define IRP_MN_SET_POWER
_In_ UCHAR MinorFunction
Definition: pofuncs.h:42
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
Status
Definition: gdiplustypes.h:24
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
static NTSTATUS NTAPI PopRequestPowerIrpCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: power.c:36
NTSTATUS NTAPI PoRegisterDeviceNotify(OUT PVOID Unknown0, IN ULONG Unknown1, IN ULONG Unknown2, IN ULONG Unknown3, IN PVOID Unknown4, IN PVOID Unknown5)
Definition: power.c:429
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define POWER_ACTION_LIGHTEST_FIRST
Definition: ntpoapi.h:417
_In_ PLARGE_INTEGER _In_opt_ PTIMER_APC_ROUTINE _In_opt_ PVOID _In_ BOOLEAN _In_opt_ LONG _Out_opt_ PBOOLEAN PreviousState
Definition: zwfuncs.h:428
struct SYSTEM_BATTERY_STATE * PSYSTEM_BATTERY_STATE
const LUID SeShutdownPrivilege
Definition: priv.c:40
_SEH2_END
Definition: create.c:4424
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
_In_ ULONG _In_ ULONG PerformanceIdleTime
Definition: pofuncs.h:24
#define ES_CONTINUOUS
Definition: potypes.h:167
VOID NTAPI PopPerfIdleDpc(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: power.c:376
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
VOID NTAPI PopGracefulShutdown(IN PVOID Context)
Definition: poshtdwn.c:244
INIT_FUNCTION BOOLEAN NTAPI PoInitSystem(IN ULONG BootPhase)
Definition: power.c:296
VOID FASTCALL PopIdle0(IN PPROCESSOR_POWER_STATE PowerState)
Definition: power.c:387
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
SYSTEM_POWER_CAPABILITIES PopCapabilities
Definition: power.c:29
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define ES_USER_PRESENT
Definition: potypes.h:166
NTSTATUS NTAPI NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength)
Definition: power.c:660
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI PopPerfIdle(PPROCESSOR_POWER_STATE PowerState)
Definition: power.c:369
VOID NTAPI KeSetTargetProcessorDpc(IN PKDPC Dpc, IN CCHAR Number)
Definition: dpc.c:970
NTSTATUS NTAPI PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure, IN PVOID Context)
Definition: events.c:147
#define OUT
Definition: typedefs.h:39
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define IopInitDeviceTreeTraverseContext( _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context)
Definition: io.h:225
struct tagContext Context
Definition: acpixf.h:1012
_In_ PIRP _In_opt_ PVOID _In_opt_ POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine
Definition: fsrtlfuncs.h:673
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:114
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
POWER_STATE NTAPI PoSetPowerState(IN PDEVICE_OBJECT DeviceObject, IN POWER_STATE_TYPE Type, IN POWER_STATE State)
Definition: power.c:597
#define ULONG_PTR
Definition: config.h:101
#define IRP_MN_WAIT_WAKE
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
KSPIN_LOCK PopDopeGlobalLock
Definition: povolume.c:28
NTSTATUS NTAPI PoRequestPowerIrp(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PREQUEST_POWER_COMPLETE CompletionFunction, IN PVOID Context, OUT PIRP *pIrp OPTIONAL)
Definition: power.c:528
PVOID NTAPI PoRegisterSystemState(IN PVOID StateHandle, IN EXECUTION_STATE Flags)
Definition: power.c:516
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
NTSTATUS NTAPI PopSetSystemPowerState(SYSTEM_POWER_STATE PowerState, POWER_ACTION PowerAction)
Definition: power.c:231
#define KeGetCurrentThread
Definition: hal.h:44
PDEVICE_OBJECT PowerDevice
Definition: power.c:22
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
SYSTEM_POWER_STATE SystemPowerState
Definition: power.c:20
BOOLEAN Shutdown
Definition: po.h:215
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD IN DWORD IN DWORD Unknown5
Definition: conport.c:35
return STATUS_SUCCESS
Definition: btrfs.c:2725
NTSTATUS PopSetSystemPowerStateTraverse(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: power.c:187
struct _PROCESSOR_POWER_INFORMATION * PPROCESSOR_POWER_INFORMATION
NTSTATUS NTAPI NtSetThreadExecutionState(IN EXECUTION_STATE esFlags, OUT EXECUTION_STATE *PreviousFlags)
Definition: power.c:811
FORCEINLINE VOID IoSetNextIrpStackLocation(_Inout_ PIRP Irp)
Definition: iofuncs.h:2632
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107
VOID NTAPI KeInitializeTimerEx(OUT PKTIMER Timer, IN TIMER_TYPE Type)
Definition: timerobj.c:244
#define STATUS_SYSTEM_SHUTDOWN
Definition: ntstatus.h:841
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675