From 3072334f2734e6a811fd2a9ef588388eb7d73855 Mon Sep 17 00:00:00 2001 From: leon9078 Date: Mon, 22 Apr 2024 18:16:24 +0200 Subject: [PATCH] Fix minor typos in code and debug log. Plus better formatting. --- Changelog.md | 1 + HibernationFixup/kern_config.hpp | 26 ++--- HibernationFixup/kern_hbfx.cpp | 12 +- HibernationFixup/kern_hbfx.hpp | 18 +-- HibernationFixup/osx_defines.h | 188 +++++++++++++++---------------- 5 files changed, 123 insertions(+), 122 deletions(-) diff --git a/Changelog.md b/Changelog.md index be5f402..7c7711b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ HibernationFixup Changelog #### v1.5.0 - Auto hibernation: make sure auto-hibernate feature only happens when hibernatemode is set to 3. (Never with mode 0 or 25). +- Fix minor typos in code and debug log. Plus better formatting. #### v1.4.9 - Add macOS 14 (Sonoma) constants diff --git a/HibernationFixup/kern_config.hpp b/HibernationFixup/kern_config.hpp index adfe0e5..b7ab30f 100644 --- a/HibernationFixup/kern_config.hpp +++ b/HibernationFixup/kern_config.hpp @@ -48,29 +48,29 @@ class Configuration { */ enum AutoHibernateModes { // If this flag is set, system will hibernate instead of regular sleep (flags below can be used to limit this behavior) - EnableAutoHibernation = 1, + EnableAutoHibernation = 1, // Auto hibernation can happen when lid is closed (if bit is not set - no matter which status lid has) - WhenLidIsClosed = 2, + WhenLidIsClosed = 2, // Auto hibernation can happen when external power is disconnected (if bit is not set - no matter whether it is connected) - WhenExternalPowerIsDisconnected = 4, + WhenExternalPowerIsDisconnected = 4, // Auto hibernation can happen when battery is not charging (if bit is not set - no matter whether it is charging) - WhenBatteryIsNotCharging = 8, + WhenBatteryIsNotCharging = 8, // Auto hibernation can happen when battery is at warning level (osx is responsible for this level) - WhenBatteryIsAtWarnLevel = 16, + WhenBatteryIsAtWarnLevel = 16, // Auto hibernation can happen when battery is at critical level (osx is responsible for this level) - WhenBatteryAtCriticalLevel = 32, - // Do not alter next wake up time - DoNotOverrideWakeUpTime = 64, + WhenBatteryAtCriticalLevel = 32, + // Do not alter next wake up time, macOS is fully responsible for sleep maintenance dark wakes + DoNotOverrideWakeUpTime = 64, // Disable power event kStimulusDarkWakeActivityTickle in kernel, so this event cannot be a trigger for switching from dark wake to full wake - DisableStimulusDarkWakeActivityTickle = 128, + DisableStimulusDarkWakeActivityTickle = 128, // Next 4 bits are used to specify minimal capacity percent remaining value when hibernation will be forced. // Can be used together with WhenBatteryIsAtWarnLevel or WhenBatteryAtCriticalLevel, when IOPMPowerSource cannot detect // warning or critical battery level - RemainCapacityBit1 = 256, - RemainCapacityBit2 = 512, - RemainCapacityBit3 = 1024, - RemainCapacityBit4 = 2048 + RemainCapacityBit1 = 256, + RemainCapacityBit2 = 512, + RemainCapacityBit3 = 1024, + RemainCapacityBit4 = 2048 }; int autoHibernateMode {0}; diff --git a/HibernationFixup/kern_hbfx.cpp b/HibernationFixup/kern_hbfx.cpp index 5fbc7a3..ee1694a 100644 --- a/HibernationFixup/kern_hbfx.cpp +++ b/HibernationFixup/kern_hbfx.cpp @@ -289,9 +289,9 @@ IOReturn HBFX::IOPMrootDomain_setMaintenanceWakeCalendar(IOPMrootDomain* that, I //============================================================================== -IOReturn HBFX::AppleRTC_setupDateTimeAlarm(void *that, void* rctDateTime) +IOReturn HBFX::AppleRTC_setupDateTimeAlarm(void *that, void* rtcDateTime) { - DBGLOG("HBFX", "AppleRTC::setupDateTimeAlarm is called, set alarm to seconds: %lld", callbackHBFX->convertDateTimeToSeconds(rctDateTime)); + DBGLOG("HBFX", "AppleRTC::setupDateTimeAlarm is called, set alarm to seconds: %lld", callbackHBFX->convertDateTimeToSeconds(rtcDateTime)); if (callbackHBFX->sleepServiceWake) { DBGLOG("HBFX", "AppleRTC::setupDateTimeAlarm called after sleepServiceWake is set"); @@ -315,13 +315,13 @@ IOReturn HBFX::AppleRTC_setupDateTimeAlarm(void *that, void* rctDateTime) gmtime_r(tv.tv_sec, &tm); DBGLOG("HBFX", "Postpone RTC wake to: %02d.%02d.%04d %02d:%02d:%02d", tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_hour, tm.tm_min, tm.tm_sec); - callbackHBFX->convertSecondsToDateTime(tv.tv_sec, rctDateTime); + callbackHBFX->convertSecondsToDateTime(tv.tv_sec, rtcDateTime); } } else SYSLOG("HBFX", "IOPMrootDomain cannot be obtained from AppleRTC"); - return FunctionCast(AppleRTC_setupDateTimeAlarm, callbackHBFX->orgAppleRTC_setupDateTimeAlarm)(that, rctDateTime); + return FunctionCast(AppleRTC_setupDateTimeAlarm, callbackHBFX->orgAppleRTC_setupDateTimeAlarm)(that, rtcDateTime); } //============================================================================== @@ -490,7 +490,7 @@ IOReturn HBFX::X86PlatformPlugin_sleepPolicyHandler(void * target, IOPMSystemSle vars->sleepReason = callbackHBFX->sleepReason; params->sleepType = callbackHBFX->sleepType; params->sleepFlags = callbackHBFX->sleepFlags; - DBGLOG("HBFX", "%02d.%02d.%04d %02d:%02d:%02d: Auto hibernate: Auto hibernate: sleep phase %d, postpone hibernate", + DBGLOG("HBFX", "%02d.%02d.%04d %02d:%02d:%02d: Auto hibernate: sleep phase %d, postpone hibernate", tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_hour, tm.tm_min, tm.tm_sec, callbackHBFX->sleepPhase); } @@ -594,7 +594,7 @@ void HBFX::IOPCIDevice_extendedConfigWrite16(IOService *that, UInt64 offset, UIn { if (!(data & kIOPCICommandMemorySpace)) { - DBGLOG("HBFX", "HBFX will add flag kIOPCICommandMemorySpace for deivce %s, offset = %08llX, data = %04X", that->getName(), offset, data); + DBGLOG("HBFX", "HBFX will add flag kIOPCICommandMemorySpace for device %s, offset = %08llX, data = %04X", that->getName(), offset, data); data |= kIOPCICommandMemorySpace; } } diff --git a/HibernationFixup/kern_hbfx.hpp b/HibernationFixup/kern_hbfx.hpp index 0e946c4..30a5c28 100644 --- a/HibernationFixup/kern_hbfx.hpp +++ b/HibernationFixup/kern_hbfx.hpp @@ -55,7 +55,7 @@ class HBFX { // return pointer to IOPMPowerSource IOPMPowerSource *getPowerSource(); - // return true if standby/auto power off is enabled + // return true if standby/autopoweroff is enabled bool isStandbyEnabled(uint32_t &standby_delay, bool &pmset_default_mode); IOReturn explicitlyCallSetMaintenanceWakeCalendar(); @@ -71,7 +71,7 @@ class HBFX { static void IOPMrootDomain_evaluatePolicy(IOPMrootDomain* that, int stimulus, uint32_t arg); static void IOPMrootDomain_requestFullWake(IOPMrootDomain* that, uint32_t reason); static IOReturn IOPMrootDomain_setMaintenanceWakeCalendar(IOPMrootDomain* that, IOPMCalendarStruct * calendar); - static IOReturn AppleRTC_setupDateTimeAlarm(void *that, void* rctDateTime); + static IOReturn AppleRTC_setupDateTimeAlarm(void *that, void* rtcDateTime); static IOReturn X86PlatformPlugin_sleepPolicyHandler(void * target, IOPMSystemSleepPolicyVariables * vars, IOPMSystemSleepParameters * params); static int packA(char *inbuf, uint32_t length, uint32_t buflen); @@ -118,10 +118,10 @@ class HBFX { using t_ml_set_interrupts_enabled = boolean_t (*) (boolean_t enable); t_ml_set_interrupts_enabled ml_set_interrupts_enabled {nullptr}; - using t_convertDateTimeToSeconds = int64_t (*) (void *rctDateTime); + using t_convertDateTimeToSeconds = int64_t (*) (void *rtcDateTime); t_convertDateTimeToSeconds convertDateTimeToSeconds {nullptr}; - using t_convertSecondsToDateTime = int64_t (*) (int64_t seconds, void *rctDateTime); + using t_convertSecondsToDateTime = int64_t (*) (int64_t seconds, void *rtcDateTime); t_convertSecondsToDateTime convertSecondsToDateTime {nullptr}; using t_checkSystemSleepEnabled = bool (*) (IOPMrootDomain* that); @@ -129,16 +129,16 @@ class HBFX { bool correct_pci_config_command {false}; - uint32_t latestStandbyDelay {0}; + uint32_t latestStandbyDelay {0}; uint32_t latestPoweroffDelay {0}; - uint32_t latestHibernateMode {0}; - uint32_t sleepPhase {-1U}; + uint32_t latestHibernateMode {0}; + uint32_t sleepPhase {-1U}; uint64_t sleepFactors {0}; uint32_t sleepReason {0}; uint32_t sleepType {0}; uint32_t sleepFlags {0}; - bool sleepServiceWake {false}; - bool wakeCalendarSet {false}; + bool sleepServiceWake {false}; + bool wakeCalendarSet {false}; /** * Current progress mask diff --git a/HibernationFixup/osx_defines.h b/HibernationFixup/osx_defines.h index d130226..f6280be 100644 --- a/HibernationFixup/osx_defines.h +++ b/HibernationFixup/osx_defines.h @@ -13,14 +13,14 @@ #include #include -#define kIOHibernateStateKey "IOHibernateState" -#define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables" -#define kIOHibernateSMCVariablesKey "IOHibernateSMCVariables" -#define kIOHibernateFileKey "Hibernate File" -#define kBoot0082Key "Boot0082" -#define kBootNextKey "BootNext" -#define kGlobalBoot0082Key NVRAM_PREFIX(NVRAM_GLOBAL_GUID, kBoot0082Key) -#define kGlobalBootNextKey NVRAM_PREFIX(NVRAM_GLOBAL_GUID, kBootNextKey) +#define kIOHibernateStateKey "IOHibernateState" +#define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables" +#define kIOHibernateSMCVariablesKey "IOHibernateSMCVariables" +#define kIOHibernateFileKey "Hibernate File" +#define kBoot0082Key "Boot0082" +#define kBootNextKey "BootNext" +#define kGlobalBoot0082Key NVRAM_PREFIX(NVRAM_GLOBAL_GUID, kBoot0082Key) +#define kGlobalBootNextKey NVRAM_PREFIX(NVRAM_GLOBAL_GUID, kBootNextKey) #define kAppleSleepDisabled "SleepDisabled" @@ -42,28 +42,28 @@ /* kIOPMUserIsActiveKey * Key refers to a boolean value that indicates if the user is active. */ -#define kIOPMUserIsActiveKey "IOPMUserIsActive" +#define kIOPMUserIsActiveKey "IOPMUserIsActive" struct IOPMSystemSleepPolicyVariables { - uint32_t signature; // kIOPMSystemSleepPolicySignature - uint32_t version; // kIOPMSystemSleepPolicyVersion + uint32_t signature; // kIOPMSystemSleepPolicySignature + uint32_t version; // kIOPMSystemSleepPolicyVersion - uint64_t currentCapability; // current system capability bits - uint64_t highestCapability; // highest system capability bits + uint64_t currentCapability; // current system capability bits + uint64_t highestCapability; // highest system capability bits - uint64_t sleepFactors; // sleep factor bits - uint32_t sleepReason; // kIOPMSleepReason* - uint32_t sleepPhase; // identify the sleep phase - uint32_t hibernateMode; // current hibernate mode + uint64_t sleepFactors; // sleep factor bits + uint32_t sleepReason; // kIOPMSleepReason* + uint32_t sleepPhase; // identify the sleep phase + uint32_t hibernateMode; // current hibernate mode - uint32_t standbyDelay; // standby delay in seconds - uint32_t standbyTimer; // standby timer in seconds - uint32_t poweroffDelay; // auto-poweroff delay in seconds - uint32_t scheduledAlarms; // bitmask of scheduled alarm types - uint32_t poweroffTimer; // auto-poweroff timer in seconds + uint32_t standbyDelay; // standby delay in seconds + uint32_t standbyTimer; // standby timer in seconds + uint32_t poweroffDelay; // auto-poweroff delay in seconds + uint32_t scheduledAlarms; // bitmask of scheduled alarm types + uint32_t poweroffTimer; // auto-poweroff timer in seconds - uint32_t reserved[49]; // pad sizeof 256 bytes + uint32_t reserved[49]; // pad sizeof 256 bytes }; struct IOPMSystemSleepParameters @@ -79,104 +79,104 @@ struct IOPMSystemSleepParameters } __attribute__((packed)); -#define kIOPMSystemSleepPolicySignature 0x54504c53 -#define kIOPMSystemSleepPolicyVersion 2 +#define kIOPMSystemSleepPolicySignature 0x54504c53 +#define kIOPMSystemSleepPolicyVersion 2 /*! @constant kIOPMCalendarWakeTypes * * These are valid values for IOPM.h:IOPMCalendarStruct->selector */ enum { - kPMCalendarTypeMaintenance = 1, - kPMCalendarTypeSleepService = 2 + kPMCalendarTypeMaintenance = 1, + kPMCalendarTypeSleepService = 2 }; // gIOHibernateMode, kIOHibernateModeKey enum { - kIOHibernateModeOn = 0x00000001, - kIOHibernateModeSleep = 0x00000002, - kIOHibernateModeEncrypt = 0x00000004, - kIOHibernateModeDiscardCleanInactive = 0x00000008, - kIOHibernateModeDiscardCleanActive = 0x00000010, - kIOHibernateModeSwitch = 0x00000020, - kIOHibernateModeRestart = 0x00000040, - kIOHibernateModeSSDInvert = 0x00000080, - kIOHibernateModeFileResize = 0x00000100, + kIOHibernateModeOn = 0x00000001, + kIOHibernateModeSleep = 0x00000002, + kIOHibernateModeEncrypt = 0x00000004, + kIOHibernateModeDiscardCleanInactive = 0x00000008, + kIOHibernateModeDiscardCleanActive = 0x00000010, + kIOHibernateModeSwitch = 0x00000020, + kIOHibernateModeRestart = 0x00000040, + kIOHibernateModeSSDInvert = 0x00000080, + kIOHibernateModeFileResize = 0x00000100, }; // gIOHibernateState, kIOHibernateStateKey enum { - kIOHibernateStateInactive = 0, - kIOHibernateStateHibernating = 1, /* writing image */ - kIOHibernateStateWakingFromHibernate = 2 /* booted and restored image */ + kIOHibernateStateInactive = 0, + kIOHibernateStateHibernating = 1, /* writing image */ + kIOHibernateStateWakingFromHibernate = 2 /* booted and restored image */ }; enum { - kMachineRestoreBridges = 0x00000001, - kMachineRestoreEarlyDevices = 0x00000002, - kMachineRestoreDehibernate = 0x00000004, - kMachineRestoreTunnels = 0x00000008, + kMachineRestoreBridges = 0x00000001, + kMachineRestoreEarlyDevices = 0x00000002, + kMachineRestoreDehibernate = 0x00000004, + kMachineRestoreTunnels = 0x00000008, }; // System Sleep Types enum { - kIOPMSleepTypeInvalid = 0, - kIOPMSleepTypeAbortedSleep = 1, - kIOPMSleepTypeNormalSleep = 2, - kIOPMSleepTypeSafeSleep = 3, - kIOPMSleepTypeHibernate = 4, - kIOPMSleepTypeStandby = 5, - kIOPMSleepTypePowerOff = 6, - kIOPMSleepTypeDeepIdle = 7, - kIOPMSleepTypeLast = 8 + kIOPMSleepTypeInvalid = 0, + kIOPMSleepTypeAbortedSleep = 1, + kIOPMSleepTypeNormalSleep = 2, + kIOPMSleepTypeSafeSleep = 3, + kIOPMSleepTypeHibernate = 4, + kIOPMSleepTypeStandby = 5, + kIOPMSleepTypePowerOff = 6, + kIOPMSleepTypeDeepIdle = 7, + kIOPMSleepTypeLast = 8 }; enum { - kIOPMSleepReasonClamshell = 101, - kIOPMSleepReasonPowerButton = 102, - kIOPMSleepReasonSoftware = 103, - kIOPMSleepReasonOSSwitchHibernate = 104, - kIOPMSleepReasonIdle = 105, - kIOPMSleepReasonLowPower = 106, - kIOPMSleepReasonThermalEmergency = 107, - kIOPMSleepReasonMaintenance = 108, - kIOPMSleepReasonSleepServiceExit = 109, - kIOPMSleepReasonDarkWakeThermalEmergency = 110 + kIOPMSleepReasonClamshell = 101, + kIOPMSleepReasonPowerButton = 102, + kIOPMSleepReasonSoftware = 103, + kIOPMSleepReasonOSSwitchHibernate = 104, + kIOPMSleepReasonIdle = 105, + kIOPMSleepReasonLowPower = 106, + kIOPMSleepReasonThermalEmergency = 107, + kIOPMSleepReasonMaintenance = 108, + kIOPMSleepReasonSleepServiceExit = 109, + kIOPMSleepReasonDarkWakeThermalEmergency = 110 }; // Sleep Factor Mask / Bits enum { - kIOPMSleepFactorSleepTimerWake = 0x00000001ULL, - kIOPMSleepFactorLidOpen = 0x00000002ULL, - kIOPMSleepFactorACPower = 0x00000004ULL, - kIOPMSleepFactorBatteryLow = 0x00000008ULL, - kIOPMSleepFactorStandbyNoDelay = 0x00000010ULL, - kIOPMSleepFactorStandbyForced = 0x00000020ULL, - kIOPMSleepFactorStandbyDisabled = 0x00000040ULL, - kIOPMSleepFactorUSBExternalDevice = 0x00000080ULL, - kIOPMSleepFactorBluetoothHIDDevice = 0x00000100ULL, - kIOPMSleepFactorExternalMediaMounted = 0x00000200ULL, - kIOPMSleepFactorThunderboltDevice = 0x00000400ULL, - kIOPMSleepFactorRTCAlarmScheduled = 0x00000800ULL, - kIOPMSleepFactorMagicPacketWakeEnabled = 0x00001000ULL, - kIOPMSleepFactorHibernateForced = 0x00010000ULL, - kIOPMSleepFactorAutoPowerOffDisabled = 0x00020000ULL, - kIOPMSleepFactorAutoPowerOffForced = 0x00040000ULL, - kIOPMSleepFactorExternalDisplay = 0x00080000ULL, - kIOPMSleepFactorNetworkKeepAliveActive = 0x00100000ULL, - kIOPMSleepFactorLocalUserActivity = 0x00200000ULL, - kIOPMSleepFactorHibernateFailed = 0x00400000ULL, - kIOPMSleepFactorThermalWarning = 0x00800000ULL, - kIOPMSleepFactorDisplayCaptured = 0x01000000ULL + kIOPMSleepFactorSleepTimerWake = 0x00000001ULL, + kIOPMSleepFactorLidOpen = 0x00000002ULL, + kIOPMSleepFactorACPower = 0x00000004ULL, + kIOPMSleepFactorBatteryLow = 0x00000008ULL, + kIOPMSleepFactorStandbyNoDelay = 0x00000010ULL, + kIOPMSleepFactorStandbyForced = 0x00000020ULL, + kIOPMSleepFactorStandbyDisabled = 0x00000040ULL, + kIOPMSleepFactorUSBExternalDevice = 0x00000080ULL, + kIOPMSleepFactorBluetoothHIDDevice = 0x00000100ULL, + kIOPMSleepFactorExternalMediaMounted = 0x00000200ULL, + kIOPMSleepFactorThunderboltDevice = 0x00000400ULL, + kIOPMSleepFactorRTCAlarmScheduled = 0x00000800ULL, + kIOPMSleepFactorMagicPacketWakeEnabled = 0x00001000ULL, + kIOPMSleepFactorHibernateForced = 0x00010000ULL, + kIOPMSleepFactorAutoPowerOffDisabled = 0x00020000ULL, + kIOPMSleepFactorAutoPowerOffForced = 0x00040000ULL, + kIOPMSleepFactorExternalDisplay = 0x00080000ULL, + kIOPMSleepFactorNetworkKeepAliveActive = 0x00100000ULL, + kIOPMSleepFactorLocalUserActivity = 0x00200000ULL, + kIOPMSleepFactorHibernateFailed = 0x00400000ULL, + kIOPMSleepFactorThermalWarning = 0x00800000ULL, + kIOPMSleepFactorDisplayCaptured = 0x01000000ULL }; // Sleep flags enum { - kIOPMSleepFlagHibernate = 0x00000001, - kIOPMSleepFlagSleepTimerEnable = 0x00000002 + kIOPMSleepFlagHibernate = 0x00000001, + kIOPMSleepFlagSleepTimerEnable = 0x00000002 }; // Sleep phases @@ -189,10 +189,10 @@ enum { // hibernate_write_image return values enum{ - kIOHibernatePostWriteSleep = 0, - kIOHibernatePostWriteWake = 1, - kIOHibernatePostWriteHalt = 2, - kIOHibernatePostWriteRestart = 3 + kIOHibernatePostWriteSleep = 0, + kIOHibernatePostWriteWake = 1, + kIOHibernatePostWriteHalt = 2, + kIOHibernatePostWriteRestart = 3 }; // For evaluatePolicy() @@ -214,9 +214,9 @@ enum { // For requestFullWake() enum FullWakeReason { - kFullWakeReasonNone = 0, - kFullWakeReasonLocalUser = 1, - kFullWakeReasonDisplayOn = 2, - fFullWakeReasonDisplayOnAndLocalUser = 3 + kFullWakeReasonNone = 0, + kFullWakeReasonLocalUser = 1, + kFullWakeReasonDisplayOn = 2, + fFullWakeReasonDisplayOnAndLocalUser = 3 }; #endif /* osx_defines_h */