Skip to content

Commit

Permalink
Fix minor typos in code and debug log. Plus better formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
leon9078 committed Apr 22, 2024
1 parent c309e34 commit 3072334
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 122 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions HibernationFixup/kern_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
12 changes: 6 additions & 6 deletions HibernationFixup/kern_hbfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
}

//==============================================================================
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
18 changes: 9 additions & 9 deletions HibernationFixup/kern_hbfx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -118,27 +118,27 @@ 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);
t_checkSystemSleepEnabled checkSystemSleepEnabled {nullptr};

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
Expand Down
Loading

0 comments on commit 3072334

Please sign in to comment.