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 ******************************************************************/
13 #include "../cache/newcc.h"
18 /* GLOBALS *******************************************************************/
20 ULONG PopShutdownPowerOffPolicy
;
22 /* PRIVATE FUNCTIONS *********************************************************/
26 PopShutdownHandler(VOID
)
31 /* Stop all interrupts */
32 KeRaiseIrqlToDpcLevel();
35 /* Do we have boot video */
36 if (InbvIsBootDriverInstalled())
38 /* Yes we do, cleanup for shutdown screen */
39 if (!InbvCheckDisplayOwnership()) InbvAcquireDisplayOwnership();
41 InbvSolidColorFill(0, 0, 639, 479, 0);
42 InbvEnableDisplayString(TRUE
);
43 InbvSetScrollRegion(0, 0, 639, 479);
45 /* Display shutdown logo and message */
46 Logo1
= InbvGetResourceAddress(IDB_SHUTDOWN_LOGO
);
47 Logo2
= InbvGetResourceAddress(IDB_LOGO
);
48 if ((Logo1
) && (Logo2
))
50 InbvBitBlt(Logo1
, 215, 352);
51 InbvBitBlt(Logo2
, 217, 111);
56 /* Do it in text-mode */
57 for (i
= 0; i
< 25; i
++) InbvDisplayString("\n");
58 InbvDisplayString(" ");
59 InbvDisplayString("The system may be powered off now.\n");
63 for (;;) HalHaltSystem();
68 PopShutdownSystem(IN POWER_ACTION SystemAction
)
70 /* Note should notify caller of NtPowerInformation(PowerShutdownNotification) */
73 DPRINT1("It's the final countdown...%lx\n", SystemAction
);
74 DbgUnLoadImageSymbols(NULL
, (PVOID
)-1, 0);
76 /* Run the thread on the boot processor */
77 KeSetSystemAffinityThread(1);
79 /* Now check what the caller wants */
83 case PowerActionShutdownReset
:
85 /* Try platform driver first, then legacy */
86 //PopInvokeSystemStateHandler(PowerStateShutdownReset, NULL);
87 PopSetSystemPowerState(PowerSystemShutdown
, SystemAction
);
88 HalReturnToFirmware(HalRebootRoutine
);
91 case PowerActionShutdown
:
93 /* Check for group policy that says to use "it is now safe" screen */
94 if (PopShutdownPowerOffPolicy
)
96 /* FIXFIX: Switch to legacy shutdown handler */
97 //PopPowerStateHandlers[PowerStateShutdownOff].Handler = PopShutdownHandler;
100 case PowerActionShutdownOff
:
102 /* Call shutdown handler */
103 //PopInvokeSystemStateHandler(PowerStateShutdownOff, NULL);
106 PopSetSystemPowerState(PowerSystemShutdown
, SystemAction
);
107 PopShutdownHandler();
109 /* If that didn't work, call the HAL */
110 HalReturnToFirmware(HalPowerDownRoutine
);
117 /* Anything else should not happen */
118 KeBugCheckEx(INTERNAL_POWER_ERROR
, 5, 0, 0, 0);
123 PopGracefulShutdown(IN PVOID Context
)
125 PEPROCESS Process
= NULL
;
127 /* Loop every process */
128 Process
= PsGetNextProcess(Process
);
131 /* Make sure this isn't the idle or initial process */
132 if ((Process
!= PsInitialSystemProcess
) && (Process
!= PsIdleProcess
))
135 DPRINT1("%15s is still RUNNING (%lx)\n", Process
->ImageFileName
, Process
->UniqueProcessId
);
138 /* Get the next process */
139 Process
= PsGetNextProcess(Process
);
142 /* First, the HAL handles any "end of boot" special functionality */
143 DPRINT1("HAL shutting down\n");
146 /* In this step, the I/O manager does first-chance shutdown notification */
147 DPRINT1("I/O manager shutting down in phase 0\n");
150 /* In this step, all workers are killed and hives are flushed */
151 DPRINT1("Configuration Manager shutting down\n");
154 /* Note that modified pages should be written here (MiShutdownSystem) */
156 /* Flush all user files before we start shutting down IO */
157 /* This is where modified pages are written back by the IO manager */
161 /* In this step, the I/O manager does last-chance shutdown notification */
162 DPRINT1("I/O manager shutting down in phase 1\n");
164 CcWaitForCurrentLazyWriterActivity();
166 /* Note that here, we should broadcast the power IRP to devices */
168 /* In this step, the HAL disables any wake timers */
169 DPRINT1("Disabling wake timers\n");
170 HalSetWakeEnable(FALSE
);
172 /* And finally the power request is sent */
173 DPRINT1("Taking the system down\n");
174 PopShutdownSystem(PopAction
.Action
);
179 PopReadShutdownPolicy(VOID
)
181 UNICODE_STRING KeyString
;
182 OBJECT_ATTRIBUTES ObjectAttributes
;
186 UCHAR Buffer
[sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + sizeof(ULONG
)];
187 PKEY_VALUE_PARTIAL_INFORMATION Info
= (PVOID
)Buffer
;
189 /* Setup object attributes */
190 RtlInitUnicodeString(&KeyString
,
191 L
"\\Registry\\Machine\\Software\\Policies\\Microsoft\\Windows NT");
192 InitializeObjectAttributes(&ObjectAttributes
,
194 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
199 Status
= ZwOpenKey(&KeyHandle
, KEY_READ
, &ObjectAttributes
);
200 if (NT_SUCCESS(Status
))
202 /* Open the policy value and query it */
203 RtlInitUnicodeString(&KeyString
, L
"DontPowerOffAfterShutdown");
204 Status
= ZwQueryValueKey(KeyHandle
,
206 KeyValuePartialInformation
,
210 if ((NT_SUCCESS(Status
)) && (Info
->Type
== REG_DWORD
))
212 /* Read the policy */
213 PopShutdownPowerOffPolicy
= *Info
->Data
== 1;
221 /* PUBLIC FUNCTIONS **********************************************************/