ReactOS 0.4.16-dev-306-g647d351
po.h File Reference
#include <guiddef.h>
#include <poclass.h>
Include dependency graph for po.h:

Go to the source code of this file.

Classes

struct  _PO_HIBER_PERF
 
struct  _PO_MEMORY_IMAGE
 
struct  _PO_MEMORY_RANGE_ARRAY_RANGE
 
struct  _PO_MEMORY_RANGE_ARRAY_LINK
 
struct  _PO_MEMORY_RANGE_ARRAY
 
struct  _POP_HIBER_CONTEXT
 
struct  _PO_NOTIFY_ORDER_LEVEL
 
struct  _POP_SHUTDOWN_BUG_CHECK
 
struct  _POP_DEVICE_POWER_IRP
 
struct  _PO_DEVICE_NOTIFY_ORDER
 
struct  _POP_DEVICE_SYS_STATE
 
struct  _POP_POWER_ACTION
 
struct  _POWER_CHANNEL_SUMMARY
 
struct  _DEVICE_OBJECT_POWER_EXTENSION
 
struct  _POP_SHUTDOWN_WAIT_ENTRY
 

Macros

#define _PO_DEBUG_   0x00
 
#define PO_STATE_DEBUG   0x01
 
#define POTRACE(x, fmt, ...)   DPRINT(fmt, ##__VA_ARGS__)
 

Typedefs

typedef enum _POP_POLICY_DEVICE_TYPE POP_POLICY_DEVICE_TYPE
 
typedef struct _PO_HIBER_PERF PO_HIBER_PERF
 
typedef struct _PO_HIBER_PERFPPO_HIBER_PERF
 
typedef struct _PO_MEMORY_IMAGE PO_MEMORY_IMAGE
 
typedef struct _PO_MEMORY_IMAGEPPO_MEMORY_IMAGE
 
typedef struct _PO_MEMORY_RANGE_ARRAY_RANGE PO_MEMORY_RANGE_ARRAY_RANGE
 
typedef struct _PO_MEMORY_RANGE_ARRAY_LINK PO_MEMORY_RANGE_ARRAY_LINK
 
typedef struct _PO_MEMORY_RANGE_ARRAY PO_MEMORY_RANGE_ARRAY
 
typedef struct _PO_MEMORY_RANGE_ARRAYPPO_MEMORY_RANGE_ARRAY
 
typedef struct _POP_HIBER_CONTEXT POP_HIBER_CONTEXT
 
typedef struct _POP_HIBER_CONTEXTPPOP_HIBER_CONTEXT
 
typedef struct _PO_NOTIFY_ORDER_LEVEL PO_NOTIFY_ORDER_LEVEL
 
typedef struct _PO_NOTIFY_ORDER_LEVELPPO_NOTIFY_ORDER_LEVEL
 
typedef struct _POP_SHUTDOWN_BUG_CHECK POP_SHUTDOWN_BUG_CHECK
 
typedef struct _POP_SHUTDOWN_BUG_CHECKPPOP_SHUTDOWN_BUG_CHECK
 
typedef struct _POP_DEVICE_POWER_IRP POP_DEVICE_POWER_IRP
 
typedef struct _POP_DEVICE_POWER_IRPPPOP_DEVICE_POWER_IRP
 
typedef struct _PO_DEVICE_NOTIFY_ORDER PO_DEVICE_NOTIFY_ORDER
 
typedef struct _PO_DEVICE_NOTIFY_ORDERPPO_DEVICE_NOTIFY_ORDER
 
typedef struct _POP_DEVICE_SYS_STATE POP_DEVICE_SYS_STATE
 
typedef struct _POP_DEVICE_SYS_STATEPPOP_DEVICE_SYS_STATE
 
typedef struct _POP_POWER_ACTION POP_POWER_ACTION
 
typedef struct _POP_POWER_ACTIONPPOP_POWER_ACTION
 
typedef enum _POP_DEVICE_IDLE_TYPE POP_DEVICE_IDLE_TYPE
 
typedef enum _POP_DEVICE_IDLE_TYPEPPOP_DEVICE_IDLE_TYPE
 
typedef struct _POWER_CHANNEL_SUMMARY POWER_CHANNEL_SUMMARY
 
typedef struct _POWER_CHANNEL_SUMMARYPPOWER_CHANNEL_SUMMARY
 
typedef struct _DEVICE_OBJECT_POWER_EXTENSION DEVICE_OBJECT_POWER_EXTENSION
 
typedef struct _DEVICE_OBJECT_POWER_EXTENSIONPDEVICE_OBJECT_POWER_EXTENSION
 
