From 626aaf227c692e91be395751c7b5e2c108edd270 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 7 Apr 2019 16:41:56 +0200 Subject: [PATCH] [NTOSKRNL] Use global power capabilities and report button presence - Add and initialize a global power capabilities variable. - Return the global power capabilities via NtPowerInformation.SystemPowerCapabilities. - Report the presence of power button, sleep button and lid. --- ntoskrnl/include/internal/po.h | 1 + ntoskrnl/po/events.c | 22 ++++++++++++++++------ ntoskrnl/po/power.c | 13 ++++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/ntoskrnl/include/internal/po.h b/ntoskrnl/include/internal/po.h index f9d57e3e59d..0d722347381 100644 --- a/ntoskrnl/include/internal/po.h +++ b/ntoskrnl/include/internal/po.h @@ -365,4 +365,5 @@ extern KGUARDED_MUTEX PopVolumeLock; extern LIST_ENTRY PopVolumeDevices; extern KSPIN_LOCK PopDopeGlobalLock; extern POP_POWER_ACTION PopAction; +extern SYSTEM_POWER_CAPABILITIES PopCapabilities; diff --git a/ntoskrnl/po/events.c b/ntoskrnl/po/events.c index e79f6df12eb..b6392bd9318 100644 --- a/ntoskrnl/po/events.c +++ b/ntoskrnl/po/events.c @@ -242,13 +242,23 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure, return STATUS_INSUFFICIENT_RESOURCES; } - /* FIXME: What do do with the capabilities? */ + DPRINT("Device capabilities: 0x%x\n", Caps); + if (Caps & SYS_BUTTON_POWER) { - DPRINT("Device capabilities: 0x%x (", Caps); - if (Caps & SYS_BUTTON_POWER) DPRINT(" POWER"); - if (Caps & SYS_BUTTON_SLEEP) DPRINT(" SLEEP"); - if (Caps & SYS_BUTTON_LID) DPRINT(" LID"); - DPRINT(" )\n"); + DPRINT("POWER button present\n"); + PopCapabilities.PowerButtonPresent = TRUE; + } + + if (Caps & SYS_BUTTON_SLEEP) + { + DPRINT("SLEEP button present\n"); + PopCapabilities.SleepButtonPresent = TRUE; + } + + if (Caps & SYS_BUTTON_LID) + { + DPRINT("LID present\n"); + PopCapabilities.LidPresent = TRUE; } SysButtonContext = ExAllocatePoolWithTag(NonPagedPool, diff --git a/ntoskrnl/po/power.c b/ntoskrnl/po/power.c index a0dd4fb3af9..f249d0eb1a8 100644 --- a/ntoskrnl/po/power.c +++ b/ntoskrnl/po/power.c @@ -26,6 +26,7 @@ PDEVICE_NODE PopSystemPowerDeviceNode = NULL; BOOLEAN PopAcpiPresent = FALSE; POP_POWER_ACTION PopAction; WORK_QUEUE_ITEM PopShutdownWorkItem; +SYSTEM_POWER_CAPABILITIES PopCapabilities; /* PRIVATE FUNCTIONS *********************************************************/ @@ -323,6 +324,9 @@ PoInitSystem(IN ULONG BootPhase) return TRUE; } + /* Initialize the power capabilities */ + RtlZeroMemory(&PopCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES)); + /* Get the Command Line */ CommandLine = KeLoaderBlock->LoadOptions; @@ -343,6 +347,9 @@ PoInitSystem(IN ULONG BootPhase) PopAcpiPresent = KeLoaderBlock->Extension->AcpiTable != NULL ? TRUE : FALSE; } + /* Enable shutdown by power button */ + if (PopAcpiPresent) + PopCapabilities.SystemS5 = TRUE; /* Initialize volume support */ InitializeListHead(&PopVolumeDevices); @@ -720,9 +727,9 @@ NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel, _SEH2_TRY { - /* Just zero the struct (and thus set PowerCapabilities->SystemBatteriesPresent = FALSE) */ - RtlZeroMemory(PowerCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES)); - //PowerCapabilities->SystemBatteriesPresent = 0; + RtlCopyMemory(PowerCapabilities, + &PopCapabilities, + sizeof(SYSTEM_POWER_CAPABILITIES)); Status = STATUS_SUCCESS; }