2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/po/poshtdwn.c
5 * PURPOSE: Power Manager Shutdown Code
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES ******************************************************************/
15 /* GLOBALS *******************************************************************/
17 ULONG PopShutdownPowerOffPolicy
;
19 /* PRIVATE FUNCTIONS *********************************************************/
23 PopShutdownHandler(VOID
)
28 /* Stop all interrupts */
29 KeRaiseIrqlToDpcLevel();
32 /* Do we have boot video */
33 if (InbvIsBootDriverInstalled())
35 /* Yes we do, cleanup for shutdown screen */
36 if (!InbvCheckDisplayOwnership()) InbvAcquireDisplayOwnership();
38 InbvSolidColorFill(0, 0, 639, 479, 0);
39 InbvEnableDisplayString(TRUE
);
40 InbvSetScrollRegion(0, 0, 639, 479);
42 /* Display shutdown logo and message */
43 Logo1
= InbvGetResourceAddress(IDB_SHUTDOWN_LOGO
);
44 Logo2
= InbvGetResourceAddress(IDB_LOGO
);
45 if ((Logo1
) && (Logo2
))
47 InbvBitBlt(Logo1
, 215, 352);
48 InbvBitBlt(Logo2
, 217, 111);
53 /* Do it in text-mode */
54 for (i
= 0; i
< 25; i
++) InbvDisplayString("\n");
55 InbvDisplayString(" ");
56 InbvDisplayString("The system may be powered off now.\n");
60 for (;;) HalHaltSystem();
65 PopShutdownSystem(IN POWER_ACTION SystemAction
)
67 /* Note should notify caller of NtPowerInformation(PowerShutdownNotification) */
70 DPRINT1("It's the final countdown...%lx\n", SystemAction
);
71 DbgUnLoadImageSymbols(NULL
, (PVOID
)-1, 0);
73 /* Run the thread on the boot processor */
74 KeSetSystemAffinityThread(1);
76 /* Now check what the caller wants */
80 case PowerActionShutdownReset
:
82 /* Try platform driver first, then legacy */
83 //PopInvokeSystemStateHandler(PowerStateShutdownReset, NULL);
84 HalReturnToFirmware(HalRebootRoutine
);
87 case PowerActionShutdown
:
89 /* Check for group policy that says to use "it is now safe" screen */
90 if (PopShutdownPowerOffPolicy
)
92 /* FIXFIX: Switch to legacy shutdown handler */
93 //PopPowerStateHandlers[PowerStateShutdownOff].Handler = PopShutdownHandler;
96 case PowerActionShutdownOff
:
98 /* Call shutdown handler */
99 //PopInvokeSystemStateHandler(PowerStateShutdownOff, NULL);
102 PopSetSystemPowerState(PowerSystemShutdown
);
103 PopShutdownHandler();
105 /* If that didn't work, call the HAL */
106 HalReturnToFirmware(HalPowerDownRoutine
);
113 /* Anything else should not happen */
114 KeBugCheckEx(INTERNAL_POWER_ERROR
, 5, 0, 0, 0);
119 PopGracefulShutdown(IN PVOID Context
)
121 PEPROCESS Process
= NULL
;
123 /* Loop every process */
124 Process
= PsGetNextProcess(Process
);
127 /* Make sure this isn't the idle or initial process */
128 if ((Process
!= PsInitialSystemProcess
) && (Process
!= PsIdleProcess
))
131 DPRINT1("%15s is still RUNNING (%lx)\n", Process
->ImageFileName
, Process
->UniqueProcessId
);
134 /* Get the next process */
135 Process
= PsGetNextProcess(Process
);
138 /* First, the HAL handles any "end of boot" special functionality */
139 DPRINT1("HAL shutting down\n");
142 /* In this step, the I/O manager does first-chance shutdown notification */
143 DPRINT1("I/O manager shutting down in phase 0\n");
146 /* In this step, all workers are killed and hives are flushed */
147 DPRINT1("Configuration Manager shutting down\n");
150 /* Note that modified pages should be written here (MiShutdownSystem) */
152 /* In this step, the I/O manager does last-chance shutdown notification */
153 DPRINT1("I/O manager shutting down in phase 1\n");
155 CcWaitForCurrentLazyWriterActivity();
157 /* Note that here, we should broadcast the power IRP to devices */
159 /* In this step, the HAL disables any wake timers */
160 DPRINT1("Disabling wake timers\n");
161 HalSetWakeEnable(FALSE
);
163 /* And finally the power request is sent */
164 DPRINT1("Taking the system down\n");
165 PopShutdownSystem(PopAction
.Action
);
170 PopReadShutdownPolicy(VOID
)
172 UNICODE_STRING KeyString
;
173 OBJECT_ATTRIBUTES ObjectAttributes
;
177 UCHAR Buffer
[sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + sizeof(ULONG
)];
178 PKEY_VALUE_PARTIAL_INFORMATION Info
= (PVOID
)Buffer
;
180 /* Setup object attributes */
181 RtlInitUnicodeString(&KeyString
,
182 L
"\\Registry\\Machine\\Software\\Policies\\Microsoft\\Windows NT");
183 InitializeObjectAttributes(&ObjectAttributes
,
185 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
190 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
191 if (NT_SUCCESS(Status
))
193 /* Open the policy value and query it */
194 RtlInitUnicodeString(&KeyString
, L
"DontPowerOffAfterShutdown");
195 Status
= ZwQueryValueKey(KeyHandle
,
197 KeyValuePartialInformation
,
201 if ((NT_SUCCESS(Status
)) && (Info
->Type
== REG_DWORD
))
203 /* Read the policy */
204 PopShutdownPowerOffPolicy
= *Info
->Data
== 1;
212 /* PUBLIC FUNCTIONS **********************************************************/