typedef struct _POP_SHUTDOWN_WAIT_ENTRY POP_SHUTDOWN_WAIT_ENTRY
 
typedef struct _POP_SHUTDOWN_WAIT_ENTRYPPOP_SHUTDOWN_WAIT_ENTRY
 

Enumerations

enum  _POP_POLICY_DEVICE_TYPE {
  PolicyDeviceSystemButton = 0 , PolicyDeviceThermalZone = 1 , PolicyDeviceBattery = 2 , PolicyDeviceMemory = 3 ,
  PolicyInitiatePowerActionAPI = 4 , PolicySetPowerStateAPI = 5 , PolicyImmediateDozeS4 = 6 , PolicySystemIdle = 7 ,
  PolicyDeviceMax = 8
}
 
enum  _POP_DEVICE_IDLE_TYPE { DeviceIdleNormal , DeviceIdleDisk }
 

Functions

BOOLEAN NTAPI PoInitSystem (IN ULONG BootPhase)
 
VOID NTAPI PoInitializePrcb (IN PKPRCB Prcb)
 
VOID NTAPI PopInitShutdownList (VOID)
 
VOID NTAPI PoInitializeDeviceObject (IN OUT PDEVOBJ_EXTENSION DeviceObjectExtension)
 
VOID NTAPI PoVolumeDevice (IN PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI PoRemoveVolumeDevice (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI PopSetSystemPowerState (SYSTEM_POWER_STATE PowerState, POWER_ACTION PowerAction)
 
VOID NTAPI PopCleanupPowerState (IN PPOWER_STATE PowerState)
 
NTSTATUS NTAPI PopAddRemoveSysCapsCallback (IN PVOID NotificationStructure, IN PVOID Context)
 
VOID NTAPI PoNotifySystemTimeSet (VOID)
 
VOID NTAPI PopReadShutdownPolicy (VOID)
 
VOID NTAPI PopGracefulShutdown (IN PVOID Context)
 
VOID NTAPI PopFlushVolumes (IN BOOLEAN ShuttingDown)
 

Variables

PDEVICE_NODE PopSystemPowerDeviceNode
 
KGUARDED_MUTEX PopVolumeLock
 
LIST_ENTRY PopVolumeDevices
 
KSPIN_LOCK PopDopeGlobalLock
 
POP_POWER_ACTION PopAction
 
SYSTEM_POWER_CAPABILITIES PopCapabilities
 

Macro Definition Documentation

◆ _PO_DEBUG_

#define _PO_DEBUG_   0x00

Definition at line 15 of file po.h.

◆ PO_STATE_DEBUG

#define PO_STATE_DEBUG   0x01

Definition at line 20 of file po.h.

◆ POTRACE

#define POTRACE (   x,
  fmt,
  ... 
)    DPRINT(fmt, ##__VA_ARGS__)

Definition at line 33 of file po.h.

Typedef Documentation

◆ DEVICE_OBJECT_POWER_EXTENSION

◆ PDEVICE_OBJECT_POWER_EXTENSION

◆ PO_DEVICE_NOTIFY_ORDER

◆ PO_HIBER_PERF

◆ PO_MEMORY_IMAGE

◆ PO_MEMORY_RANGE_ARRAY

◆ PO_MEMORY_RANGE_ARRAY_LINK

◆ PO_MEMORY_RANGE_ARRAY_RANGE

◆ PO_NOTIFY_ORDER_LEVEL

◆ POP_DEVICE_IDLE_TYPE

◆ POP_DEVICE_POWER_IRP

◆ POP_DEVICE_SYS_STATE

◆ POP_HIBER_CONTEXT

◆ POP_POLICY_DEVICE_TYPE

◆ POP_POWER_ACTION

◆ POP_SHUTDOWN_BUG_CHECK

◆ POP_SHUTDOWN_WAIT_ENTRY

◆ POWER_CHANNEL_SUMMARY

◆ PPO_DEVICE_NOTIFY_ORDER

◆ PPO_HIBER_PERF

◆ PPO_MEMORY_IMAGE

◆ PPO_MEMORY_RANGE_ARRAY

◆ PPO_NOTIFY_ORDER_LEVEL

◆ PPOP_DEVICE_IDLE_TYPE

◆ PPOP_DEVICE_POWER_IRP

◆ PPOP_DEVICE_SYS_STATE

◆ PPOP_HIBER_CONTEXT

◆ PPOP_POWER_ACTION

◆ PPOP_SHUTDOWN_BUG_CHECK

◆ PPOP_SHUTDOWN_WAIT_ENTRY

◆ PPOWER_CHANNEL_SUMMARY

Enumeration Type Documentation

◆ _POP_DEVICE_IDLE_TYPE

Enumerator
DeviceIdleNormal 
DeviceIdleDisk 

Definition at line 243 of file po.h.

244{
enum _POP_DEVICE_IDLE_TYPE * PPOP_DEVICE_IDLE_TYPE
enum _POP_DEVICE_IDLE_TYPE POP_DEVICE_IDLE_TYPE
@ DeviceIdleDisk
Definition: po.h:246
@ DeviceIdleNormal
Definition: po.h:245

◆ _POP_POLICY_DEVICE_TYPE

Enumerator
PolicyDeviceSystemButton 
PolicyDeviceThermalZone 
PolicyDeviceBattery 
PolicyDeviceMemory 
PolicyInitiatePowerActionAPI 
PolicySetPowerStateAPI 
PolicyImmediateDozeS4 
PolicySystemIdle 
PolicyDeviceMax 

Definition at line 36 of file po.h.

37{
@ PolicySetPowerStateAPI
Definition: po.h:43
@ PolicyDeviceBattery
Definition: po.h:40
@ PolicyInitiatePowerActionAPI
Definition: po.h:42
@ PolicyDeviceSystemButton
Definition: po.h:38
@ PolicyDeviceMax
Definition: po.h:46
@ PolicyImmediateDozeS4
Definition: po.h:44
@ PolicySystemIdle
Definition: po.h:45
@ PolicyDeviceMemory
Definition: po.h:41
@ PolicyDeviceThermalZone
Definition: po.h:39
enum _POP_POLICY_DEVICE_TYPE POP_POLICY_DEVICE_TYPE

Function Documentation

◆ PoInitializeDeviceObject()

VOID NTAPI PoInitializeDeviceObject ( IN OUT PDEVOBJ_EXTENSION  DeviceObjectExtension)

Definition at line 361 of file povolume.c.

362{
363 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension = (PVOID)DeviceObjectExtension;
364 PAGED_CODE();
365
366 /* Initialize the power flags */
367 DeviceExtension->PowerFlags = PowerSystemUnspecified & 0xF;
368 DeviceExtension->PowerFlags |= ((PowerDeviceUnspecified << 4) & 0xF0);
369
370 /* The device object is not on drugs yet */
371 DeviceExtension->Dope = NULL;
372}
#define PAGED_CODE()
#define NULL
Definition: types.h:112
@ PowerSystemUnspecified
Definition: ntpoapi.h:35
@ PowerDeviceUnspecified
Definition: ntpoapi.h:48
struct _DEVICE_OBJECT_POWER_EXTENSION * Dope
Definition: iotypes.h:1083
void * PVOID
Definition: typedefs.h:50

Referenced by IoCreateDevice().

◆ PoInitializePrcb()

VOID NTAPI PoInitializePrcb ( IN PKPRCB  Prcb)

Definition at line 510 of file power.c.

511{
512 /* Initialize the Power State */
513 RtlZeroMemory(&Prcb->PowerState, sizeof(Prcb->PowerState));
514 Prcb->PowerState.Idle0KernelTimeLimit = 0xFFFFFFFF;
515 Prcb->PowerState.CurrentThrottle = 100;
516 Prcb->PowerState.CurrentThrottleIndex = 0;
517 Prcb->PowerState.IdleFunction = PopIdle0;
518
519 /* Initialize the Perf DPC and Timer */
520 KeInitializeDpc(&Prcb->PowerState.PerfDpc, PopPerfIdleDpc, Prcb);
521 KeSetTargetProcessorDpc(&Prcb->PowerState.PerfDpc, Prcb->Number);
522 KeInitializeTimerEx(&Prcb->PowerState.PerfTimer, SynchronizationTimer);
523}
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
VOID NTAPI KeSetTargetProcessorDpc(IN PKDPC Dpc, IN CCHAR Number)
Definition: dpc.c:989
@ SynchronizationTimer
VOID NTAPI PopPerfIdleDpc(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: power.c:490
VOID FASTCALL PopIdle0(IN PPROCESSOR_POWER_STATE PowerState)
Definition: power.c:501
VOID NTAPI KeInitializeTimerEx(OUT PKTIMER Timer, IN TIMER_TYPE Type)
Definition: timerobj.c:244
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by KiInitializeKernel(), and KiSystemStartupBootStack().

◆ PoInitSystem()

BOOLEAN NTAPI PoInitSystem ( IN ULONG  BootPhase)

Definition at line 397 of file power.c.

398{
400 PCHAR CommandLine;
401 BOOLEAN ForceAcpiDisable = FALSE;
402
403 /* Check if this is phase 1 init */
404 if (BootPhase == 1)
405 {
407 /* Register power button notification */
410 (PVOID)&GUID_DEVICE_SYS_BUTTON,
415 if (!NT_SUCCESS(Status))
416 return FALSE;
417
418 /* Register lid notification */
421 (PVOID)&GUID_DEVICE_LID,
426 if (!NT_SUCCESS(Status))
427 return FALSE;
428
429 /* Register battery notification */
432 (PVOID)&GUID_DEVICE_BATTERY,
437
438 return NT_SUCCESS(Status);
439 }
440
441 /* Initialize the power capabilities */
443
444 /* Get the Command Line */
445 CommandLine = KeLoaderBlock->LoadOptions;
446
447 /* Upcase it */
448 _strupr(CommandLine);
449
450 /* Check for ACPI disable */
451 if (strstr(CommandLine, "NOACPI")) ForceAcpiDisable = TRUE;
452
453 if (ForceAcpiDisable)
454 {
455 /* Set the ACPI State to False if it's been forced that way */
457 }
458 else
459 {
460 /* Otherwise check if the LoaderBlock has a ACPI Table */
462 }
463
464 /* Enable shutdown by power button */
465 if (PopAcpiPresent)
467
468 /* Initialize volume support */
471
472 /* Initialize support for dope */
474
475 /* Initialize support for shutdown waits and work-items */
477
478 return TRUE;
479}
unsigned char BOOLEAN
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
LONG NTSTATUS
Definition: precomp.h:26
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
Status
Definition: gdiplustypes.h:25
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
BOOLEAN PopAcpiPresent
Definition: power.c:26
SYSTEM_POWER_CAPABILITIES PopCapabilities
Definition: power.c:29
NTSTATUS NTAPI IoRegisterPlugPlayNotification(_In_ IO_NOTIFICATION_EVENT_CATEGORY EventCategory, _In_ ULONG EventCategoryFlags, _In_opt_ PVOID EventCategoryData, _In_ PDRIVER_OBJECT DriverObject, _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, _Inout_opt_ PVOID Context, _Out_ PVOID *NotificationEntry)
Definition: pnpnotify.c:346
LIST_ENTRY PopVolumeDevices
Definition: povolume.c:27
VOID NTAPI PopInitShutdownList(VOID)
Definition: poshtdwn.c:35
NTSTATUS NTAPI PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure, IN PVOID Context)
Definition: events.c:147
KSPIN_LOCK PopDopeGlobalLock
Definition: povolume.c:28
KGUARDED_MUTEX PopVolumeLock
Definition: povolume.c:26
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:1005
PLOADER_PARAMETER_EXTENSION Extension
Definition: arc.h:559
uint32_t ULONG_PTR
Definition: typedefs.h:65
char * PCHAR
Definition: typedefs.h:51
_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
@ EventCategoryDeviceInterfaceChange
Definition: iotypes.h:1226
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1239

Referenced by Phase1InitializationDiscard().

◆ PoNotifySystemTimeSet()

VOID NTAPI PoNotifySystemTimeSet ( VOID  )

Definition at line 39 of file events.c.

40{
42
43 /* Check if Win32k registered a notification callback */
45 {
46 /* Raise to dispatch */
48
49 /* Notify the callback */
51
52 /* Lower IRQL back */
54 }
55}
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID NTAPI ExNotifyCallback(IN PCALLBACK_OBJECT CallbackObject, IN PVOID Argument1, IN PVOID Argument2)
Definition: callback.c:467
PCALLBACK_OBJECT SetSystemTimeCallback
Definition: callback.c:27
PKWIN32_POWEREVENT_CALLOUT PopEventCallout
Definition: events.c:32
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by ExpSetTimeZoneInformation(), NtSetSystemTime(), and Phase1InitializationDiscard().

◆ PopAddRemoveSysCapsCallback()

NTSTATUS NTAPI PopAddRemoveSysCapsCallback ( IN PVOID  NotificationStructure,
IN PVOID  Context 
)

Definition at line 147 of file events.c.

149{
151 PSYS_BUTTON_CONTEXT SysButtonContext;
156 PIRP Irp;
159 BOOLEAN Arrival;
160 ULONG Caps;
163
164 DPRINT("PopAddRemoveSysCapsCallback(%p %p)\n",
166
168 if (Notification->Version != 1)
172 if (RtlCompareMemory(&Notification->Event, &GUID_DEVICE_INTERFACE_ARRIVAL, sizeof(GUID)) == sizeof(GUID))
173 Arrival = TRUE;
174 else if (RtlCompareMemory(&Notification->Event, &GUID_DEVICE_INTERFACE_REMOVAL, sizeof(GUID)) == sizeof(GUID))
175 Arrival = FALSE;
176 else
178
179 if (Arrival && DeviceType == PolicyDeviceBattery)
180 {
182 return STATUS_SUCCESS;
183 }
184
185 if (Arrival)
186 {
187 DPRINT("Arrival of %wZ\n", Notification->SymbolicLinkName);
188
189 /* Open the device */
191 Notification->SymbolicLinkName,
193 NULL,
194 NULL);
200 0);
201 if (!NT_SUCCESS(Status))
202 {
203 DPRINT1("ZwOpenFile() failed with status 0x%08lx\n", Status);
204 return Status;
205 }
210 (PVOID*)&FileObject,
211 NULL);
212 if (!NT_SUCCESS(Status))
213 {
214 DPRINT1("ObReferenceObjectByHandle() failed with status 0x%08lx\n", Status);
216 return Status;
217 }
220
221 /* Get capabilities (IOCTL_GET_SYS_BUTTON_CAPS) */
225 NULL,
226 0,
227 &Caps,
228 sizeof(Caps),
229 FALSE,
230 &Event,
232 if (!Irp)
233 {
234 DPRINT1("IoBuildDeviceIoControlRequest() failed\n");
237 }
239 if (Status == STATUS_PENDING)
240 {
241 DPRINT("IOCTL_GET_SYS_BUTTON_CAPS pending\n");
244 }
245 if (!NT_SUCCESS(Status))
246 {
247 DPRINT1("Sending IOCTL_GET_SYS_BUTTON_CAPS failed with status 0x%08x\n", Status);
250 }
251
252 DPRINT("Device capabilities: 0x%x\n", Caps);
253 if (Caps & SYS_BUTTON_POWER)
254 {
255 DPRINT("POWER button present\n");
257 }
258
259 if (Caps & SYS_BUTTON_SLEEP)
260 {
261 DPRINT("SLEEP button present\n");
263 }
264
265 if (Caps & SYS_BUTTON_LID)
266 {
267 DPRINT("LID present\n");
269 }
270
271 SysButtonContext = ExAllocatePoolWithTag(NonPagedPool,
272 sizeof(SYS_BUTTON_CONTEXT),
273 'IWOP');
274 if (!SysButtonContext)
275 {
276 DPRINT1("ExAllocatePoolWithTag() failed\n");
279 }
280
281 /* Queue a work item to get sys button event */
282 SysButtonContext->WorkItem = IoAllocateWorkItem(DeviceObject);
283 SysButtonContext->DeviceObject = DeviceObject;
284 if (!SysButtonContext->WorkItem)
285 {
286 DPRINT1("IoAllocateWorkItem() failed\n");
288 ExFreePoolWithTag(SysButtonContext, 'IWOP');
290 }
291 IoQueueWorkItem(SysButtonContext->WorkItem,
294 SysButtonContext);
295
297 return STATUS_SUCCESS;
298 }
299 else
300 {
301 DPRINT1("Removal of a power capable device not implemented\n");
303 }
304}
#define DPRINT1
Definition: precomp.h:8
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define FILE_SHARE_READ
Definition: compat.h:136
const GUID GUID_DEVICE_INTERFACE_ARRIVAL
Definition: deviface.c:14
const GUID GUID_DEVICE_INTERFACE_REMOVAL
Definition: deviface.c:15
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NonPagedPool
Definition: env_spec_w32.h:307
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
DeviceType
Definition: mmdrv.h:42
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI ZwOpenFile(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _Out_ PIO_STATUS_BLOCK IoStatusBlock, _In_ ULONG ShareAccess, _In_ ULONG OpenOptions)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_READ_DATA
Definition: nt_native.h:628
@ NotificationEvent
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define IoCallDriver
Definition: irp.c:1225
static VOID NTAPI PopGetSysButton(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
Definition: events.c:107
#define STATUS_REVISION_MISMATCH
Definition: ntstatus.h:325
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
SYSTEM_POWER_CAPABILITIES PopCapabilities
Definition: power.c:29
#define SYS_BUTTON_SLEEP
Definition: poclass.h:84
#define SYS_BUTTON_POWER
Definition: poclass.h:83
#define IOCTL_GET_SYS_BUTTON_CAPS
Definition: poclass.h:59
#define SYS_BUTTON_LID
Definition: poclass.h:85
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
BOOLEAN SystemBatteriesPresent
Definition: ntpoapi.h:374
PIO_WORKITEM WorkItem
Definition: events.c:20
PDEVICE_OBJECT DeviceObject
Definition: events.c:19
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PWDFDEVICE_INIT _In_ PFN_WDF_DEVICE_SHUTDOWN_NOTIFICATION Notification
Definition: wdfcontrol.h:115
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
@ DelayedWorkQueue
Definition: extypes.h:190
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1206
struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION * PDEVICE_INTERFACE_CHANGE_NOTIFICATION
* PFILE_OBJECT
Definition: iotypes.h:1998
@ Suspended
Definition: ketypes.h:420
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by PoInitSystem().

◆ PopCleanupPowerState()

VOID NTAPI PopCleanupPowerState ( IN PPOWER_STATE  PowerState)

Definition at line 164 of file power.c.

165{
166 //UNIMPLEMENTED;
167}

Referenced by PspExitProcess(), and PspExitThread().

◆ PopFlushVolumes()

VOID NTAPI PopFlushVolumes ( IN BOOLEAN  ShuttingDown)

Definition at line 227 of file povolume.c.

228{
229 POP_FLUSH_VOLUME FlushContext = {{0}};
230 ULONG FlushPolicy;
231 UNICODE_STRING RegistryName = RTL_CONSTANT_STRING(L"\\Registry");
233 HANDLE RegistryHandle;
234 PLIST_ENTRY NextEntry;
236 ULONG VolumeCount = 0;
238 HANDLE ThreadHandle;
239 ULONG ThreadCount;
240
241 /* Setup the flush context */
242 InitializeListHead(&FlushContext.List);
244
245 /* What to flush */
246 FlushPolicy = ShuttingDown ? 1 | 2 : PopFlushPolicy;
247 if ((FlushPolicy & 1))
248 {
249 /* Registry flush requested, so open it */
250 DPRINT("Opening registry\n");
252 &RegistryName,
254 NULL,
255 NULL);
256 Status = ZwOpenKey(&RegistryHandle, KEY_READ, &ObjectAttributes);
257 if (NT_SUCCESS(Status))
258 {
259 /* Flush the registry */
260 DPRINT("Flushing registry\n");
261 ZwFlushKey(RegistryHandle);
262 ZwClose(RegistryHandle);
263 }
264 }
265
266 /* Serialize with other flushes */
268
269 /* Scan the volume list */
270 NextEntry = PopVolumeDevices.Flink;
271 while (NextEntry != &PopVolumeDevices)
272 {
273 /* Get the dope from the link */
275
276 /* Grab the next entry now, since we'll be modifying the list */
277 NextEntry = NextEntry->Flink;
278
279 /* Make sure the object is mounted, writable, exists, and is not a floppy */
280 if (!(Dope->DeviceObject->Vpb->Flags & VPB_MOUNTED) ||
281 (Dope->DeviceObject->Characteristics & FILE_FLOPPY_DISKETTE) ||
282 (Dope->DeviceObject->Characteristics & FILE_READ_ONLY_DEVICE) ||
283 ((Dope->DeviceObject->Vpb->RealDevice) &&
284 (Dope->DeviceObject->Vpb->RealDevice->Characteristics & FILE_FLOPPY_DISKETTE)))
285 {
286 /* Not flushable */
287 continue;
288 }
289
290 /* Remove it from the dope and add it to the flush context list */
291 RemoveEntryList(&Dope->Volume);
292 InsertTailList(&FlushContext.List, &Dope->Volume);
293
294 /* Next */
295 VolumeCount++;
296 }
297
298 /* Check if we should skip non-removable devices */
299 if (!(FlushPolicy & 2))
300 {
301 /* ReactOS only implements this routine for shutdown, which requires it */
303 }
304
305 /* Check if there were no volumes at all */
306 if (!VolumeCount)
307 {
308 /* Nothing to do */
310 return;
311 }
312
313 /* Allocate up to 8 flusher threads */
314 ThreadCount = min(VolumeCount, 8);
316 NULL,
318 NULL,
319 NULL);
320
321 /* We will ourselves become a flusher thread */
322 FlushContext.Count = 1;
323 ThreadCount--;
324
325 /* Look for any extra ones we might need */
326 while (ThreadCount > 0)
327 {
328 /* Create a new one */
329 ThreadCount--;
330 DPRINT("Creating flush thread\n");
331 Status = PsCreateSystemThread(&ThreadHandle,
334 0L,
335 NULL,
337 &FlushContext);
338 if (NT_SUCCESS(Status))
339 {
340 /* One more created... */
341 FlushContext.Count++;
342 ZwClose(ThreadHandle);
343 }
344 }
345
346 /* Allow flushes to go through */
348
349 /* Enter the flush work */
350 DPRINT("Local flush\n");
351 PopFlushVolumeWorker(&FlushContext);
352
353 /* Wait for all flushes to be over */
354 DPRINT("Waiting for flushes\n");
356 DPRINT("Flushes have completed\n");
357}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
UNICODE_STRING Volume
Definition: fltkernel.h:1172
#define min(a, b)
Definition: monoChain.cc:55
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
#define KEY_READ
Definition: nt_native.h:1023
#define FILE_READ_ONLY_DEVICE
Definition: nt_native.h:808
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
#define L(x)
Definition: ntvdm.h:50
LIST_ENTRY PopVolumeDevices
Definition: povolume.c:27
ULONG PopFlushPolicy
Definition: povolume.c:24
VOID NTAPI PopFlushVolumeWorker(IN PVOID Context)
Definition: povolume.c:148
KGUARDED_MUTEX PopVolumeLock
Definition: povolume.c:26
PDEVICE_OBJECT DeviceObject
Definition: po.h:262
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY List
Definition: povolume.c:19
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define VPB_MOUNTED
Definition: iotypes.h:1807
@ Executive
Definition: ketypes.h:415

Referenced by NtSetSystemPowerState().

◆ PopGracefulShutdown()

VOID NTAPI PopGracefulShutdown ( IN PVOID  Context)

Definition at line 232 of file poshtdwn.c.

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}
VOID NTAPI CcShutdownSystem(VOID)
Definition: cachesub.c:299
VOID NTAPI CmShutdownSystem(VOID)
Definition: cmsysini.c:2146
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
NTSTATUS NTAPI CcWaitForCurrentLazyWriterActivity(VOID)
Definition: lazyrite.c:30
#define HalSetWakeEnable
Definition: halfuncs.h:39
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
POP_POWER_ACTION PopAction
Definition: power.c:27
VOID NTAPI PopProcessShutDownLists(VOID)
Definition: poshtdwn.c:103
VOID NTAPI PopShutdownSystem(IN POWER_ACTION SystemAction)
Definition: poshtdwn.c:177
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
POWER_ACTION Action
Definition: po.h:229
#define HalEndOfBoot
Definition: haltypes.h:307

