Taking reference on kext from user-space daemon

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

Taking reference on kext from user-space daemon

Postby adam81 » Sun Aug 20, 2017 7:53 am

I've got Kext which give service to user-space client that is using iokit service communication.

I'd like that the client will take reference on the kext, so that it wouldn't be possible to unload the kext while the client is sill up, and when the client goes down, the kext should terminate as well.

according to the documentation I can use IOServiceOpen and IOConnectAddRef, but kextunload stills removes the driver.

kextstat also shows that no references are taken on the driver, those are references by other drivers as it mentioned in the documentation, but I thought that the above commands will do the trick.

    Index Refs Address Size Wired Name (Version) UUID <Linked Against>
    1 100 0xffffff7f80a46000 0x9d90 0x9d90 com.apple.kpi.bsd (16.7.0) 410B3B98-9DAB-4590-9086-7C57A5B3099A
    2 8 0xffffff7f80fc3000 0x3940 0x3940 com.apple.kpi.dsep (16.7.0) FA744B47-913C-4B5D-8C16-2F8005D85935
    3 127 0xffffff7f80a04000 0x21040 0x21040 com.apple.kpi.iokit (16.7.0) 80F2DA67-C67B-4583-9B09-082DB11F69FC
    ...
    170 0 0xffffff7f80a04000 0x21040 0x21040 com.my-driver.noo (1.0.0) 53390CCD-55F0-315F-BBD7-21645800E4A0

what should I do in order to increase the #Refs from the above chart ?
adam81
 
Posts: 18
Joined: Mon Jan 25, 2016 9:26 am

Re: Taking reference on kext from user-space daemon

Postby morpheus » Tue Aug 22, 2017 10:33 pm

Rather than messing with the refs, you can refuse to unload and mark yourself in use from kernel space. That might be easier.
morpheus
Site Admin
 
Posts: 532
Joined: Thu Apr 11, 2013 6:24 pm

Re: Taking reference on kext from user-space daemon

Postby adam81 » Wed Aug 23, 2017 2:18 pm

Thanks for the advice, but how exactly should I prevent the driver unloading from within the driver ? is there any particular kpi for this purpose ?

according to 'kextstat' official documentation, Refs defined as "The number of references to this kext by others. If nonzero, the kext cannot be unloaded.".

Not really sure what is "others"... is it other kexts, or also user-space entities.

thanks
adam81
 
Posts: 18
Joined: Mon Jan 25, 2016 9:26 am


Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 3 guests