自动卸载OS X驱动程序
Automatic unloading of an OS X driver
这是我的第一个问题:)
我目前正在编写一个通用的ext,它提供了一个字符设备和目标OSX 10.7+。它是纯C,没有IOKit/c++。(如果这很重要,我正在10.11上测试驱动程序。)
我想在所有指向字符设备的文件描述符关闭后卸载驱动程序,但这似乎不起作用。
根据Apple的OSKextRetainKextWithLoadTag
文档:
当autoload被启用时,在ext的最后一个引用被删除后不久,如果没有未完成的引用,并且没有它的Libkern c++子类的实例(如果有的话),它将被卸载。
…
定义IOService子类的文本自动启用了下载。其他kext可以使用引用计数来管理自动卸载,而无需定义和创建Libkern c++对象。
如上所述,我的ext没有任何IOService
子类(或任何类,就此而言),所以我应该能够使用OSKextRetainKextWithLoadTag
。
但是,在所有文件描述符关闭后,文本将永远保持加载状态:
static int cdev_open(dev_t dev, int flags, int devtype, struct proc *p)
{
/* ... */
return OSKextRetainKextWithLoadTag(OSKextGetCurrentLoadTag()) == kOSReturnSuccess) ? 0 : kOSReturnError
}
static int cdev_close(dev_t dev, int flags, int devtype, struct proc *p)
{
/* ... */
OSKextReleaseKextWithLoadTag(OSKextGetCurrentLoadTag());
return 0;
}
此外,我编写了我的kext的"混合"版本,其中我用一个提供IOService
子类(IOResources
作为提供者)的瘦c++包装器包装了启动和停止例程,以防通用kext不再支持卸载。相同的结果。
(我发现了几个使用OSKextRetainKextWithLoadTag
和OSKextReleaseKextWithLoadTag
的通用文本的例子,但是它们太老了,不知道它们是否适用于最新版本的OS x)
知道我做错了什么吗?
谢谢。
考虑以下generic
ext:
kern_return_t xxxKext_start(kmod_info_t * ki, void *d)
{
// this should set auto unload enabled
// and retain a refcount on the kext
OSKextRetainKextWithLoadTag(OSKextGetCurrentLoadTag());
// this should call OSKext::considerUnloads()
// and remove the search retain and the previous call retain
OSKextReleaseKextWithLoadTag(OSKextGetCurrentLoadTag());
// somewhere here or even before - kext suppose to be unloaded automatically (according to Apple docs)
return KERN_SUCCESS;
}
kern_return_t xxxKext_stop(kmod_info_t *ki, void *d)
{
return KERN_SUCCESS;
}
无论调用kextunload
或类似的方法,该文本都应该在短时间后自动消失。
在10.12.1
它工作完美。过一段时间(不是他们在文档中描述的那么短的延迟),它将从kextstat
命令中消失。
在10.11.6
中,由于某种原因,它将保持加载状态。
所以你没有做错任何事情,它只是在某些版本中坏了。
- Mongodb c++驱动程序:如何查询元素的数组
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 使用mongocxx驱动程序时包含头文件问题
- void*到驱动程序中的UnicodeString
- C++驱动程序看不到头文件
- 用于创建/注册虚拟存储设备的 IOKit 驱动程序
- 员工测试驱动程序数据结构
- 获取 OID(类型::b_oid)作为 MongoDB C++驱动程序中的字符串
- 如何在 c++ 中映射驱动程序?
- 如何在 cuda 中将 kd 树从主机复制到驱动程序
- Visual Studio 如何在内核模式驱动程序项目中使用C++标准库?
- 为什么我的驱动程序只读取部分字符串?
- 为 Sql 服务器实现 odbc 包装器.将数据库数据读取为字符或要求驱动程序将数据转换为 C 类型
- 如何在C++中将OID_PM_WOL_PATTERN_LIST发送到NDIS驱动程序?
- C++ 创建 NdisProt 驱动程序的句柄
- 使用 mongo c++ 驱动程序查询嵌套的 BSON 文档
- 有没有办法使用 mongocxx 驱动程序从 GridFS 集合的文件下载任意范围?
- 使用CMake ExternalProject_Add构建mongo cxx驱动程序
- 无法在OS X下编译CUDA驱动程序API示例
- 自动卸载OS X驱动程序