在 DriverKit 中可以将哪些选项传递给 IOService::Terminate

What options can be passed to IOService::Terminate in DriverKit

virtual kern_return_t IOService::Terminate(uint64_t options) 说你可以传递带有选项的参数。我想知道有哪些不同的选择?文档什么也没说。

来自 XNU 源代码包(7195.50.7.100.1,macOS 11.0.1)的 IOService.iig 文件包含以下内容:

    /*!
     * @brief       Start an IOService termination.
     * @discussion  An IOService object created with Create() may be removed by calling Terminate().
     *              The termination is asynchronous and will later call Stop() on the service.
     * @param       options No options are currently defined, pass zero.
     * @return      kIOReturnSuccess on success. See IOReturn.h for error codes.
     */
    virtual kern_return_t
    Terminate(
        uint64_t             options);

options No options are currently defined, pass zero.

在内核方面,IOService::terminate 确实有一些有效的选项。但是,我不知道您是否可以从 DriverKit 传递这些。它们可能会被过滤:

  • kIOServiceSynchronous:

kIOServiceSynchronous may be passed to cause terminate to not return until the service is finalized.

  • kIOServiceRequired:

By default, if any client has the service open, terminate fails. If the kIOServiceRequired flag is passed however, terminate will be successful though further progress in the destruction of the IOService object will not proceed until the last client has closed it.

  • kIOServiceTerminateWithRematch:这个我不是很清楚,没有文档,但是粗略的看了下相关代码可以看出,当一个对象这样终止时,它的provider会重新触发I/O 套件匹配.

还有一些,例如 kIOServiceRecursing,它们在从 terminate() 本身转发到各种终止阶段函数时在内部使用,以跟踪终止状态。这些通常不应该在 kext 代码中使用,我非常怀疑如果你在 DriverKit 中使用它们,它们是否会被传递。