In my DriverKit driver, I'd like to create a custom class that inherits from OSObject so that I can store it in an OSArray (and other OSObject derived collections).
The documentation for kexts and IOKit indicates that you use the OSDeclareDefaultStructors and OSDefineMetaClassAndStructors macros to define constructors, destructors, and the metaclass info. However, these macros don't seem to exist in DriverKit.
I've done something like this:
class MyCustomObject: public OSObject
{
using super = OSObject;
public:
virtual bool init() override;
virtual void free() override;
}
bool MyCustomClass::init()
{
if (!super::init()) {
os_log(OS_LOG_DEFAULT, "[Driver] MyCustomClass super::init() failed");
return false;
}
// Initialize stuff
return true;
}
void MyCustomClass::free(void)
{
// Release retained members
super::free();
}
That works as far as it goes, and compiles. But I can't new an instance of it, which also means I don't know how to implement the traditional static withFoo() type method to create one.
Is creating a custom OSObject subclass in a DriverKit dext supported? If so, how should that be set up?