ReactOS 0.4.15-dev-8096-ga0eec98
poshtdwn.c
Go to the documentation of this file.
1/*
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
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <ntoskrnl.h>
12#ifdef NEWCC
13#include <cache/newcc.h>
14#endif
15
16#define NDEBUG
17#include <debug.h>
18
19#include "inbv/logo.h"
20
21/* GLOBALS *******************************************************************/
22
29
30
31/* PRIVATE FUNCTIONS *********************************************************/
32
33VOID
36{
37 PAGED_CODE();
38
39 /* Initialize the global shutdown event */
41
42 /* Initialize the shutdown lists */
45
46 /* Initialize the shutdown list lock */
48
49 /* The list is available now */
51}
52
57{
58 PPOP_SHUTDOWN_WAIT_ENTRY ShutDownWaitEntry;
60 PAGED_CODE();
61
62 /* Allocate a new shutdown wait entry */
63 ShutDownWaitEntry = ExAllocatePoolWithTag(PagedPool, sizeof(*ShutDownWaitEntry), 'LSoP');
64 if (ShutDownWaitEntry == NULL)
65 {
66 return STATUS_NO_MEMORY;
67 }
68
69 /* Reference the thread and save it in the wait entry */
71 ShutDownWaitEntry->Thread = Thread;
72
73 /* Acquire the shutdown list lock */
75
76 /* Check if the list is still available */
78 {
79 /* Insert the item in the list */
80 ShutDownWaitEntry->NextEntry = PopShutdownThreadList;
81 PopShutdownThreadList = ShutDownWaitEntry;
82
83 /* We are successful */
85 }
86 else
87 {
88 /* We cannot proceed, cleanup and return failure */
90 ExFreePoolWithTag(ShutDownWaitEntry, 'LSoP');
92 }
93
94 /* Release the list lock */
96
97 /* Return the status */
98 return Status;
99}
100
101VOID
102NTAPI
104{
105 PPOP_SHUTDOWN_WAIT_ENTRY ShutDownWaitEntry;
107 PLIST_ENTRY ListEntry;
108
109 /* First signal the shutdown event */
111
112 /* Acquire the shutdown list lock */
114
115 /* Block any further attempts to register a shutdown event */
117
118 /* Release the list lock, since we are exclusively using the lists now */
120
121 /* Process the shutdown queue */
123 {
124 /* Get the head entry */
125 ListEntry = RemoveHeadList(&PopShutdownQueue);
127
128 /* Call the shutdown worker routine */
129 WorkItem->WorkerRoutine(WorkItem->Parameter);
130 }
131
132 /* Now process the shutdown thread list */
133 while (PopShutdownThreadList != NULL)
134 {
135 /* Get the top entry and remove it from the list */
136 ShutDownWaitEntry = PopShutdownThreadList;
138
139 /* Wait for the thread to finish and dereference it */
140 KeWaitForSingleObject(ShutDownWaitEntry->Thread, 0, 0, 0, 0);
141 ObDereferenceObject(ShutDownWaitEntry->Thread);
142
143 /* Finally free the entry */
144 ExFreePoolWithTag(ShutDownWaitEntry, 'LSoP');
145 }
146}
147
148VOID
149NTAPI
151{
152 /* Stop all interrupts */
154 _disable();
155
156 /* Do we have boot video */
158 {
159 /* Yes we do, cleanup for shutdown screen */
162 // InbvEnableDisplayString(TRUE);
164 }
165 else
166 {
167 /* Do it in text-mode */
169 }
170
171 /* Hang the system */
172 for (;;) HalHaltSystem();
173}
174
175VOID
176NTAPI
178{
179 /* Note should notify caller of NtPowerInformation(PowerShutdownNotification) */
180
181 /* Unload symbols */
182 DPRINT("It's the final countdown...%lx\n", SystemAction);
184
185 /* Run the thread on the boot processor */
187
188 /* Now check what the caller wants */
189 switch (SystemAction)
190 {
191 /* Reset */
193
194 /* Try platform driver first, then legacy */
195 //PopInvokeSystemStateHandler(PowerStateShutdownReset, NULL);
198 break;
199
201
202 /* Check for group policy that says to use "it is now safe" screen */
204 {
205 /* FIXFIX: Switch to legacy shutdown handler */
206 //PopPowerStateHandlers[PowerStateShutdownOff].Handler = PopShutdownHandler;
207 }
208
210
211 /* Call shutdown handler */
212 //PopInvokeSystemStateHandler(PowerStateShutdownOff, NULL);
213
214 /* ReactOS Hack */
217
218 /* If that didn't work, call the HAL */
220 break;
221
222 default:
223 break;
224 }
225
226 /* Anything else should not happen */
227 KeBugCheckEx(INTERNAL_POWER_ERROR, 5, 0, 0, 0);
228}
229
230VOID
231NTAPI
233{
235
236 /* Process the registered waits and work items */
238
239 /* Loop every process */
241 while (Process)
242 {
243 /* Make sure this isn't the idle or initial process */
245 {
246 /* Print it */
247 DPRINT1("%15s is still RUNNING (%p)\n", Process->ImageFileName, Process->UniqueProcessId);
248 }
249
250 /* Get the next process */
252 }
253
254 /* First, the HAL handles any "end of boot" special functionality */
255 DPRINT("HAL shutting down\n");
256 HalEndOfBoot();
257
258 /* Shut down the Shim cache if enabled */
260
261 /* In this step, the I/O manager does first-chance shutdown notification */
262 DPRINT("I/O manager shutting down in phase 0\n");
264
265 /* In this step, all workers are killed and hives are flushed */
266 DPRINT("Configuration Manager shutting down\n");
268
269 /* Shut down the Executive */
270 DPRINT("Executive shutting down\n");
272
273 /* Note that modified pages should be written here (MiShutdownSystem) */
275
276 /* Flush all user files before we start shutting down IO */
277 /* This is where modified pages are written back by the IO manager */
279
280 /* In this step, the I/O manager does last-chance shutdown notification */
281 DPRINT("I/O manager shutting down in phase 1\n");
284
285 /* FIXME: Calling Mm shutdown phase 1 here to get page file dereference
286 * but it shouldn't be called here. Only phase 2 should be called.
287 */
289
290 /* Note that here, we should broadcast the power IRP to devices */
291
292 /* In this step, the HAL disables any wake timers */
293 DPRINT("Disabling wake timers\n");
295
296 /* And finally the power request is sent */
297 DPRINT("Taking the system down\n");
299}
300
301VOID
302NTAPI
304{
305 UNICODE_STRING KeyString;
312
313 /* Setup object attributes */
314 RtlInitUnicodeString(&KeyString,
315 L"\\Registry\\Machine\\Software\\Policies\\Microsoft\\Windows NT");
317 &KeyString,
319 NULL,
320 NULL);
321
322 /* Open the key */
323 Status = ZwOpenKey(&KeyHandle, KEY_READ, &ObjectAttributes);
324 if (NT_SUCCESS(Status))
325 {
326 /* Open the policy value and query it */
327 RtlInitUnicodeString(&KeyString, L"DontPowerOffAfterShutdown");
328 Status = ZwQueryValueKey(KeyHandle,
329 &KeyString,
331 &Info,
332 sizeof(Info),
333 &Length);
334 if ((NT_SUCCESS(Status)) && (Info->Type == REG_DWORD))
335 {
336 /* Read the policy */
337 PopShutdownPowerOffPolicy = *Info->Data == 1;
338 }
339
340 /* Close the key */
342 }
343}
344
345/* PUBLIC FUNCTIONS **********************************************************/
346
347/*
348 * @unimplemented
349 */
351NTAPI
354{
356
357 /* Acquire the shutdown list lock */
359
360 /* Check if the list is (already/still) available */
362 {
363 /* Insert the item into the list */
366 }
367 else
368 {
369 /* We are already in shutdown */
371 }
372
373 /* Release the list lock */
375
376 return Status;
377}
378
379/*
380 * @implemented
381 */
383NTAPI
385{
387 PAGED_CODE();
388
389 /* Initialize to NULL */
390 if (Event) *Event = NULL;
391
392 /* Request a shutdown wait */
394 if (!NT_SUCCESS(Status))
395 {
396 return Status;
397 }
398
399 /* Return the global shutdown event */
401 return STATUS_SUCCESS;
402}
403
#define PAGED_CODE()
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI DisplayShutdownBitmap(VOID)
Definition: bootanim.c:924
VOID NTAPI DisplayShutdownText(VOID)
Definition: bootanim.c:981
VOID NTAPI CcShutdownSystem(VOID)
Definition: cachesub.c:299
Definition: bufpool.h:45
VOID NTAPI CmShutdownSystem(VOID)
Definition: cmsysini.c:2146
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define PagedPool
Definition: env_spec_w32.h:308
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment KeRaiseIrqlToDpcLevel
Definition: CrNtStubs.h:68
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
Status
Definition: gdiplustypes.h:25
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
VOID NTAPI HalReturnToFirmware(_In_ FIRMWARE_REENTRY Action)
Definition: reboot.c:21
VOID NTAPI InbvAcquireDisplayOwnership(VOID)
Definition: inbv.c:290
BOOLEAN NTAPI InbvCheckDisplayOwnership(VOID)
Definition: inbv.c:316
BOOLEAN NTAPI InbvResetDisplay(VOID)
Definition: inbv.c:431
BOOLEAN NTAPI InbvIsBootDriverInstalled(VOID)
Definition: inbv.c:396
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
void __cdecl _disable(void)
Definition: intrin_arm.h:365
NTSTATUS NTAPI CcWaitForCurrentLazyWriterActivity(VOID)
Definition: lazyrite.c:30
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define _In_
Definition: ms_sal.h:308
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
#define HalSetWakeEnable
Definition: halfuncs.h:39
#define HalHaltSystem
Definition: halfuncs.h:43
@ HalPowerDownRoutine
Definition: haltypes.h:35
@ HalRebootRoutine
Definition: haltypes.h:37
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
VOID NTAPI DbgUnLoadImageSymbols(_In_ PSTRING Name, _In_ PVOID Base, _In_ ULONG_PTR ProcessId)
@ KeyValuePartialInformation
Definition: nt_native.h:1182
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ NotificationEvent
VOID NTAPI ExShutdownSystem(VOID)
Definition: shutdown.c:21
VOID NTAPI IoShutdownSystem(IN ULONG Phase)
Definition: device.c:133
VOID MmShutdownSystem(IN ULONG Phase)
Definition: shutdown.c:77
@ PowerSystemShutdown
Definition: ntpoapi.h:41
POWER_ACTION
Definition: ntpoapi.h:122
@ PowerActionShutdownOff
Definition: ntpoapi.h:129
@ PowerActionShutdown
Definition: ntpoapi.h:127
@ PowerActionShutdownReset
Definition: ntpoapi.h:128
#define STATUS_SYSTEM_SHUTDOWN
Definition: ntstatus.h:855
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI PopSetSystemPowerState(SYSTEM_POWER_STATE PowerState, POWER_ACTION PowerAction)
Definition: power.c:332
POP_POWER_ACTION PopAction
Definition: power.c:27
VOID NTAPI PopInitShutdownList(VOID)
Definition: poshtdwn.c:35
VOID NTAPI PopReadShutdownPolicy(VOID)
Definition: poshtdwn.c:303
KEVENT PopShutdownEvent
Definition: poshtdwn.c:24
VOID NTAPI PopProcessShutDownLists(VOID)
Definition: poshtdwn.c:103
NTSTATUS NTAPI PoQueueShutdownWorkItem(_In_ PWORK_QUEUE_ITEM WorkItem)
Definition: poshtdwn.c:352
ULONG PopShutdownPowerOffPolicy
Definition: poshtdwn.c:23
VOID NTAPI PopShutdownSystem(IN POWER_ACTION SystemAction)
Definition: poshtdwn.c:177
VOID NTAPI PopShutdownHandler(VOID)
Definition: poshtdwn.c:150
NTSTATUS NTAPI PoRequestShutdownEvent(OUT PVOID *Event)
Definition: poshtdwn.c:384
NTSTATUS NTAPI PoRequestShutdownWait(_In_ PETHREAD Thread)
Definition: poshtdwn.c:55
KGUARDED_MUTEX PopShutdownListMutex
Definition: poshtdwn.c:27
BOOLEAN PopShutdownListAvailable
Definition: poshtdwn.c:28
LIST_ENTRY PopShutdownQueue
Definition: poshtdwn.c:26
PPOP_SHUTDOWN_WAIT_ENTRY PopShutdownThreadList
Definition: poshtdwn.c:25
VOID NTAPI PopGracefulShutdown(IN PVOID Context)
Definition: poshtdwn.c:232
VOID NTAPI ApphelpCacheShutdown(VOID)
Definition: apphelp.c:465
PEPROCESS NTAPI PsGetNextProcess(IN PEPROCESS OldProcess OPTIONAL)
Definition: process.c:128
PEPROCESS PsIdleProcess
Definition: psmgr.c:51
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
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:108
#define REG_DWORD
Definition: sdbapi.c:596
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
Definition: typedefs.h:120
POWER_ACTION Action
Definition: po.h:229
Definition: po.h:272
struct _POP_SHUTDOWN_WAIT_ENTRY * NextEntry
Definition: po.h:273
PETHREAD Thread
Definition: po.h:274
VOID NTAPI KeSetSystemAffinityThread(IN KAFFINITY Affinity)
Definition: thrdobj.c:1107
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:115
#define HalEndOfBoot
Definition: haltypes.h:307
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define ObDereferenceObject
Definition: obfuncs.h:203
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned char UCHAR
Definition: xmlstorage.h:181