1

我希望我的 IOKit 驱动程序能够收到power off事件通知restart。幸运的是,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 );
}

但是,该事件未按预期显示。

可能错过了对电源平面阶段的注册(尽管没有明确说明它是从 覆盖该方法的先决条件systemWillShutDownIOService

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 可能不存在..

4

1 回答 1

1

我认为PMinit()调用是强制性的,如文档中所述:

要参与电源管理以便接收电源事件通知,请确保您的驱动程序正确连接到电源平面

https://developer.apple.com/library/archive/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/PowerMgmt/PowerMgmt.html#//apple_ref/doc/uid/TP0000020-TPXREF104

于 2018-08-10T16:02:37.613 回答