IOServiceMatching is failing

We have a kernel extension. The userspace to kernel communication happens using IOKit. Kernel extension is loaded successfully, checked using kextstat and ioreg. But still IOServiceMatching fails and returns NULL. This is occurring on specific setups, intermittently.


Steps to Reproduce:

  1. Write a custom kernel extension
  2. Load kernel extension
  3. In userspace code, call IOKit API named "IOServiceMatching", to get the service handle for same kernel extension.



Expected Results: IOServiceMatching should not return NULL as extension is loaded successfully.


Actual Results: IOServiceMatching is retuning NULL.


Version/Build: SDK Osx 10.11.


Configuration: Issue is reproducible on both Sierra and HighSierra.

Replies

You should run

ioreg
to double check that the service is registered correctly. Make sure the service is marked as
registered
because that’s a precondition for
IOServiceMatching
finding it.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

ioreg is showing it as registered.


id 0x10000065d, registered, matched, active, busy 0 (0 ms), retain 5>


I have attached all the logs here: https://bugreport.apple.com/web/?problemID=35331742

ioreg is showing it as registered.

Cool. Please post the following:

  • An

    ioreg
    dump of the properties that you’re trying to match on — For example:
    $ ioreg -c IOSerialBSDClient -w 0
    …
        | |   |   | +-o IOSerialBSDClient  <class IOSerialBSDClient, id 0x1000004c5, registered, matched, active, busy 0 (0 ms), retain 5>
        | |   |   |     {
        | |   |   |       "IOClass" = "IOSerialBSDClient"
        | |   |   |       "CFBundleIdentifier" = "com.apple.iokit.IOSerialFamily"
        | |   |   |       "IOProviderClass" = "IOSerialStreamSync"
        | |   |   |       "Product Name" = "LPSS Serial Adapter (2)"
        | |   |   |       "IOTTYBaseName" = "lpss-serial"
        | |   |   |       "IOSerialBSDClientType" = "IORS232SerialStream"
        | |   |   |       "IOProbeScore" = 1000
        | |   |   |       "IOCalloutDevice" = "/dev/cu.lpss-serial2"
        | |   |   |       "IOResourceMatch" = "IOBSD"
        | |   |   |       "IOMatchCategory" = "IODefaultMatchCategory"
        | |   |   |       "IOTTYDevice" = "lpss-serial2"
        | |   |   |       "IODialinDevice" = "/dev/tty.lpss-serial2"
        | |   |   |       "IOGeneralInterest" = "IOCommand is not serializable"
        | |   |   |       "IOTTYSuffix" = "2"
        | |   |   |     }
    …

    .

  • A dump of your matching dictionary — For example, if you have code like this:

    kr = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching(kIOSerialBSDServiceValue), &iterator);

    change it to look like this:

    CFDictionaryRef matchingDictionary = IOServiceMatching(kIOSerialBSDServiceValue);
    NSLog(@"%@", matchingDictionary);
    kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary, &iterator);

    and then post what got logged.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"