Chris
Chris

Reputation: 8442

OSDynamicCast not compiling in basic driver kit example

I've got a very simple driver kit driver. It's almost boiler plate.

I'm getting a build failure when trying to use OSDynamicCast, as per the below

kern_return_t IMPL(MyHIDDriver, NewUserClient) {
   
    IOService* client;
    
    auto ret = Create(this, "MyTest", &client);
    *userClient = OSDynamicCast(IOUserClient, client);
    return ret;
}

My use of OSDynamicCast is giving me the following issue.

Use of undeclared identifier 'gIOUserClientMetaClass'; did you mean 'gIOUserServerMetaClass'?

Before adding the NewUserClient override, the driver was running fine (I've observed it in the IORegistry).

I'm not sure what I'm missing here in Xcode that would cause this issue. Samples I've referenced, such as this, do exactly what I'm doing with OSDynamicCast.

enter image description here

Upvotes: 1

Views: 138

Answers (1)

pmdj
pmdj

Reputation: 23438

Is the IOUserClient header #included somewhere in this compilation unit? It sounds like you're simply missing

#include <DriverKit/IOUserClient.h>

Entirely unrelated to the issue you're experiencing, but you may want to initialise the client variable to a nullptr to avoid issues with undefined behaviour in case Create fails:

IOService* client = nullptr;

The documentation does not guarantee that it will be set to this automatically if the call fails, so the subsequent OSDynamicCast would be exposed to undefined behaviour.

Upvotes: 1

Related Questions