Referenced by NtSetSystemPowerState().

◆ PopInitShutdownList()

VOID NTAPI PopInitShutdownList ( VOID  )

Definition at line 35 of file poshtdwn.c.

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}
KEVENT PopShutdownEvent
Definition: poshtdwn.c:24
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

Referenced by PoInitSystem().

◆ PopReadShutdownPolicy()

VOID NTAPI PopReadShutdownPolicy ( VOID  )

Definition at line 303 of file poshtdwn.c.

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}
Definition: bufpool.h:45
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
@ KeyValuePartialInformation
Definition: nt_native.h:1182
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
ULONG PopShutdownPowerOffPolicy
Definition: poshtdwn.c:23
#define REG_DWORD
Definition: sdbapi.c:596
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by NtSetSystemPowerState().

◆ PopSetSystemPowerState()

NTSTATUS NTAPI PopSetSystemPowerState ( SYSTEM_POWER_STATE  PowerState,
POWER_ACTION  PowerAction 
)

Definition at line 332 of file power.c.

333{
338 POWER_STATE_TRAVERSE_CONTEXT PowerContext;
339
341 if (!NT_SUCCESS(Status))
342 {
343 DPRINT1("No system power driver available\n");
344 Fdo = NULL;
345 }
346 else
347 {
349 if (Fdo == DeviceObject)
350 {
351 DPRINT("An FDO was not attached\n");
352 return STATUS_UNSUCCESSFUL;
353 }
354 }
355
356 /* Set up context */
357 PowerContext.PowerAction = PowerAction;
358 PowerContext.SystemPowerState = PowerState;
359 PowerContext.PowerDevice = Fdo;
360
361 /* Query for system power change */
365 &PowerContext);
366
368 if (!NT_SUCCESS(Status))
369 {
370 DPRINT1("Query system power state failed; changing state anyway\n");
371 }
372
373 /* Set system power change */
377 &PowerContext);
378
380
382
383 if (Fdo != NULL)
384 {
385 if (PowerAction != PowerActionShutdownReset)
387
389 }
390
391 return Status;
392}
#define IopInitDeviceTreeTraverseContext( _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context)
Definition: io.h:229
NTSTATUS IopGetSystemPowerDeviceObject(IN PDEVICE_OBJECT *DeviceObject)
NTSTATUS IopTraverseDeviceTree(PDEVICETREE_TRAVERSE_CONTEXT Context)
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
NTSTATUS PopSetSystemPowerStateTraverse(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: power.c:288
NTSTATUS PopSendSetSystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
Definition: power.c:212
NTSTATUS PopQuerySystemPowerStateTraverse(PDEVICE_NODE DeviceNode, PVOID Context)
Definition: power.c:254
@ PowerActionShutdownReset
Definition: ntpoapi.h:128
SYSTEM_POWER_STATE SystemPowerState
Definition: power.c:20
POWER_ACTION PowerAction
Definition: power.c:21
PDEVICE_OBJECT PowerDevice
Definition: power.c:22
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3034
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461

Referenced by PopShutdownSystem().

◆ PoRemoveVolumeDevice()

VOID NTAPI PoRemoveVolumeDevice ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 103 of file povolume.c.

104{
106 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
108 PAGED_CODE();
109
110 /* If the device already has the dope, return it */
111 DeviceExtension = IoGetDevObjExtension(DeviceObject);
112 if (!DeviceExtension->Dope)
113 {
114 /* no dope */
115 return;
116 }
117
118 /* Make sure we can flush safely */
120
121 /* Get dope from device */
122 Dope = (PDEVICE_OBJECT_POWER_EXTENSION)DeviceExtension->Dope;
123
124 if (Dope->Volume.Flink)
125 {
126 /* Remove from volume from list */
127 RemoveEntryList(&Dope->Volume);
128 }
129
130 /* Allow flushes to go through */
132
133 /* Now remove dope from device object */
135
136 /* remove from dev obj */
137 DeviceExtension->Dope = NULL;
138
139 /* Release lock */
141
142 /* Free dope */
144}
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
if(dx< 0)
Definition: linetemp.h:194
#define IoGetDevObjExtension(DeviceObject)
Definition: io.h:129
struct _DEVICE_OBJECT_POWER_EXTENSION * PDEVICE_OBJECT_POWER_EXTENSION
KSPIN_LOCK PopDopeGlobalLock
Definition: povolume.c:28
#define TAG_PO_DOPE
Definition: tag.h:129

Referenced by IoDeleteDevice().

◆ PoVolumeDevice()

VOID NTAPI PoVolumeDevice ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 81 of file povolume.c.

82{
84 PAGED_CODE();
85
86 /* Get dope from the device (if the device has no dope, it will receive some) */
88 if (Dope)
89 {
90 /* Make sure we can flush safely */
92
93 /* Add this volume into the list of power-manager volumes */
95
96 /* Allow flushes to go through */
98 }
99}
PDEVICE_OBJECT_POWER_EXTENSION NTAPI PopGetDope(IN PDEVICE_OBJECT DeviceObject)
Definition: povolume.c:34

Referenced by IoCreateDevice(), and IoVerifyVolume().

Variable Documentation

◆ PopAction

POP_POWER_ACTION PopAction
extern

Definition at line 27 of file power.c.

Referenced by NtSetSystemPowerState(), and PopGracefulShutdown().

◆ PopCapabilities

SYSTEM_POWER_CAPABILITIES PopCapabilities
extern

Definition at line 29 of file power.c.

Referenced by NtPowerInformation(), PoInitSystem(), and PopAddRemoveSysCapsCallback().

◆ PopDopeGlobalLock

KSPIN_LOCK PopDopeGlobalLock
extern

Definition at line 28 of file povolume.c.

Referenced by PoInitSystem(), PopGetDope(), and PoRemoveVolumeDevice().

◆ PopSystemPowerDeviceNode

PDEVICE_NODE PopSystemPowerDeviceNode
extern

Definition at line 25 of file power.c.

Referenced by IopGetSystemPowerDeviceObject(), and PiCallDriverAddDevice().

◆ PopVolumeDevices

LIST_ENTRY PopVolumeDevices
extern

Definition at line 27 of file povolume.c.

Referenced by PoInitSystem(), PopFlushVolumes(), PopFlushVolumeWorker(), and PoVolumeDevice().

◆ PopVolumeLock

KGUARDED_MUTEX PopVolumeLock
extern