2008-03-09 14:11:42 +00:00
|
|
|
|
/*
|
2008-08-18 09:49:28 +00:00
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2001-04-16 00:51:19 +00:00
|
|
|
|
* FILE: ntoskrnl/po/power.c
|
|
|
|
|
* PURPOSE: Power Manager
|
2005-01-26 13:58:37 +00:00
|
|
|
|
* PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
|
2020-11-06 08:39:31 +00:00
|
|
|
|
* Herv<EFBFBD> Poussineau (hpoussin@reactos.com)
|
1999-08-20 16:31:17 +00:00
|
|
|
|
*/
|
2001-05-01 23:08:21 +00:00
|
|
|
|
|
2008-08-18 09:49:28 +00:00
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
|
#include <ntoskrnl.h>
|
2001-05-01 23:08:21 +00:00
|
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
|
#include <debug.h>
|
2001-05-01 23:08:21 +00:00
|
|
|
|
|
2008-08-18 09:49:28 +00:00
|
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
typedef struct _POWER_STATE_TRAVERSE_CONTEXT
|
|
|
|
|
{
|
|
|
|
|
SYSTEM_POWER_STATE SystemPowerState;
|
|
|
|
|
POWER_ACTION PowerAction;
|
|
|
|
|
PDEVICE_OBJECT PowerDevice;
|
|
|
|
|
} POWER_STATE_TRAVERSE_CONTEXT, *PPOWER_STATE_TRAVERSE_CONTEXT;
|
|
|
|
|
|
2001-05-01 23:08:21 +00:00
|
|
|
|
PDEVICE_NODE PopSystemPowerDeviceNode = NULL;
|
2005-03-12 00:49:18 +00:00
|
|
|
|
BOOLEAN PopAcpiPresent = FALSE;
|
2010-03-08 20:47:10 +00:00
|
|
|
|
POP_POWER_ACTION PopAction;
|
|
|
|
|
WORK_QUEUE_ITEM PopShutdownWorkItem;
|
2019-04-07 14:41:56 +00:00
|
|
|
|
SYSTEM_POWER_CAPABILITIES PopCapabilities;
|
2001-05-01 23:08:21 +00:00
|
|
|
|
|
2008-08-18 09:49:28 +00:00
|
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
1999-08-20 16:31:17 +00:00
|
|
|
|
|
2020-02-23 15:18:18 +00:00
|
|
|
|
static WORKER_THREAD_ROUTINE PopPassivePowerCall;
|
|
|
|
|
_Use_decl_annotations_
|
|
|
|
|
static
|
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
PopPassivePowerCall(
|
|
|
|
|
PVOID Parameter)
|
|
|
|
|
{
|
|
|
|
|
PIRP Irp = Parameter;
|
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
|
|
|
|
|
|
ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
|
|
|
|
|
|
|
|
|
|
_Analysis_assume_(Irp != NULL);
|
|
|
|
|
IoStack = IoGetNextIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
|
|
(VOID)IoCallDriver(IoStack->DeviceObject, Irp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_IRQL_requires_max_(DISPATCH_LEVEL)
|
|
|
|
|
_IRQL_requires_same_
|
|
|
|
|
static
|
|
|
|
|
NTSTATUS
|
|
|
|
|
PopPresentIrp(
|
|
|
|
|
_In_ PIO_STACK_LOCATION NextStack,
|
|
|
|
|
_In_ PIRP Irp)
|
|
|
|
|
{
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
BOOLEAN CallAtPassiveLevel;
|
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
|
PWORK_QUEUE_ITEM WorkQueueItem;
|
|
|
|
|
|
|
|
|
|
ASSERT(NextStack->MajorFunction == IRP_MJ_POWER);
|
|
|
|
|
|
|
|
|
|
DeviceObject = NextStack->DeviceObject;
|
|
|
|
|
|
|
|
|
|
/* Determine whether the IRP must be handled at PASSIVE_LEVEL.
|
|
|
|
|
* Only SET_POWER to working state can happen at raised IRQL. */
|
|
|
|
|
CallAtPassiveLevel = TRUE;
|
|
|
|
|
if ((NextStack->MinorFunction == IRP_MN_SET_POWER) &&
|
|
|
|
|
!(DeviceObject->Flags & DO_POWER_PAGABLE))
|
|
|
|
|
{
|
|
|
|
|
if (NextStack->Parameters.Power.Type == DevicePowerState &&
|
|
|
|
|
NextStack->Parameters.Power.State.DeviceState == PowerDeviceD0)
|
|
|
|
|
{
|
|
|
|
|
CallAtPassiveLevel = FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (NextStack->Parameters.Power.Type == SystemPowerState &&
|
|
|
|
|
NextStack->Parameters.Power.State.SystemState == PowerSystemWorking)
|
|
|
|
|
{
|
|
|
|
|
CallAtPassiveLevel = FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CallAtPassiveLevel)
|
|
|
|
|
{
|
|
|
|
|
/* We need to fit a work item into the DriverContext below */
|
|
|
|
|
C_ASSERT(sizeof(Irp->Tail.Overlay.DriverContext) >= sizeof(WORK_QUEUE_ITEM));
|
|
|
|
|
|
|
|
|
|
if (KeGetCurrentIrql() == PASSIVE_LEVEL)
|
|
|
|
|
{
|
|
|
|
|
/* Already at passive, call next driver directly */
|
|
|
|
|
return IoCallDriver(DeviceObject, Irp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Need to schedule a work item and return pending */
|
|
|
|
|
NextStack->Control |= SL_PENDING_RETURNED;
|
|
|
|
|
|
|
|
|
|
WorkQueueItem = (PWORK_QUEUE_ITEM)&Irp->Tail.Overlay.DriverContext;
|
|
|
|
|
ExInitializeWorkItem(WorkQueueItem,
|
|
|
|
|
PopPassivePowerCall,
|
|
|
|
|
Irp);
|
|
|
|
|
ExQueueWorkItem(WorkQueueItem, DelayedWorkQueue);
|
|
|
|
|
|
|
|
|
|
return STATUS_PENDING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Direct call. Raise IRQL in debug to catch invalid paged memory access. */
|
|
|
|
|
#if DBG
|
|
|
|
|
{
|
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
Status = IoCallDriver(DeviceObject, Irp);
|
|
|
|
|
|
|
|
|
|
#if DBG
|
|
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-10 19:45:01 +00:00
|
|
|
|
static IO_COMPLETION_ROUTINE PopRequestPowerIrpCompletion;
|
|
|
|
|
|
2005-07-02 14:50:22 +00:00
|
|
|
|
static
|
2007-07-04 08:26:47 +00:00
|
|
|
|
NTSTATUS
|
2008-08-18 09:49:28 +00:00
|
|
|
|
NTAPI
|
2021-05-10 19:45:01 +00:00
|
|
|
|
PopRequestPowerIrpCompletion(
|
|
|
|
|
_In_ PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
_In_ PIRP Irp,
|
|
|
|
|
_In_reads_opt_(_Inexpressible_("varies")) PVOID Context)
|
2005-07-02 14:50:22 +00:00
|
|
|
|
{
|
2007-07-04 08:26:47 +00:00
|
|
|
|
PIO_STACK_LOCATION Stack;
|
2015-10-11 19:57:06 +00:00
|
|
|
|
PREQUEST_POWER_COMPLETE CompletionRoutine;
|
|
|
|
|
POWER_STATE PowerState;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2015-10-11 19:57:06 +00:00
|
|
|
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
CompletionRoutine = Context;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2015-10-11 19:57:06 +00:00
|
|
|
|
PowerState.DeviceState = (ULONG_PTR)Stack->Parameters.Others.Argument3;
|
2021-05-10 19:45:01 +00:00
|
|
|
|
|
|
|
|
|
if (CompletionRoutine)
|
|
|
|
|
{
|
|
|
|
|
CompletionRoutine(Stack->Parameters.Others.Argument1,
|
|
|
|
|
(UCHAR)(ULONG_PTR)Stack->Parameters.Others.Argument2,
|
|
|
|
|
PowerState,
|
|
|
|
|
Stack->Parameters.Others.Argument4,
|
|
|
|
|
&Irp->IoStatus);
|
|
|
|
|
}
|
2010-03-20 16:48:00 +00:00
|
|
|
|
|
2015-10-11 19:57:06 +00:00
|
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
2010-03-20 16:48:00 +00:00
|
|
|
|
IoFreeIrp(Irp);
|
2015-10-11 19:57:06 +00:00
|
|
|
|
ObDereferenceObject(DeviceObject);
|
2010-03-20 16:48:00 +00:00
|
|
|
|
|
2010-09-08 21:30:40 +00:00
|
|
|
|
return STATUS_MORE_PROCESSING_REQUIRED;
|
2005-07-02 14:50:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
PopCleanupPowerState(IN PPOWER_STATE PowerState)
|
|
|
|
|
{
|
2007-07-04 08:26:47 +00:00
|
|
|
|
//UNIMPLEMENTED;
|
2006-07-09 18:54:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-05-01 23:08:21 +00:00
|
|
|
|
NTSTATUS
|
2011-06-19 04:25:33 +00:00
|
|
|
|
PopSendQuerySystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
|
2005-05-09 01:38:29 +00:00
|
|
|
|
{
|
2011-06-19 04:25:33 +00:00
|
|
|
|
KEVENT Event;
|
2007-07-04 08:26:47 +00:00
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
|
PIO_STACK_LOCATION IrpSp;
|
|
|
|
|
PIRP Irp;
|
2011-06-19 04:25:33 +00:00
|
|
|
|
NTSTATUS Status;
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
KeInitializeEvent(&Event,
|
|
|
|
|
NotificationEvent,
|
|
|
|
|
FALSE);
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_POWER,
|
|
|
|
|
DeviceObject,
|
|
|
|
|
NULL,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
&Event,
|
|
|
|
|
&IoStatusBlock);
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
|
if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
IrpSp = IoGetNextIrpStackLocation(Irp);
|
|
|
|
|
IrpSp->MinorFunction = IRP_MN_QUERY_POWER;
|
|
|
|
|
IrpSp->Parameters.Power.Type = SystemPowerState;
|
|
|
|
|
IrpSp->Parameters.Power.State.SystemState = SystemState;
|
|
|
|
|
IrpSp->Parameters.Power.ShutdownType = PowerAction;
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
Status = PoCallDriver(DeviceObject, Irp);
|
|
|
|
|
if (Status == STATUS_PENDING)
|
2001-05-01 23:08:21 +00:00
|
|
|
|
{
|
2011-06-19 04:25:33 +00:00
|
|
|
|
KeWaitForSingleObject(&Event,
|
|
|
|
|
Executive,
|
|
|
|
|
KernelMode,
|
|
|
|
|
FALSE,
|
|
|
|
|
NULL);
|
|
|
|
|
Status = IoStatusBlock.Status;
|
2001-05-01 23:08:21 +00:00
|
|
|
|
}
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
2001-05-01 23:08:21 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
NTSTATUS
|
|
|
|
|
PopSendSetSystemPowerState(PDEVICE_OBJECT DeviceObject, SYSTEM_POWER_STATE SystemState, POWER_ACTION PowerAction)
|
|
|
|
|
{
|
|
|
|
|
KEVENT Event;
|
|
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
|
PIO_STACK_LOCATION IrpSp;
|
|
|
|
|
PIRP Irp;
|
|
|
|
|
NTSTATUS Status;
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
|
|
2007-07-04 08:26:47 +00:00
|
|
|
|
KeInitializeEvent(&Event,
|
|
|
|
|
NotificationEvent,
|
|
|
|
|
FALSE);
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
|
|
2007-07-04 08:26:47 +00:00
|
|
|
|
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_POWER,
|
2011-06-19 04:25:33 +00:00
|
|
|
|
DeviceObject,
|
2007-07-04 08:26:47 +00:00
|
|
|
|
NULL,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
&Event,
|
|
|
|
|
&IoStatusBlock);
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
|
if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
2007-07-04 08:26:47 +00:00
|
|
|
|
IrpSp = IoGetNextIrpStackLocation(Irp);
|
|
|
|
|
IrpSp->MinorFunction = IRP_MN_SET_POWER;
|
|
|
|
|
IrpSp->Parameters.Power.Type = SystemPowerState;
|
2011-06-19 04:25:33 +00:00
|
|
|
|
IrpSp->Parameters.Power.State.SystemState = SystemState;
|
|
|
|
|
IrpSp->Parameters.Power.ShutdownType = PowerAction;
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
Status = PoCallDriver(DeviceObject, Irp);
|
2007-07-04 08:26:47 +00:00
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
|
{
|
|
|
|
|
KeWaitForSingleObject(&Event,
|
|
|
|
|
Executive,
|
|
|
|
|
KernelMode,
|
|
|
|
|
FALSE,
|
|
|
|
|
NULL);
|
2011-06-19 04:25:33 +00:00
|
|
|
|
Status = IoStatusBlock.Status;
|
|
|
|
|
}
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
|
PopQuerySystemPowerStateTraverse(PDEVICE_NODE DeviceNode,
|
|
|
|
|
PVOID Context)
|
|
|
|
|
{
|
|
|
|
|
PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
|
2016-07-27 11:15:52 +00:00
|
|
|
|
PDEVICE_OBJECT TopDeviceObject;
|
2011-06-19 04:25:33 +00:00
|
|
|
|
NTSTATUS Status;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
DPRINT("PopQuerySystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
if (DeviceNode == IopRootDeviceNode)
|
|
|
|
|
return STATUS_SUCCESS;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
2016-07-27 11:15:52 +00:00
|
|
|
|
TopDeviceObject = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
|
|
|
|
|
|
|
|
|
|
Status = PopSendQuerySystemPowerState(TopDeviceObject,
|
2011-06-19 04:25:33 +00:00
|
|
|
|
PowerStateContext->SystemPowerState,
|
|
|
|
|
PowerStateContext->PowerAction);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("Device '%wZ' failed IRP_MN_QUERY_POWER\n", &DeviceNode->InstancePath);
|
|
|
|
|
}
|
2016-07-27 11:15:52 +00:00
|
|
|
|
ObDereferenceObject(TopDeviceObject);
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
#if 0
|
|
|
|
|
return Status;
|
|
|
|
|
#else
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
|
PopSetSystemPowerStateTraverse(PDEVICE_NODE DeviceNode,
|
|
|
|
|
PVOID Context)
|
|
|
|
|
{
|
|
|
|
|
PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
|
2016-07-27 11:15:52 +00:00
|
|
|
|
PDEVICE_OBJECT TopDeviceObject;
|
2011-06-19 04:25:33 +00:00
|
|
|
|
NTSTATUS Status;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
DPRINT("PopSetSystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
if (DeviceNode == IopRootDeviceNode)
|
|
|
|
|
return STATUS_SUCCESS;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
if (DeviceNode->PhysicalDeviceObject == PowerStateContext->PowerDevice)
|
|
|
|
|
return STATUS_SUCCESS;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
2016-07-27 11:15:52 +00:00
|
|
|
|
TopDeviceObject = IoGetAttachedDeviceReference(DeviceNode->PhysicalDeviceObject);
|
|
|
|
|
if (TopDeviceObject == PowerStateContext->PowerDevice)
|
|
|
|
|
{
|
|
|
|
|
ObDereferenceObject(TopDeviceObject);
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Status = PopSendSetSystemPowerState(TopDeviceObject,
|
2011-06-19 04:25:33 +00:00
|
|
|
|
PowerStateContext->SystemPowerState,
|
|
|
|
|
PowerStateContext->PowerAction);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("Device '%wZ' failed IRP_MN_SET_POWER\n", &DeviceNode->InstancePath);
|
2001-05-01 23:08:21 +00:00
|
|
|
|
}
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2016-07-27 11:15:52 +00:00
|
|
|
|
ObDereferenceObject(TopDeviceObject);
|
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
#if 0
|
|
|
|
|
return Status;
|
|
|
|
|
#else
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
|
|
|
|
PopSetSystemPowerState(SYSTEM_POWER_STATE PowerState, POWER_ACTION PowerAction)
|
|
|
|
|
{
|
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
|
PDEVICE_OBJECT Fdo;
|
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
DEVICETREE_TRAVERSE_CONTEXT Context;
|
|
|
|
|
POWER_STATE_TRAVERSE_CONTEXT PowerContext;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
Status = IopGetSystemPowerDeviceObject(&DeviceObject);
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
|
if (!NT_SUCCESS(Status))
|
2011-06-19 04:25:33 +00:00
|
|
|
|
{
|
|
|
|
|
DPRINT1("No system power driver available\n");
|
|
|
|
|
Fdo = NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Fdo = IoGetAttachedDeviceReference(DeviceObject);
|
|
|
|
|
if (Fdo == DeviceObject)
|
|
|
|
|
{
|
|
|
|
|
DPRINT("An FDO was not attached\n");
|
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
/* Set up context */
|
|
|
|
|
PowerContext.PowerAction = PowerAction;
|
|
|
|
|
PowerContext.SystemPowerState = PowerState;
|
|
|
|
|
PowerContext.PowerDevice = Fdo;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
/* Query for system power change */
|
|
|
|
|
IopInitDeviceTreeTraverseContext(&Context,
|
|
|
|
|
IopRootDeviceNode,
|
|
|
|
|
PopQuerySystemPowerStateTraverse,
|
|
|
|
|
&PowerContext);
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
Status = IopTraverseDeviceTree(&Context);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("Query system power state failed; changing state anyway\n");
|
|
|
|
|
}
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
/* Set system power change */
|
|
|
|
|
IopInitDeviceTreeTraverseContext(&Context,
|
|
|
|
|
IopRootDeviceNode,
|
|
|
|
|
PopSetSystemPowerStateTraverse,
|
|
|
|
|
&PowerContext);
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
IopTraverseDeviceTree(&Context);
|
2001-05-01 23:08:21 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
if (!PopAcpiPresent) return STATUS_NOT_IMPLEMENTED;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2011-06-19 04:25:33 +00:00
|
|
|
|
if (Fdo != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (PowerAction != PowerActionShutdownReset)
|
|
|
|
|
PopSendSetSystemPowerState(Fdo, PowerState, PowerAction);
|
|
|
|
|
|
|
|
|
|
ObDereferenceObject(Fdo);
|
|
|
|
|
}
|
2001-05-01 23:08:21 +00:00
|
|
|
|
|
2007-07-04 08:26:47 +00:00
|
|
|
|
return Status;
|
2001-05-01 23:08:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-06 19:44:01 +00:00
|
|
|
|
CODE_SEG("INIT")
|
2007-01-25 01:13:09 +00:00
|
|
|
|
BOOLEAN
|
2005-09-13 23:48:54 +00:00
|
|
|
|
NTAPI
|
2009-11-08 01:13:49 +00:00
|
|
|
|
PoInitSystem(IN ULONG BootPhase)
|
2001-05-01 23:08:21 +00:00
|
|
|
|
{
|
2006-10-08 04:47:26 +00:00
|
|
|
|
PVOID NotificationEntry;
|
|
|
|
|
PCHAR CommandLine;
|
|
|
|
|
BOOLEAN ForceAcpiDisable = FALSE;
|
2006-10-02 05:40:36 +00:00
|
|
|
|
|
2006-10-08 04:47:26 +00:00
|
|
|
|
/* Check if this is phase 1 init */
|
|
|
|
|
if (BootPhase == 1)
|
|
|
|
|
{
|
2021-06-17 15:52:12 +00:00
|
|
|
|
NTSTATUS Status;
|
2010-08-20 02:27:05 +00:00
|
|
|
|
/* Register power button notification */
|
2021-06-17 15:52:12 +00:00
|
|
|
|
Status = IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange,
|
|
|
|
|
PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES,
|
|
|
|
|
(PVOID)&GUID_DEVICE_SYS_BUTTON,
|
|
|
|
|
IopRootDeviceNode->PhysicalDeviceObject->DriverObject,
|
|
|
|
|
PopAddRemoveSysCapsCallback,
|
|
|
|
|
NULL,
|
|
|
|
|
&NotificationEntry);
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
|
return FALSE;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2010-08-20 02:27:05 +00:00
|
|
|
|
/* Register lid notification */
|
2021-06-17 15:52:12 +00:00
|
|
|
|
Status = IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange,
|
|
|
|
|
PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES,
|
|
|
|
|
(PVOID)&GUID_DEVICE_LID,
|
|
|
|
|
IopRootDeviceNode->PhysicalDeviceObject->DriverObject,
|
|
|
|
|
PopAddRemoveSysCapsCallback,
|
|
|
|
|
NULL,
|
|
|
|
|
&NotificationEntry);
|
|
|
|
|
return NT_SUCCESS(Status);
|
2006-10-08 04:47:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-07 14:41:56 +00:00
|
|
|
|
/* Initialize the power capabilities */
|
|
|
|
|
RtlZeroMemory(&PopCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES));
|
|
|
|
|
|
2006-10-08 04:47:26 +00:00
|
|
|
|
/* Get the Command Line */
|
|
|
|
|
CommandLine = KeLoaderBlock->LoadOptions;
|
2006-10-02 05:40:36 +00:00
|
|
|
|
|
2006-10-08 04:47:26 +00:00
|
|
|
|
/* Upcase it */
|
|
|
|
|
_strupr(CommandLine);
|
2006-10-02 05:40:36 +00:00
|
|
|
|
|
2006-10-08 04:47:26 +00:00
|
|
|
|
/* Check for ACPI disable */
|
|
|
|
|
if (strstr(CommandLine, "NOACPI")) ForceAcpiDisable = TRUE;
|
2006-09-12 15:19:51 +00:00
|
|
|
|
|
2006-10-08 04:47:26 +00:00
|
|
|
|
if (ForceAcpiDisable)
|
2005-03-15 23:02:51 +00:00
|
|
|
|
{
|
2006-10-08 04:47:26 +00:00
|
|
|
|
/* Set the ACPI State to False if it's been forced that way */
|
|
|
|
|
PopAcpiPresent = FALSE;
|
2005-03-15 23:02:51 +00:00
|
|
|
|
}
|
2006-10-08 04:47:26 +00:00
|
|
|
|
else
|
2005-03-15 23:02:51 +00:00
|
|
|
|
{
|
2009-11-08 01:13:49 +00:00
|
|
|
|
/* Otherwise check if the LoaderBlock has a ACPI Table */
|
|
|
|
|
PopAcpiPresent = KeLoaderBlock->Extension->AcpiTable != NULL ? TRUE : FALSE;
|
2005-03-15 23:02:51 +00:00
|
|
|
|
}
|
2007-01-25 01:13:09 +00:00
|
|
|
|
|
2019-04-07 14:41:56 +00:00
|
|
|
|
/* Enable shutdown by power button */
|
|
|
|
|
if (PopAcpiPresent)
|
|
|
|
|
PopCapabilities.SystemS5 = TRUE;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2010-03-08 20:47:10 +00:00
|
|
|
|
/* Initialize volume support */
|
|
|
|
|
InitializeListHead(&PopVolumeDevices);
|
|
|
|
|
KeInitializeGuardedMutex(&PopVolumeLock);
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2010-03-08 20:47:10 +00:00
|
|
|
|
/* Initialize support for dope */
|
|
|
|
|
KeInitializeSpinLock(&PopDopeGlobalLock);
|
2013-11-18 17:47:37 +00:00
|
|
|
|
|
|
|
|
|
/* Initialize support for shutdown waits and work-items */
|
|
|
|
|
PopInitShutdownList();
|
|
|
|
|
|
2007-01-25 01:13:09 +00:00
|
|
|
|
return TRUE;
|
2001-05-01 23:08:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-01 03:05:30 +00:00
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
PopPerfIdle(PPROCESSOR_POWER_STATE PowerState)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("PerfIdle function: %p\n", PowerState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
PopPerfIdleDpc(IN PKDPC Dpc,
|
|
|
|
|
IN PVOID DeferredContext,
|
|
|
|
|
IN PVOID SystemArgument1,
|
|
|
|
|
IN PVOID SystemArgument2)
|
|
|
|
|
{
|
|
|
|
|
/* Call the Perf Idle function */
|
|
|
|
|
PopPerfIdle(&((PKPRCB)DeferredContext)->PowerState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
FASTCALL
|
2006-09-11 06:50:19 +00:00
|
|
|
|
PopIdle0(IN PPROCESSOR_POWER_STATE PowerState)
|
2006-09-01 03:05:30 +00:00
|
|
|
|
{
|
2006-09-11 06:50:19 +00:00
|
|
|
|
/* FIXME: Extremly naive implementation */
|
|
|
|
|
HalProcessorIdle();
|
2006-09-01 03:05:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-06 19:44:01 +00:00
|
|
|
|
CODE_SEG("INIT")
|
2006-09-01 03:05:30 +00:00
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
PoInitializePrcb(IN PKPRCB Prcb)
|
|
|
|
|
{
|
|
|
|
|
/* Initialize the Power State */
|
|
|
|
|
RtlZeroMemory(&Prcb->PowerState, sizeof(Prcb->PowerState));
|
|
|
|
|
Prcb->PowerState.Idle0KernelTimeLimit = 0xFFFFFFFF;
|
|
|
|
|
Prcb->PowerState.CurrentThrottle = 100;
|
|
|
|
|
Prcb->PowerState.CurrentThrottleIndex = 0;
|
|
|
|
|
Prcb->PowerState.IdleFunction = PopIdle0;
|
|
|
|
|
|
|
|
|
|
/* Initialize the Perf DPC and Timer */
|
|
|
|
|
KeInitializeDpc(&Prcb->PowerState.PerfDpc, PopPerfIdleDpc, Prcb);
|
2006-09-11 06:50:19 +00:00
|
|
|
|
KeSetTargetProcessorDpc(&Prcb->PowerState.PerfDpc, Prcb->Number);
|
2006-09-01 03:05:30 +00:00
|
|
|
|
KeInitializeTimerEx(&Prcb->PowerState.PerfTimer, SynchronizationTimer);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-18 09:49:28 +00:00
|
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
|
|
2008-11-02 16:33:43 +00:00
|
|
|
|
/*
|
|
|
|
|
* @unimplemented
|
|
|
|
|
*/
|
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
|
|
|
|
PoCancelDeviceNotify(IN PVOID NotifyBlock)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @unimplemented
|
|
|
|
|
*/
|
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
|
|
|
|
PoRegisterDeviceNotify(OUT PVOID Unknown0,
|
|
|
|
|
IN ULONG Unknown1,
|
|
|
|
|
IN ULONG Unknown2,
|
|
|
|
|
IN ULONG Unknown3,
|
|
|
|
|
IN PVOID Unknown4,
|
|
|
|
|
IN PVOID Unknown5)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @unimplemented
|
|
|
|
|
*/
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("PoShutdownBugCheck called\n");
|
|
|
|
|
|
|
|
|
|
/* FIXME: Log error if requested */
|
|
|
|
|
/* FIXME: Initiate a shutdown */
|
|
|
|
|
|
|
|
|
|
/* Bugcheck the system */
|
|
|
|
|
KeBugCheckEx(BugCheckCode,
|
|
|
|
|
BugCheckParameter1,
|
|
|
|
|
BugCheckParameter2,
|
|
|
|
|
BugCheckParameter3,
|
|
|
|
|
BugCheckParameter4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @unimplemented
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
PoSetHiberRange(IN PVOID HiberContext,
|
|
|
|
|
IN ULONG Flags,
|
|
|
|
|
IN OUT PVOID StartPage,
|
|
|
|
|
IN ULONG Length,
|
|
|
|
|
IN ULONG PageTag)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-18 09:49:28 +00:00
|
|
|
|
/*
|
|
|
|
|
* @implemented
|
|
|
|
|
*/
|
2020-02-23 15:18:18 +00:00
|
|
|
|
_IRQL_requires_max_(DISPATCH_LEVEL)
|
2008-08-18 09:49:28 +00:00
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
2020-02-23 15:18:18 +00:00
|
|
|
|
PoCallDriver(
|
|
|
|
|
_In_ PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
_Inout_ __drv_aliasesMem PIRP Irp)
|
2008-08-18 09:49:28 +00:00
|
|
|
|
{
|
2020-02-23 15:18:18 +00:00
|
|
|
|
PIO_STACK_LOCATION NextStack;
|
2008-08-18 09:49:28 +00:00
|
|
|
|
|
2020-02-23 15:18:18 +00:00
|
|
|
|
ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
|
2008-08-18 09:49:28 +00:00
|
|
|
|
|
2020-02-23 15:18:18 +00:00
|
|
|
|
ASSERT(DeviceObject);
|
|
|
|
|
ASSERT(Irp);
|
|
|
|
|
|
|
|
|
|
NextStack = IoGetNextIrpStackLocation(Irp);
|
|
|
|
|
ASSERT(NextStack->MajorFunction == IRP_MJ_POWER);
|
|
|
|
|
|
|
|
|
|
/* Set DeviceObject for PopPresentIrp */
|
|
|
|
|
NextStack->DeviceObject = DeviceObject;
|
|
|
|
|
|
|
|
|
|
/* Only QUERY_POWER and SET_POWER use special handling */
|
|
|
|
|
if (NextStack->MinorFunction != IRP_MN_SET_POWER &&
|
|
|
|
|
NextStack->MinorFunction != IRP_MN_QUERY_POWER)
|
|
|
|
|
{
|
|
|
|
|
return IoCallDriver(DeviceObject, Irp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Call the next driver, either directly or at PASSIVE_LEVEL */
|
|
|
|
|
return PopPresentIrp(NextStack, Irp);
|
2008-08-18 09:49:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @unimplemented
|
|
|
|
|
*/
|
|
|
|
|
PULONG
|
|
|
|
|
NTAPI
|
|
|
|
|
PoRegisterDeviceForIdleDetection(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN ULONG ConservationIdleTime,
|
|
|
|
|
IN ULONG PerformanceIdleTime,
|
|
|
|
|
IN DEVICE_POWER_STATE State)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @unimplemented
|
|
|
|
|
*/
|
|
|
|
|
PVOID
|
|
|
|
|
NTAPI
|
|
|
|
|
PoRegisterSystemState(IN PVOID StateHandle,
|
|
|
|
|
IN EXECUTION_STATE Flags)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @implemented
|
|
|
|
|
*/
|
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
2021-05-10 19:45:01 +00:00
|
|
|
|
PoRequestPowerIrp(
|
|
|
|
|
_In_ PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
_In_ UCHAR MinorFunction,
|
|
|
|
|
_In_ POWER_STATE PowerState,
|
|
|
|
|
_In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction,
|
|
|
|
|
_In_opt_ __drv_aliasesMem PVOID Context,
|
|
|
|
|
_Outptr_opt_ PIRP *pIrp)
|
2008-08-18 09:49:28 +00:00
|
|
|
|
{
|
|
|
|
|
PDEVICE_OBJECT TopDeviceObject;
|
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
|
PIRP Irp;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2008-08-18 09:49:28 +00:00
|
|
|
|
if (MinorFunction != IRP_MN_QUERY_POWER
|
|
|
|
|
&& MinorFunction != IRP_MN_SET_POWER
|
|
|
|
|
&& MinorFunction != IRP_MN_WAIT_WAKE)
|
|
|
|
|
return STATUS_INVALID_PARAMETER_2;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2008-08-18 09:49:28 +00:00
|
|
|
|
/* Always call the top of the device stack */
|
|
|
|
|
TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2015-10-11 19:57:06 +00:00
|
|
|
|
Irp = IoAllocateIrp(TopDeviceObject->StackSize + 2, FALSE);
|
2008-08-18 09:49:28 +00:00
|
|
|
|
if (!Irp)
|
|
|
|
|
{
|
2012-03-06 22:06:44 +00:00
|
|
|
|
ObDereferenceObject(TopDeviceObject);
|
2008-08-18 09:49:28 +00:00
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
}
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2015-10-11 19:57:06 +00:00
|
|
|
|
Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
|
2008-08-18 09:49:28 +00:00
|
|
|
|
Irp->IoStatus.Information = 0;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2015-10-11 19:57:06 +00:00
|
|
|
|
IoSetNextIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
|
|
Stack = IoGetNextIrpStackLocation(Irp);
|
|
|
|
|
Stack->Parameters.Others.Argument1 = DeviceObject;
|
|
|
|
|
Stack->Parameters.Others.Argument2 = (PVOID)(ULONG_PTR)MinorFunction;
|
|
|
|
|
Stack->Parameters.Others.Argument3 = (PVOID)(ULONG_PTR)PowerState.DeviceState;
|
|
|
|
|
Stack->Parameters.Others.Argument4 = Context;
|
|
|
|
|
Stack->DeviceObject = TopDeviceObject;
|
|
|
|
|
IoSetNextIrpStackLocation(Irp);
|
|
|
|
|
|
2008-08-18 09:49:28 +00:00
|
|
|
|
Stack = IoGetNextIrpStackLocation(Irp);
|
2015-10-11 19:57:06 +00:00
|
|
|
|
Stack->MajorFunction = IRP_MJ_POWER;
|
2008-08-18 09:49:28 +00:00
|
|
|
|
Stack->MinorFunction = MinorFunction;
|
|
|
|
|
if (MinorFunction == IRP_MN_WAIT_WAKE)
|
2015-10-11 19:57:06 +00:00
|
|
|
|
{
|
2008-08-18 09:49:28 +00:00
|
|
|
|
Stack->Parameters.WaitWake.PowerState = PowerState.SystemState;
|
2015-10-11 19:57:06 +00:00
|
|
|
|
}
|
2008-08-18 09:49:28 +00:00
|
|
|
|
else
|
2010-03-20 16:48:00 +00:00
|
|
|
|
{
|
|
|
|
|
Stack->Parameters.Power.Type = DevicePowerState;
|
2010-03-20 16:49:50 +00:00
|
|
|
|
Stack->Parameters.Power.State = PowerState;
|
2010-03-20 16:48:00 +00:00
|
|
|
|
}
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2008-08-18 09:49:28 +00:00
|
|
|
|
if (pIrp != NULL)
|
|
|
|
|
*pIrp = Irp;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2015-10-11 19:57:06 +00:00
|
|
|
|
IoSetCompletionRoutine(Irp, PopRequestPowerIrpCompletion, CompletionFunction, TRUE, TRUE, TRUE);
|
2011-06-20 10:54:00 +00:00
|
|
|
|
PoCallDriver(TopDeviceObject, Irp);
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2008-08-18 09:49:28 +00:00
|
|
|
|
/* Always return STATUS_PENDING. The completion routine
|
|
|
|
|
* will call CompletionFunction and complete the Irp.
|
|
|
|
|
*/
|
|
|
|
|
return STATUS_PENDING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @unimplemented
|
|
|
|
|
*/
|
|
|
|
|
POWER_STATE
|
|
|
|
|
NTAPI
|
|
|
|
|
PoSetPowerState(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
|
IN POWER_STATE_TYPE Type,
|
|
|
|
|
IN POWER_STATE State)
|
|
|
|
|
{
|
|
|
|
|
POWER_STATE ps;
|
|
|
|
|
|
2008-08-30 15:14:12 +00:00
|
|
|
|
ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
|
2008-08-18 09:49:28 +00:00
|
|
|
|
|
|
|
|
|
ps.SystemState = PowerSystemWorking; // Fully on
|
|
|
|
|
ps.DeviceState = PowerDeviceD0; // Fully on
|
|
|
|
|
|
|
|
|
|
return ps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @unimplemented
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
PoSetSystemState(IN EXECUTION_STATE Flags)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @unimplemented
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
PoStartNextPowerIrp(IN PIRP Irp)
|
|
|
|
|
{
|
2019-08-20 12:20:17 +00:00
|
|
|
|
UNIMPLEMENTED_ONCE;
|
2008-08-18 09:49:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @unimplemented
|
|
|
|
|
*/
|
|
|
|
|
VOID
|
|
|
|
|
NTAPI
|
|
|
|
|
PoUnregisterSystemState(IN PVOID StateHandle)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @unimplemented
|
|
|
|
|
*/
|
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
2016-01-07 20:00:05 +00:00
|
|
|
|
NtInitiatePowerAction(IN POWER_ACTION SystemAction,
|
|
|
|
|
IN SYSTEM_POWER_STATE MinSystemState,
|
|
|
|
|
IN ULONG Flags,
|
|
|
|
|
IN BOOLEAN Asynchronous)
|
2004-07-17 03:07:00 +00:00
|
|
|
|
{
|
2007-07-04 08:26:47 +00:00
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2004-07-17 03:07:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @unimplemented
|
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
|
NTSTATUS
|
2008-08-18 09:49:28 +00:00
|
|
|
|
NTAPI
|
2007-07-04 08:26:47 +00:00
|
|
|
|
NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel,
|
|
|
|
|
IN PVOID InputBuffer OPTIONAL,
|
|
|
|
|
IN ULONG InputBufferLength,
|
|
|
|
|
OUT PVOID OutputBuffer OPTIONAL,
|
|
|
|
|
IN ULONG OutputBufferLength)
|
2004-07-17 03:07:00 +00:00
|
|
|
|
{
|
2007-07-04 08:26:47 +00:00
|
|
|
|
NTSTATUS Status;
|
2016-09-25 13:46:18 +00:00
|
|
|
|
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
2007-07-04 08:26:47 +00:00
|
|
|
|
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
2013-08-31 16:02:13 +00:00
|
|
|
|
DPRINT("NtPowerInformation(PowerInformationLevel 0x%x, InputBuffer 0x%p, "
|
|
|
|
|
"InputBufferLength 0x%x, OutputBuffer 0x%p, OutputBufferLength 0x%x)\n",
|
2007-07-04 08:26:47 +00:00
|
|
|
|
PowerInformationLevel,
|
|
|
|
|
InputBuffer, InputBufferLength,
|
|
|
|
|
OutputBuffer, OutputBufferLength);
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2016-09-25 13:46:18 +00:00
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
|
{
|
|
|
|
|
_SEH2_TRY
|
|
|
|
|
{
|
|
|
|
|
ProbeForRead(InputBuffer, InputBufferLength, 1);
|
|
|
|
|
ProbeForWrite(OutputBuffer, OutputBufferLength, sizeof(ULONG));
|
|
|
|
|
}
|
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
|
{
|
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
|
|
|
|
}
|
|
|
|
|
_SEH2_END;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-04 08:26:47 +00:00
|
|
|
|
switch (PowerInformationLevel)
|
|
|
|
|
{
|
|
|
|
|
case SystemBatteryState:
|
|
|
|
|
{
|
|
|
|
|
PSYSTEM_BATTERY_STATE BatteryState = (PSYSTEM_BATTERY_STATE)OutputBuffer;
|
|
|
|
|
|
|
|
|
|
if (InputBuffer != NULL)
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
if (OutputBufferLength < sizeof(SYSTEM_BATTERY_STATE))
|
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
|
2016-09-25 13:46:18 +00:00
|
|
|
|
_SEH2_TRY
|
|
|
|
|
{
|
|
|
|
|
/* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
|
|
|
|
|
RtlZeroMemory(BatteryState, sizeof(SYSTEM_BATTERY_STATE));
|
2019-04-20 21:26:57 +00:00
|
|
|
|
BatteryState->EstimatedTime = MAXULONG;
|
|
|
|
|
// BatteryState->AcOnLine = TRUE;
|
2016-09-25 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
|
{
|
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
|
}
|
|
|
|
|
_SEH2_END;
|
2007-07-04 08:26:47 +00:00
|
|
|
|
|
2008-06-21 10:08:09 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2014-11-23 15:57:13 +00:00
|
|
|
|
|
|
|
|
|
case SystemPowerCapabilities:
|
2008-06-21 10:08:09 +00:00
|
|
|
|
{
|
|
|
|
|
PSYSTEM_POWER_CAPABILITIES PowerCapabilities = (PSYSTEM_POWER_CAPABILITIES)OutputBuffer;
|
|
|
|
|
|
|
|
|
|
if (InputBuffer != NULL)
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
if (OutputBufferLength < sizeof(SYSTEM_POWER_CAPABILITIES))
|
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
|
2016-09-25 13:46:18 +00:00
|
|
|
|
_SEH2_TRY
|
|
|
|
|
{
|
2019-04-07 14:41:56 +00:00
|
|
|
|
RtlCopyMemory(PowerCapabilities,
|
|
|
|
|
&PopCapabilities,
|
|
|
|
|
sizeof(SYSTEM_POWER_CAPABILITIES));
|
2016-09-25 13:46:18 +00:00
|
|
|
|
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
|
{
|
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
|
}
|
|
|
|
|
_SEH2_END;
|
2008-06-21 10:08:09 +00:00
|
|
|
|
|
2007-07-04 08:26:47 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-25 13:03:06 +00:00
|
|
|
|
case ProcessorInformation:
|
|
|
|
|
{
|
|
|
|
|
PPROCESSOR_POWER_INFORMATION PowerInformation = (PPROCESSOR_POWER_INFORMATION)OutputBuffer;
|
|
|
|
|
|
|
|
|
|
if (InputBuffer != NULL)
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
if (OutputBufferLength < sizeof(PROCESSOR_POWER_INFORMATION))
|
|
|
|
|
return STATUS_BUFFER_TOO_SMALL;
|
|
|
|
|
|
2020-05-24 22:24:52 +00:00
|
|
|
|
/* FIXME: return structures for all processors */
|
|
|
|
|
|
2016-09-25 13:46:18 +00:00
|
|
|
|
_SEH2_TRY
|
|
|
|
|
{
|
2020-05-24 22:24:52 +00:00
|
|
|
|
/* FIXME: some values are hardcoded */
|
2016-09-25 13:46:18 +00:00
|
|
|
|
PowerInformation->Number = 0;
|
|
|
|
|
PowerInformation->MaxMhz = 1000;
|
2020-05-24 22:24:52 +00:00
|
|
|
|
PowerInformation->CurrentMhz = KeGetCurrentPrcb()->MHz;
|
2016-09-25 13:46:18 +00:00
|
|
|
|
PowerInformation->MhzLimit = 1000;
|
|
|
|
|
PowerInformation->MaxIdleState = 0;
|
|
|
|
|
PowerInformation->CurrentIdleState = 0;
|
|
|
|
|
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
|
{
|
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
|
}
|
|
|
|
|
_SEH2_END;
|
2016-09-25 13:03:06 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-04 08:26:47 +00:00
|
|
|
|
default:
|
|
|
|
|
Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
DPRINT1("PowerInformationLevel 0x%x is UNIMPLEMENTED! Have a nice day.\n",
|
|
|
|
|
PowerInformationLevel);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Status;
|
2004-07-17 03:07:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-10-23 18:16:24 +00:00
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
|
|
|
|
NtGetDevicePowerState(IN HANDLE Device,
|
|
|
|
|
IN PDEVICE_POWER_STATE PowerState)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
|
NTAPI
|
|
|
|
|
NtIsSystemResumeAutomatic(VOID)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
|
|
|
|
NtRequestWakeupLatency(IN LATENCY_TIME Latency)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
|
|
|
|
NtSetThreadExecutionState(IN EXECUTION_STATE esFlags,
|
|
|
|
|
OUT EXECUTION_STATE *PreviousFlags)
|
|
|
|
|
{
|
2009-06-26 09:39:00 +00:00
|
|
|
|
PKTHREAD Thread = KeGetCurrentThread();
|
|
|
|
|
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
|
|
|
|
EXECUTION_STATE PreviousState;
|
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
|
|
/* Validate flags */
|
|
|
|
|
if (esFlags & ~(ES_CONTINUOUS | ES_USER_PRESENT))
|
|
|
|
|
{
|
|
|
|
|
/* Fail the request */
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check for user parameters */
|
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
|
{
|
|
|
|
|
/* Protect the probes */
|
|
|
|
|
_SEH2_TRY
|
|
|
|
|
{
|
|
|
|
|
/* Check if the pointer is valid */
|
|
|
|
|
ProbeForWriteUlong(PreviousFlags);
|
|
|
|
|
}
|
2009-08-24 19:58:15 +00:00
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2009-06-26 09:39:00 +00:00
|
|
|
|
{
|
|
|
|
|
/* It isn't -- fail */
|
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
|
|
|
|
}
|
|
|
|
|
_SEH2_END;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Save the previous state, always masking in the continous flag */
|
|
|
|
|
PreviousState = Thread->PowerState | ES_CONTINUOUS;
|
|
|
|
|
|
|
|
|
|
/* Check if we need to update the power state */
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
|
if (esFlags & ES_CONTINUOUS) Thread->PowerState = (UCHAR)esFlags;
|
2009-06-26 09:39:00 +00:00
|
|
|
|
|
|
|
|
|
/* Protect the write back to user mode */
|
|
|
|
|
_SEH2_TRY
|
|
|
|
|
{
|
|
|
|
|
/* Return the previous flags */
|
|
|
|
|
*PreviousFlags = PreviousState;
|
|
|
|
|
}
|
|
|
|
|
_SEH2_EXCEPT(ExSystemExceptionFilter())
|
|
|
|
|
{
|
|
|
|
|
/* Something's wrong, fail */
|
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
|
|
|
|
}
|
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
|
|
/* All is good */
|
|
|
|
|
return STATUS_SUCCESS;
|
2006-10-23 18:16:24 +00:00
|
|
|
|
}
|
2010-03-08 20:47:10 +00:00
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
|
NTAPI
|
|
|
|
|
NtSetSystemPowerState(IN POWER_ACTION SystemAction,
|
2014-11-23 15:57:13 +00:00
|
|
|
|
IN SYSTEM_POWER_STATE MinSystemState,
|
|
|
|
|
IN ULONG Flags)
|
2010-03-08 20:47:10 +00:00
|
|
|
|
{
|
|
|
|
|
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
|
|
|
|
POP_POWER_ACTION Action = {0};
|
|
|
|
|
NTSTATUS Status;
|
2010-10-05 15:52:00 +00:00
|
|
|
|
ULONG Dummy;
|
2010-03-08 20:47:10 +00:00
|
|
|
|
|
|
|
|
|
/* Check for invalid parameter combinations */
|
|
|
|
|
if ((MinSystemState >= PowerSystemMaximum) ||
|
|
|
|
|
(MinSystemState <= PowerSystemUnspecified) ||
|
|
|
|
|
(SystemAction > PowerActionWarmEject) ||
|
|
|
|
|
(SystemAction < PowerActionReserved) ||
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
|
(Flags & ~(POWER_ACTION_QUERY_ALLOWED |
|
|
|
|
|
POWER_ACTION_UI_ALLOWED |
|
|
|
|
|
POWER_ACTION_OVERRIDE_APPS |
|
|
|
|
|
POWER_ACTION_LIGHTEST_FIRST |
|
|
|
|
|
POWER_ACTION_LOCK_CONSOLE |
|
|
|
|
|
POWER_ACTION_DISABLE_WAKES |
|
2010-03-08 20:47:10 +00:00
|
|
|
|
POWER_ACTION_CRITICAL)))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("NtSetSystemPowerState: Bad parameters!\n");
|
|
|
|
|
DPRINT1(" SystemAction: 0x%x\n", SystemAction);
|
|
|
|
|
DPRINT1(" MinSystemState: 0x%x\n", MinSystemState);
|
|
|
|
|
DPRINT1(" Flags: 0x%x\n", Flags);
|
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check for user caller */
|
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
|
{
|
|
|
|
|
/* Check for shutdown permission */
|
|
|
|
|
if (!SeSinglePrivilegeCheck(SeShutdownPrivilege, PreviousMode))
|
|
|
|
|
{
|
|
|
|
|
/* Not granted */
|
|
|
|
|
DPRINT1("ERROR: Privilege not held for shutdown\n");
|
2014-08-30 08:31:28 +00:00
|
|
|
|
return STATUS_PRIVILEGE_NOT_HELD;
|
2010-03-08 20:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Do it as a kernel-mode caller for consistency with system state */
|
2014-11-23 15:57:13 +00:00
|
|
|
|
return ZwSetSystemPowerState(SystemAction, MinSystemState, Flags);
|
2010-03-08 20:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read policy settings (partial shutdown vs. full shutdown) */
|
|
|
|
|
if (SystemAction == PowerActionShutdown) PopReadShutdownPolicy();
|
|
|
|
|
|
|
|
|
|
/* Disable lazy flushing of registry */
|
2014-11-02 11:30:14 +00:00
|
|
|
|
DPRINT("Stopping lazy flush\n");
|
2010-03-08 20:47:10 +00:00
|
|
|
|
CmSetLazyFlushState(FALSE);
|
|
|
|
|
|
|
|
|
|
/* Setup the power action */
|
|
|
|
|
Action.Action = SystemAction;
|
|
|
|
|
Action.Flags = Flags;
|
|
|
|
|
|
|
|
|
|
/* Notify callbacks */
|
2014-11-02 11:30:14 +00:00
|
|
|
|
DPRINT("Notifying callbacks\n");
|
2010-03-08 20:47:10 +00:00
|
|
|
|
ExNotifyCallback(PowerStateCallback, (PVOID)3, NULL);
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2010-03-08 20:47:10 +00:00
|
|
|
|
/* Swap in any worker thread stacks */
|
2014-11-02 11:30:14 +00:00
|
|
|
|
DPRINT("Swapping worker threads\n");
|
2010-03-08 20:47:10 +00:00
|
|
|
|
ExSwapinWorkerThreads(FALSE);
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2010-03-08 20:47:10 +00:00
|
|
|
|
/* Make our action global */
|
|
|
|
|
PopAction = Action;
|
|
|
|
|
|
|
|
|
|
/* Start power loop */
|
|
|
|
|
Status = STATUS_CANCELLED;
|
|
|
|
|
while (TRUE)
|
|
|
|
|
{
|
|
|
|
|
/* Break out if there's nothing to do */
|
|
|
|
|
if (Action.Action == PowerActionNone) break;
|
|
|
|
|
|
|
|
|
|
/* Check for first-pass or restart */
|
|
|
|
|
if (Status == STATUS_CANCELLED)
|
|
|
|
|
{
|
|
|
|
|
/* Check for shutdown action */
|
|
|
|
|
if ((PopAction.Action == PowerActionShutdown) ||
|
|
|
|
|
(PopAction.Action == PowerActionShutdownReset) ||
|
|
|
|
|
(PopAction.Action == PowerActionShutdownOff))
|
|
|
|
|
{
|
|
|
|
|
/* Set the action */
|
|
|
|
|
PopAction.Shutdown = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now we are good to go */
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check if we're still in an invalid status */
|
|
|
|
|
if (!NT_SUCCESS(Status)) break;
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2021-01-21 15:39:27 +00:00
|
|
|
|
/* Flush all volumes and the registry */
|
|
|
|
|
DPRINT("Flushing volumes\n");
|
|
|
|
|
PopFlushVolumes(PopAction.Shutdown);
|
|
|
|
|
|
[CACHE]
The cache manager rewrite I started years ago has finally appeared in
ReactOS' trunk and although at this point it's not quite perfectly
integrated, it's enough to boot up the bootcd or livecd. To check out
the more mature original, check out arty-newcc-reactos, branch
arty-newcc on bitbucket.org . Amine Khaldi encouraged me quite a bit
to not give up on it, and was able to reach out and be an advocate
when i really wasn't able to. Others agree that the time has come to
begin removing the old cache manager. I expect the remaining problems
in the version going to trunk will be taken care of relatively
quickly.
The motivation for this effort lies in the particularly hairy
relationship between ReactOS' cache manager and data sections. This
code completely removes page sharing between cache manager and section
and reimagines cache manager as being a facility layered on the memory
manager, not really caring about individual pages, but simply managing
data section objects where caching might occur.
It took me about 2 years to do the first pass of this rewrite and most
of this year to fix some lingering issues, properly implement demand
paging in ReactOS (code which didn't come with this patch in a
recognizable form), and finish getting the PrivateCacheMap and
SharedCacheMap relationship correct.
Currently, the new ntoskrnl/cache directory contains an own
implementation of data file sections. After things have settled down,
we can begin to deprecate and remove the parts of ReactOS' section
implementation that depend on a close relationship with cache
manager. Eventually, I think that the extra code added to
ntoskrnl/cache/section will be removed and ReactOS' own sections will
replace the use of the special MM_CACHE_SECTION_SEGMENT in the cache
path.
Note also, that this makes all cache manager (and new section parts)
use wide file offsets. If my section code were to take over other
parts of the ReactOS memory manager, they would also benefit from
these improvements.
I invite anyone who wants to to peek at this code and fix whatever
bugs can be found.
svn path=/trunk/; revision=49423
2010-11-02 02:32:39 +00:00
|
|
|
|
#ifndef NEWCC
|
2010-10-05 15:52:00 +00:00
|
|
|
|
/* Flush dirty cache pages */
|
2018-01-23 18:07:25 +00:00
|
|
|
|
/* XXX: Is that still mandatory? As now we'll wait on lazy writer to complete? */
|
2021-01-21 15:39:27 +00:00
|
|
|
|
CcRosFlushDirtyPages(MAXULONG, &Dummy, TRUE, FALSE);
|
|
|
|
|
DPRINT("Cache flushed %lu pages\n", Dummy);
|
2010-11-28 22:33:19 +00:00
|
|
|
|
#else
|
|
|
|
|
Dummy = 0;
|
[CACHE]
The cache manager rewrite I started years ago has finally appeared in
ReactOS' trunk and although at this point it's not quite perfectly
integrated, it's enough to boot up the bootcd or livecd. To check out
the more mature original, check out arty-newcc-reactos, branch
arty-newcc on bitbucket.org . Amine Khaldi encouraged me quite a bit
to not give up on it, and was able to reach out and be an advocate
when i really wasn't able to. Others agree that the time has come to
begin removing the old cache manager. I expect the remaining problems
in the version going to trunk will be taken care of relatively
quickly.
The motivation for this effort lies in the particularly hairy
relationship between ReactOS' cache manager and data sections. This
code completely removes page sharing between cache manager and section
and reimagines cache manager as being a facility layered on the memory
manager, not really caring about individual pages, but simply managing
data section objects where caching might occur.
It took me about 2 years to do the first pass of this rewrite and most
of this year to fix some lingering issues, properly implement demand
paging in ReactOS (code which didn't come with this patch in a
recognizable form), and finish getting the PrivateCacheMap and
SharedCacheMap relationship correct.
Currently, the new ntoskrnl/cache directory contains an own
implementation of data file sections. After things have settled down,
we can begin to deprecate and remove the parts of ReactOS' section
implementation that depend on a close relationship with cache
manager. Eventually, I think that the extra code added to
ntoskrnl/cache/section will be removed and ReactOS' own sections will
replace the use of the special MM_CACHE_SECTION_SEGMENT in the cache
path.
Note also, that this makes all cache manager (and new section parts)
use wide file offsets. If my section code were to take over other
parts of the ReactOS memory manager, they would also benefit from
these improvements.
I invite anyone who wants to to peek at this code and fix whatever
bugs can be found.
svn path=/trunk/; revision=49423
2010-11-02 02:32:39 +00:00
|
|
|
|
#endif
|
2010-03-08 20:47:10 +00:00
|
|
|
|
|
|
|
|
|
/* Set IRP for drivers */
|
|
|
|
|
PopAction.IrpMinor = IRP_MN_SET_POWER;
|
|
|
|
|
if (PopAction.Shutdown)
|
|
|
|
|
{
|
2014-11-02 11:30:14 +00:00
|
|
|
|
DPRINT("Queueing shutdown thread\n");
|
2010-03-08 20:47:10 +00:00
|
|
|
|
/* Check if we are running in the system context */
|
|
|
|
|
if (PsGetCurrentProcess() != PsInitialSystemProcess)
|
|
|
|
|
{
|
|
|
|
|
/* We're not, so use a worker thread for shutdown */
|
|
|
|
|
ExInitializeWorkItem(&PopShutdownWorkItem,
|
|
|
|
|
&PopGracefulShutdown,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
ExQueueWorkItem(&PopShutdownWorkItem, CriticalWorkQueue);
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2010-03-08 20:47:10 +00:00
|
|
|
|
/* Spend us -- when we wake up, the system is good to go down */
|
|
|
|
|
KeSuspendThread(KeGetCurrentThread());
|
|
|
|
|
Status = STATUS_SYSTEM_SHUTDOWN;
|
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Do the shutdown inline */
|
|
|
|
|
PopGracefulShutdown(NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-02 11:30:14 +00:00
|
|
|
|
|
2010-03-08 20:47:10 +00:00
|
|
|
|
/* You should not have made it this far */
|
2018-07-04 01:42:04 +00:00
|
|
|
|
// ASSERTMSG("System is still up and running?!\n", FALSE);
|
2015-03-14 16:40:26 +00:00
|
|
|
|
DPRINT1("System is still up and running, you may not have chosen a yet supported power option: %u\n", PopAction.Action);
|
2010-03-08 20:47:10 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
|
/* We're done, return */
|
|
|
|
|
return Status;
|
|
|
|
|
}
|