3 ms·
If the Apple story is indeed true, there's a certain irony to it: device drivers in the OS X/iOS kernel are written against a C++ API called I/O Kit. For forwar
by pmjordan 14y ago
If the Apple story is indeed true, there's a certain irony to it: device drivers in the OS X/iOS kernel are written against a C++ API called I/O Kit. For forward-compatibility with newer kernel versions, all the public classes contain a significant number of dummy virtual functions, and many also have a pointer member variable called "reserved" so they can later add new fields if they need to without changing the class size.
E.g.: http://www.opensource.apple.com/source/xnu/xnu-1699.24.23/iokit/IOKit/IOMemoryDescriptor.h http://www.opensource.apple.com/source/xnu/xnu-1699.24.23/io... - note the
ExpansionData * reserved;
member variable and the block of
private:
OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 0);
#ifdef __LP64__
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 1);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 2);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 3);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 4);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 5);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 6);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 7);
#else /* !__LP64__ */
OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 1);
OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 2);
OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 3);
OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 4);
OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 5);
OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 6);
OSMetaClassDeclareReservedUsed(IOMemoryDescriptor, 7);
#endif /* !__LP64__ */
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 8);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 9);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 10);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 11);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 12);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 13);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 14);
OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 15);
dummy methods.
There is also a system in place for the linker to patch the vtables of dynamically loaded classes (i.e. third-party drivers). They've also built an Objective-C-like Class/metaclass system in C++ via macros for I/O Kit, for some very basic reflection (mainly to keep track of whether instances of a class exist, and if not, unloading the kernel module).