1#include <IOKit/IOLib.h> 2#include "dtrace_dof.h" 3extern "C" { 4#include <pexpert/pexpert.h> //This is for debugging purposes ONLY 5} 6 7extern "C" { 8kern_return_t _dtrace_register_anon_DOF(char *, unsigned char *, unsigned int); 9} 10 11// Define my superclass 12#define super IOService 13 14// REQUIRED! This macro defines the class's constructors, destructors, 15// and several other methods I/O Kit requires. Do NOT use super as the 16// second parameter. You must use the literal name of the superclass. 17OSDefineMetaClassAndStructors(com_apple_driver_dtraceDOF, IOService) 18 19// There are byte-order dependancies in the dof_hdr emitted by the byte code compiler. 20// Rather than swizzle, we'll instead insist that each endian-ness is stored on a 21// distinguished property (and only that property is manipulated or referenced by its 22// matching architecture.) 23#if defined(__BIG_ENDIAN__) 24#define BYTE_CODE_CONTAINER "Anonymous DOF" 25#else 26#define BYTE_CODE_CONTAINER "DOF Anonymous" 27#endif 28 29bool com_apple_driver_dtraceDOF::init(OSDictionary *dict) 30{ 31 bool res = super::init(dict); 32 33 OSDictionary *AnonymousDOF = OSDynamicCast(OSDictionary, dict->getObject(BYTE_CODE_CONTAINER)); 34 35 if (AnonymousDOF) { 36 37 OSCollectionIterator *keyIterator = OSCollectionIterator::withCollection(AnonymousDOF); // must release 38 OSString *key = NULL; // do not release 39 40 while ((key = OSDynamicCast(OSString, keyIterator->getNextObject()))) { 41 OSData *dof = NULL; 42 43 dof = OSDynamicCast(OSData, AnonymousDOF->getObject(key)); 44 45 if (dof) { 46 const char *name = key->getCStringNoCopy(); 47 int len = dof->getLength(); 48 49 IOLog("com_apple_driver_dtraceDOF getLength(%s) = %d\n", name, len); 50 51 if (len > 0) { 52 kern_return_t ret = 53 _dtrace_register_anon_DOF((char *)name, (unsigned char *)(dof->getBytesNoCopy()), len); 54 55 if (KERN_SUCCESS != ret) 56 IOLog("com_apple_driver_dtraceDOF FAILED to register %s!\n", name); 57 } 58 } 59 } 60 keyIterator->release(); 61 } 62 63 return res; 64} 65 66void com_apple_driver_dtraceDOF::free(void) 67{ 68 super::free(); 69} 70 71IOService *com_apple_driver_dtraceDOF::probe(IOService *provider, SInt32 *score) 72{ 73 IOService *res = super::probe(provider, score); 74 return res; 75} 76 77bool com_apple_driver_dtraceDOF::start(IOService *provider) 78{ 79 bool res = super::start(provider); 80 return res; 81} 82 83void com_apple_driver_dtraceDOF::stop(IOService *provider) 84{ 85 super::stop(provider); 86} 87