Re: Preventing IOKit kext unload
Re: Preventing IOKit kext unload
- Subject: Re: Preventing IOKit kext unload
- From: Nik Gervae <email@hidden>
- Date: Fri, 13 Aug 2010 14:21:13 -0700
I'm not sure exactly what your kext does, but here is some more info:
If you are using I/O Kit now, your kext should get unloaded automatically after about a minute when it has no instances of its defined classes. As long as the hardware is present, or have an IOUserClient connection (using a class defined by your kext!), you should have at least one instance of a class hanging around. There should be no need to unload such a kext explicitly, except in debug scenarios. So maybe you don't need to worry about preventing unload after all, as long as you manage autounload.
If you are doing something completely in software and just riding on IOService life cycle, and all you want is autounload, you can enable and manage that for a generic kext on Snow Leopard or later using OSKextRetainKextWithLoadTag() and OSKextReleaseKextWithLoadTag(). You could retain the kext when a daemon connects, and release it when the daemon disconnects, and your kext would unload after about a minute when its retain count goes to zero. See OSKextLib.h for more info.
(The old-school way of preventing a hybrid kext from autounloading was to just allocate an instance of a C++ class defined in the kext, and keep it around.)
Nik Gervae
Kext Management Engineer
Apple, Inc.
On 13 Aug, 2010, at 09:47 , Daniel Markarian wrote:
> Hey Bogdan,
>
> http://lists.apple.com/archives/darwin-kernel/2010/Jan/msg00028.html
>
> Dan
>
> Le 2010-08-13 à 04:55, Bogdan Harjoc a écrit :
>
>> Hello,
>>
>> I have recently had to move from a generic kext to an IOKit one, in
>> order to get the lifecycle functionality that IOKit offers. Since my
>> kext exposes a control device, I used to return an error in the kext
>> stop function if unregistering the control device failed (i.e. a
>> daemon was connected to it).
>>
>> But none of the IOService callbacks that kexts usually override (stop,
>> detach, free, ...) allow returning an error. And calling
>> provider->retain() in device->start() doesn't prevent device->stop()
>> from being called. Neither does device->adjustBusy(+1).
>>
>> What I am currently doing is I override device->terminate() and I
>> return false if the kext is busy. But since no IOKit documentation
>> recommends this, I assume it's not the proper way do prevent unload.
>>
>> My question is, how does one prevent cleanup when the kext is still
>> busy ? (particularly when there are non-IOKit resources in use)
>>
>> Thank you.
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Darwin-kernel mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Darwin-kernel mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden