我想在没有连接交流适配器的情况下以翻盖模式使用 Macbook air。但是,当我合上盖子时,Mac OS 会强制系统进入睡眠状态。
我发现来自苹果开源的 XNU 内核的这一部分可能与这种行为有关:
iokit/内核/IOPMrootDomain.cpp
...
6362 /*
6363 * Evaluate clamshell and SLEEP if appropiate
6364 */
6365 if (eval_clamshell && clamshellClosed)
6366 {
6367 if (shouldSleepOnClamshellClosed())
6368 privateSleepSystem (kIOPMSleepReasonClamshell);
6369 else
6370 evaluatePolicy( kStimulusDarkWakeEvaluate );
6371 }
...
3061 //******************************************************************************
3062 // sleepOnClamshellClosed
3063 //
3064 // contains the logic to determine if the system should sleep when the clamshell
3065 // is closed.
3066 //******************************************************************************
3067
3068 bool IOPMrootDomain::shouldSleepOnClamshellClosed( void )
3069 {
3070 if (!clamshellExists)
3071 return false;
3072
3073 DLOG("clamshell closed %d, disabled %d, desktopMode %d, ac %d sleepDisabled %d\n",
3074 clamshellClosed, clamshellDisabled, desktopMode, acAdaptorConnected, clamshellSleepDisabled);
3075
3076 return ( !clamshellDisabled && !(desktopMode && acAdaptorConnected) && !clamshellSleepDisabled );
3077 }
当然,我可以编译内核,但我怀疑它是否是最新的 Mavericks 内核。所以我想知道我是否可以通过插入动态库来覆盖内核空间函数,就像我们为用户空间函数所做的那样。