简体   繁体   English

OSX kext:由于其他所有者拥有,因此无法在:: start()中打开IOResouces

[英]OSX kext: Can't open IOResouces in ::start() due to owned by some other

part of my work over the least years is USB virtulization under OSX and I found myself confused once again in front of a closed door. 在过去的几年中,我的工作的一部分是在OSX下进行USB虚拟化,我发现自己在封闭的门前再次感到困惑。

One of the first steps my kext (derived from IOUSBControllerV3) like to do is, after my provider (IOResources, because I'm virtuall) called my ::start() (::init() done), inside super class, to try a provider->open(this). 我的kext(派生自IOUSBControllerV3)要执行的第一步之一是,在提供程序(IOResources,因为我是virtuall)在超类内部调用了:: start()(:: init()完成)之后,尝试提供程序->打开(this)。

This is the normal way and works fine till the day, another (not from me) virtualisation kext is already loaded. 这是正常的方式,并且可以正常运行,直到另一天(不是我的)虚拟化kext已经加载。 Then the call failed and in consequence my ::start() and the kext installation failed at all (is non functional). 然后调用失败,结果我的:: start()和kext安装完全失败(不起作用)。

Grabbing the source code of the IOService class and get inforamtion by provider->isOpen() is true and provider->isOpen(this) is false IOResouces seemed to be owned by the other (virtulisation) kext. 抓住IOService类的源代码并通过provider-> isOpen()获取信息是正确的,而provider-> isOpen(this)是错误的IOResouces似乎是由另一个(虚拟化)kext拥有的。 Which means the IOService internal __owner is occupied exclusive by some other. 这意味着IOService内部__owner被其他人独占。

How can this be?? 怎么会这样?? How can IOResources be handle only one __owner at one time? IOResources如何一次只能处理一个__owner?

The provider->open() call is done inside my base class IOUSBController::start() and is still keep open till ::stop() is called, which means end of life. provider-> open()调用是在我的基类IOUSBController :: start()中完成的,并且一直保持打开状态,直到调用:: stop()为止,这意味着生命周期终止。

The failure returns from the call provider->open(this) inside my super class IOUSBController::start() inside my ::start() and depends on if another kext with provider IOResources is already loaded or not. 故障从我的:: start()内部的超类IOUSBController :: start()中的调用provider-> open(this)返回,并且取决于是否已加载具有提供者IOResources的另一个kext。

At this state there can't be any resouces conflict, because it is the very beginning of loading the kext. 在这种状态下,不会有任何资源冲突,因为这是加载kext的开始。 And in my imagination there can't be any resource conflict at all, because all is virtuall. 在我的想象中,根本不会发生任何资源冲突,因为一切都是虚拟的。

Or is it true, that IOResources can only handle (be provider for) one kext? 还是真的,IOResources只能处理(作为提供者)一个kext?

No, unbelievable. 不,令人难以置信。 My next idea was, that the foreigen kext is bad implemented (it's not perfect, because kextunload is not possible) but the provider->open(this) and ->close(this) calls are done in the holy apple base classes, which must be correct. 我的下一个想法是,前生的kext实现不好(因为kextunload是不可能的,所以它不是完美的),但是provider-> open(this)和-> close(this)调用是在神圣的苹果基类中完成的,必须正确。

Sorry, lot of text and thanks in advance for any constructive comment. 抱歉,大量文字,并感谢您提出的建设性意见。

Is there a good reason why you need to open() IOResources? 是否有充分的理由为什么需要open() IOResources? The point of open() in the context of IOService s is specifically for providing exclusive or at least reserved access to resources which don't support an arbitrary number of clients. IOService的上下文中, open()的点专门用于提供对不支持任意数量客户端的资源的独占或至少保留访问。 (eg a physical device can usually only have one driver loaded) IOResources is a dummy service which doesn't provide any features apart from the publishResource / resourceMatching mechanism. (例如,物理设备通常只能加载一个驱动程序)IOResources是虚拟服务,除了publishResource / resourceMatching机制之外,它不提供任何功能。 I'm not aware of any reason why you'd need to call open() on it. 我不知道您需要在其上调用open()的任何原因。

Edit: I'd missed that the call to open() is made by Apple's superclass, not the asker's code. 编辑:我错过了对open()的调用是由Apple的超类而不是asker的代码进行的。 In this case, as with any base classes that have special requirements on a provider object, I recommend writing your own provider class. 在这种情况下,与对提供程序对象有特殊要求的任何基类一样,建议您编写自己的提供程序类。 This provider class can be a client of IOResources, and the driver with the fussy base class can be a client of it. 此提供程序类可以是IOResources的客户端,而具有挑剔基类的驱动程序可以是它的客户端。

Following Phils (pmdj) very constructive proposals, he is obviously a member of the apple kext IOKit olymp, a simple enhancement seems to fix my problem. 遵循Phils(pmdj)极富建设性的建议,他显然是apple kext IOKit olymp的成员,一个简单的增强似乎可以解决我的问题。

In ::start(provider) I create (OSTypeAlloc()) a dummy IOService class dumprov, make dumprov->init() and dumprov->start(provider) and then call my superclass IOUSBController::start(dumprov) with success:-) 在:: start(provider)中,我创建(OSTypeAlloc())一个虚拟IOService类dumprov,使dumprov-> init()和dumprov-> start(provider),然后成功调用我的超类IOUSBController :: start(dumprov): - )

When I'm called finaly to ::stop(), I call IOUSBController::stop(dumprov) and make a dumprov->release(). 当我对:: stop()调用finaly时,我将调用IOUSBController :: stop(dumprov)并创建dumprov-> release()。 Fine! 精细!

Many thanks to pmdj!! 非常感谢pmdj!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM