在MacOS中关闭并重新启动通知



我希望我的iokit驱动程序获得power offrestart事件的通知。幸运的是,IOKIT使用IOService::systemWillShutDown方法提供了这种通知,该通知应被覆盖,还包括我的逻辑。

这是Apple技术文档的示例:

void MyExampleDriver::systemWillShutdown( IOOptionBits specifier )
{ 
    if ( kIOMessageSystemWillPowerOff == specifier ) {
        // System is shutting down; perform appropriate processing.
    } else if ( kIOMessageSystemWillRestart == specifier ) {
        // System is restarting; perform appropriate processing.
    }
    /*
     * You must call your superclass's implementation of systemWillShutdown as
     * soon as you're finished processing your shutdown or restart
     * because the shutdown will not proceed until you do.
     */
    super::systemWillShutdown( specifier );
}

但是,该事件并未如预期的那样显示。

也许错过了对平面阶段的注册(尽管并未清楚地将其视为从IOService中覆盖方法systemWillShutDown的先决条件。)

PMinit();
provider->joinPMtree(this);
registerPowerDriver(this, myPowerStates, 3);

加入PMTREE是否是强制性的,以便获得重新启动和关闭电源的电源事件?

在尝试调试问题时,我将断点列入方法IOService::systemWillShutdown,并且在关机关闭后,它确实被多次调用以下返回:

frame #0: 0xffffff80134b1b04 kernel`IOService::systemWillShutdown(this=0xffffff801a0cf800, specifier=3758096976) at IOServicePM.cpp:7167 [opt]
frame #1: 0xffffff80135123f1 kernel`PMHaltWorker::work(me=<unavailable>) at IOPMrootDomain.cpp:8165 [opt]
frame #2: 0xffffff8013512178 kernel`PMHaltWorker::main(arg=<unavailable>, waitResult=<unavailable>) at IOPMrootDomain.cpp:8095 [opt]

因此,似乎还有其他内核扩展名确实接到了此调用,并且它们在gPMHaltArray中列出 - 但我的Kext可能不存在。

我认为 pminit()呼叫是文档中报告的:

参与电源管理,以便您收到有关电源事件的通知,请确保驾驶员正确连接到电源平面

https://developer.apple.com/library/archive/documentation/devicedrivers/conepperual/iokitfundamentals/poperapemgmt/powermgmt/powermgmt.html#//poppermgmt.html#//apple_reff/doc/doc/uid/uid/uid/tp00000202020202020202020202020202020202020202020-TPXREF104

最新更新