1c1dac77fSApple OSS Distributions /* 23ca3bd55SApple OSS Distributions * Copyright (c) 2000 Apple Inc. All rights reserved. 3c1dac77fSApple OSS Distributions * 4e13b1fa5SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5c1dac77fSApple OSS Distributions * 6e13b1fa5SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7e13b1fa5SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8e13b1fa5SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9e13b1fa5SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10e13b1fa5SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11e13b1fa5SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12e13b1fa5SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13e13b1fa5SApple OSS Distributions * terms of an Apple operating system software license agreement. 14c1dac77fSApple OSS Distributions * 15e13b1fa5SApple OSS Distributions * Please obtain a copy of the License at 16e13b1fa5SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17e13b1fa5SApple OSS Distributions * 18e13b1fa5SApple OSS Distributions * The Original Code and all software distributed under the License are 19e13b1fa5SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20c1dac77fSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21c1dac77fSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22e13b1fa5SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23e13b1fa5SApple OSS Distributions * Please see the License for the specific language governing rights and 24e13b1fa5SApple OSS Distributions * limitations under the License. 25c1dac77fSApple OSS Distributions * 26e13b1fa5SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27c1dac77fSApple OSS Distributions */ 28c1dac77fSApple OSS Distributions /* OSObject.cpp created by gvdl on Fri 1998-11-17 */ 29c1dac77fSApple OSS Distributions 30c1dac77fSApple OSS Distributions #include <libkern/c++/OSObject.h> 31a3bb9fccSApple OSS Distributions #include <libkern/c++/OSString.h> 32e13b1fa5SApple OSS Distributions #include <libkern/c++/OSArray.h> 33c1dac77fSApple OSS Distributions #include <libkern/c++/OSSerialize.h> 34c1dac77fSApple OSS Distributions #include <libkern/c++/OSLib.h> 35e13b1fa5SApple OSS Distributions #include <libkern/OSDebug.h> 36c1dac77fSApple OSS Distributions #include <libkern/c++/OSCPPDebug.h> 37e13b1fa5SApple OSS Distributions #include <IOKit/IOKitDebug.h> 38c1dac77fSApple OSS Distributions #include <libkern/OSAtomic.h> 39c1dac77fSApple OSS Distributions 40fad439e7SApple OSS Distributions #include <libkern/c++/OSCollection.h> 41fad439e7SApple OSS Distributions 42e13b1fa5SApple OSS Distributions #include <kern/queue.h> 43e13b1fa5SApple OSS Distributions 44c1dac77fSApple OSS Distributions __BEGIN_DECLS 45*bb611c8fSApple OSS Distributions size_t debug_ivars_size; 46c1dac77fSApple OSS Distributions __END_DECLS 47c1dac77fSApple OSS Distributions 48c1dac77fSApple OSS Distributions 49c1dac77fSApple OSS Distributions // OSDefineMetaClassAndAbstractStructors(OSObject, 0); 50c1dac77fSApple OSS Distributions /* Class global data */ 51c1dac77fSApple OSS Distributions OSObject::MetaClass OSObject::gMetaClass; 52c1dac77fSApple OSS Distributions const OSMetaClass * const OSObject::metaClass = &OSObject::gMetaClass; 53a5e72196SApple OSS Distributions const OSMetaClass * const OSObject::superClass = NULL; 54c1dac77fSApple OSS Distributions 55c1dac77fSApple OSS Distributions /* Class member functions - Can't use defaults */ 56a5e72196SApple OSS Distributions OSObject::~OSObject() 57a5e72196SApple OSS Distributions { 58a5e72196SApple OSS Distributions } 59a5e72196SApple OSS Distributions const OSMetaClass * 60a5e72196SApple OSS Distributions OSObject::getMetaClass() const 61a5e72196SApple OSS Distributions { 62a5e72196SApple OSS Distributions return &gMetaClass; 63a5e72196SApple OSS Distributions } 64a5e72196SApple OSS Distributions OSObject * 65a5e72196SApple OSS Distributions OSObject::MetaClass::alloc() const 66a5e72196SApple OSS Distributions { 67a5e72196SApple OSS Distributions return NULL; 68a5e72196SApple OSS Distributions } 69c1dac77fSApple OSS Distributions 70c1dac77fSApple OSS Distributions /* The OSObject::MetaClass constructor */ 71c1dac77fSApple OSS Distributions OSObject::MetaClass::MetaClass() 72c1dac77fSApple OSS Distributions : OSMetaClass("OSObject", OSObject::superClass, sizeof(OSObject)) 73a5e72196SApple OSS Distributions { 74a5e72196SApple OSS Distributions } 75c1dac77fSApple OSS Distributions 76c1dac77fSApple OSS Distributions // Virtual Padding 77c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 0); 78c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 1); 79c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 2); 80c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 3); 81c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 4); 82c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 5); 83c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 6); 84c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 7); 85c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 8); 86c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 9); 87c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 10); 88c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 11); 89c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 12); 90c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 13); 91c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 14); 92c1dac77fSApple OSS Distributions OSMetaClassDefineReservedUnused(OSObject, 15); 93e13b1fa5SApple OSS Distributions 94a5e72196SApple OSS Distributions static const char * 95a5e72196SApple OSS Distributions getClassName(const OSObject *obj) 96fad439e7SApple OSS Distributions { 97fad439e7SApple OSS Distributions const OSMetaClass *meta = obj->getMetaClass(); 98fad439e7SApple OSS Distributions return (meta) ? meta->getClassName() : "unknown class?"; 99fad439e7SApple OSS Distributions } 100c1dac77fSApple OSS Distributions 101a5e72196SApple OSS Distributions int 102a5e72196SApple OSS Distributions OSObject::getRetainCount() const 103c1dac77fSApple OSS Distributions { 104fad439e7SApple OSS Distributions return (int) ((UInt16) retainCount); 105c1dac77fSApple OSS Distributions } 106c1dac77fSApple OSS Distributions 107a5e72196SApple OSS Distributions bool 108a5e72196SApple OSS Distributions OSObject::taggedTryRetain(const void *tag) const 109c1dac77fSApple OSS Distributions { 110368ad365SApple OSS Distributions volatile UInt32 *countP = (volatile UInt32 *) &retainCount; 111368ad365SApple OSS Distributions UInt32 inc = 1; 112368ad365SApple OSS Distributions UInt32 origCount; 113368ad365SApple OSS Distributions UInt32 newCount; 114368ad365SApple OSS Distributions 115368ad365SApple OSS Distributions // Increment the collection bucket. 116a5e72196SApple OSS Distributions if ((const void *) OSTypeID(OSCollection) == tag) { 117368ad365SApple OSS Distributions inc |= (1UL << 16); 118a5e72196SApple OSS Distributions } 119368ad365SApple OSS Distributions 120368ad365SApple OSS Distributions do { 121368ad365SApple OSS Distributions origCount = *countP; 122368ad365SApple OSS Distributions if (((UInt16) origCount | 0x1) == 0xffff) { 123368ad365SApple OSS Distributions if (origCount & 0x1) { 124368ad365SApple OSS Distributions // If count == 0xffff that means we are freeing now so we can 125368ad365SApple OSS Distributions // just return obviously somebody is cleaning up dangling 126368ad365SApple OSS Distributions // references. 127a5e72196SApple OSS Distributions return false; 128a5e72196SApple OSS Distributions } else { 129368ad365SApple OSS Distributions // If count == 0xfffe then we have wrapped our reference count. 130368ad365SApple OSS Distributions // We should stop counting now as this reference must be 131368ad365SApple OSS Distributions // leaked rather than accidently wrapping around the clock and 132368ad365SApple OSS Distributions // freeing a very active object later. 133368ad365SApple OSS Distributions 134fad439e7SApple OSS Distributions #if !DEBUG 135368ad365SApple OSS Distributions break; // Break out of update loop which pegs the reference 1363ca3bd55SApple OSS Distributions #else /* DEBUG */ 137368ad365SApple OSS Distributions // @@@ gvdl: eventually need to make this panic optional 138368ad365SApple OSS Distributions // based on a boot argument i.e. debug= boot flag 139a5e72196SApple OSS Distributions panic("OSObject::refcount: " 140a5e72196SApple OSS Distributions "About to wrap the reference count, reference leak?"); 141368ad365SApple OSS Distributions #endif /* !DEBUG */ 142368ad365SApple OSS Distributions } 143368ad365SApple OSS Distributions } 144fad439e7SApple OSS Distributions 145fad439e7SApple OSS Distributions newCount = origCount + inc; 1463ca3bd55SApple OSS Distributions } while (!OSCompareAndSwap(origCount, newCount, const_cast<UInt32 *>(countP))); 147a5e72196SApple OSS Distributions 148a5e72196SApple OSS Distributions return true; 149c1dac77fSApple OSS Distributions } 150c1dac77fSApple OSS Distributions 151a5e72196SApple OSS Distributions void 152a5e72196SApple OSS Distributions OSObject::taggedRetain(const void *tag) const 153a5e72196SApple OSS Distributions { 154a5e72196SApple OSS Distributions if (!taggedTryRetain(tag)) { 155a5e72196SApple OSS Distributions panic("OSObject::refcount: Attempting to retain a freed object"); 156a5e72196SApple OSS Distributions } 157a5e72196SApple OSS Distributions } 158a5e72196SApple OSS Distributions 159a5e72196SApple OSS Distributions void 160a5e72196SApple OSS Distributions OSObject::taggedRelease(const void *tag) const 161c1dac77fSApple OSS Distributions { 162fad439e7SApple OSS Distributions taggedRelease(tag, 1); 163fad439e7SApple OSS Distributions } 164fad439e7SApple OSS Distributions 165a5e72196SApple OSS Distributions void 166a5e72196SApple OSS Distributions OSObject::taggedRelease(const void *tag, const int when) const 167fad439e7SApple OSS Distributions { 168fad439e7SApple OSS Distributions volatile UInt32 *countP = (volatile UInt32 *) &retainCount; 169fad439e7SApple OSS Distributions UInt32 dec = 1; 170fad439e7SApple OSS Distributions UInt32 origCount; 171fad439e7SApple OSS Distributions UInt32 newCount; 172fad439e7SApple OSS Distributions UInt32 actualCount; 173fad439e7SApple OSS Distributions 174368ad365SApple OSS Distributions // Increment the collection bucket. 175a5e72196SApple OSS Distributions if ((const void *) OSTypeID(OSCollection) == tag) { 176fad439e7SApple OSS Distributions dec |= (1UL << 16); 177a5e72196SApple OSS Distributions } 178fad439e7SApple OSS Distributions 179fad439e7SApple OSS Distributions do { 180fad439e7SApple OSS Distributions origCount = *countP; 181fad439e7SApple OSS Distributions 182368ad365SApple OSS Distributions if (((UInt16) origCount | 0x1) == 0xffff) { 183368ad365SApple OSS Distributions if (origCount & 0x1) { 184368ad365SApple OSS Distributions // If count == 0xffff that means we are freeing now so we can 185368ad365SApple OSS Distributions // just return obviously somebody is cleaning up some dangling 186368ad365SApple OSS Distributions // references. So we blow out immediately. 187368ad365SApple OSS Distributions return; 188a5e72196SApple OSS Distributions } else { 189368ad365SApple OSS Distributions // If count == 0xfffe then we have wrapped our reference 190368ad365SApple OSS Distributions // count. We should stop counting now as this reference must be 191368ad365SApple OSS Distributions // leaked rather than accidently freeing an active object later. 192368ad365SApple OSS Distributions 193368ad365SApple OSS Distributions #if !DEBUG 194368ad365SApple OSS Distributions return; // return out of function which pegs the reference 1953ca3bd55SApple OSS Distributions #else /* DEBUG */ 196368ad365SApple OSS Distributions // @@@ gvdl: eventually need to make this panic optional 197368ad365SApple OSS Distributions // based on a boot argument i.e. debug= boot flag 198368ad365SApple OSS Distributions panic("OSObject::refcount: %s", 199368ad365SApple OSS Distributions "About to unreference a pegged object, reference leak?"); 200368ad365SApple OSS Distributions #endif /* !DEBUG */ 201368ad365SApple OSS Distributions } 202368ad365SApple OSS Distributions } 203fad439e7SApple OSS Distributions actualCount = origCount - dec; 204a5e72196SApple OSS Distributions if ((UInt16) actualCount < when) { 205368ad365SApple OSS Distributions newCount = 0xffff; 206a5e72196SApple OSS Distributions } else { 207fad439e7SApple OSS Distributions newCount = actualCount; 208a5e72196SApple OSS Distributions } 2093ca3bd55SApple OSS Distributions } while (!OSCompareAndSwap(origCount, newCount, const_cast<UInt32 *>(countP))); 210fad439e7SApple OSS Distributions 211fad439e7SApple OSS Distributions // 212fad439e7SApple OSS Distributions // This panic means that we have just attempted to release an object 2133ca3bd55SApple OSS Distributions // whose retain count has gone to less than the number of collections 214fad439e7SApple OSS Distributions // it is a member off. Take a panic immediately. 2153ca3bd55SApple OSS Distributions // In fact the panic MAY not be a registry corruption but it is 216fad439e7SApple OSS Distributions // ALWAYS the wrong thing to do. I call it a registry corruption 'cause 217fad439e7SApple OSS Distributions // the registry is the biggest single use of a network of collections. 218fad439e7SApple OSS Distributions // 2193ca3bd55SApple OSS Distributions // xxx - this error message is overly-specific; 2203ca3bd55SApple OSS Distributions // xxx - any code in the kernel could trip this, 2213ca3bd55SApple OSS Distributions // xxx - and it applies as noted to all collections, not just the registry 2223ca3bd55SApple OSS Distributions if ((UInt16) actualCount < (actualCount >> 16)) { 2233ca3bd55SApple OSS Distributions panic("A kext releasing a(n) %s has corrupted the registry.", 224fad439e7SApple OSS Distributions getClassName(this)); 2253ca3bd55SApple OSS Distributions } 226fad439e7SApple OSS Distributions 227fad439e7SApple OSS Distributions // Check for a 'free' condition and that if we are first through 2283ca3bd55SApple OSS Distributions if (newCount == 0xffff) { 2293ca3bd55SApple OSS Distributions (const_cast<OSObject *>(this))->free(); 2303ca3bd55SApple OSS Distributions } 231c1dac77fSApple OSS Distributions } 232c1dac77fSApple OSS Distributions 233a5e72196SApple OSS Distributions void 234a5e72196SApple OSS Distributions OSObject::release() const 235c1dac77fSApple OSS Distributions { 236a5e72196SApple OSS Distributions taggedRelease(NULL); 237fad439e7SApple OSS Distributions } 238fad439e7SApple OSS Distributions 239a5e72196SApple OSS Distributions void 240a5e72196SApple OSS Distributions OSObject::retain() const 241fad439e7SApple OSS Distributions { 242a5e72196SApple OSS Distributions taggedRetain(NULL); 243fad439e7SApple OSS Distributions } 244fad439e7SApple OSS Distributions 24588cc0b97SApple OSS Distributions extern "C" void 24688cc0b97SApple OSS Distributions osobject_retain(void * object) 24788cc0b97SApple OSS Distributions { 24888cc0b97SApple OSS Distributions ((OSObject *)object)->retain(); 24988cc0b97SApple OSS Distributions } 25088cc0b97SApple OSS Distributions 25188cc0b97SApple OSS Distributions extern "C" void 25288cc0b97SApple OSS Distributions osobject_release(void * object) 25388cc0b97SApple OSS Distributions { 25488cc0b97SApple OSS Distributions ((OSObject *)object)->release(); 25588cc0b97SApple OSS Distributions } 25688cc0b97SApple OSS Distributions 257a5e72196SApple OSS Distributions void 258a5e72196SApple OSS Distributions OSObject::release(int when) const 259fad439e7SApple OSS Distributions { 260a5e72196SApple OSS Distributions taggedRelease(NULL, when); 261c1dac77fSApple OSS Distributions } 262c1dac77fSApple OSS Distributions 263a5e72196SApple OSS Distributions bool 264a5e72196SApple OSS Distributions OSObject::serialize(OSSerialize *s) const 265c1dac77fSApple OSS Distributions { 266a3bb9fccSApple OSS Distributions char cstr[128]; 267a3bb9fccSApple OSS Distributions bool ok; 268c1dac77fSApple OSS Distributions 269a3bb9fccSApple OSS Distributions snprintf(cstr, sizeof(cstr), "%s is not serializable", getClassName(this)); 270c1dac77fSApple OSS Distributions 271a3bb9fccSApple OSS Distributions OSString * str; 272a3bb9fccSApple OSS Distributions str = OSString::withCStringNoCopy(cstr); 273a5e72196SApple OSS Distributions if (!str) { 274a5e72196SApple OSS Distributions return false; 275a5e72196SApple OSS Distributions } 276c1dac77fSApple OSS Distributions 277a3bb9fccSApple OSS Distributions ok = str->serialize(s); 278a3bb9fccSApple OSS Distributions str->release(); 279a3bb9fccSApple OSS Distributions 280a5e72196SApple OSS Distributions return ok; 281c1dac77fSApple OSS Distributions } 282c1dac77fSApple OSS Distributions 283a5e72196SApple OSS Distributions void * 284a5e72196SApple OSS Distributions OSObject::operator new(size_t size) 285c1dac77fSApple OSS Distributions { 2860f3703acSApple OSS Distributions #if IOTRACKING 287a5e72196SApple OSS Distributions if (kIOTracking & gIOKitDebug) { 288a5e72196SApple OSS Distributions return OSMetaClass::trackedNew(size); 289a5e72196SApple OSS Distributions } 2900f3703acSApple OSS Distributions #endif 291e13b1fa5SApple OSS Distributions 292*bb611c8fSApple OSS Distributions void *mem = kheap_alloc_tag_bt(KHEAP_DEFAULT, size, 293*bb611c8fSApple OSS Distributions (zalloc_flags_t) (Z_WAITOK | Z_ZERO), VM_KERN_MEMORY_LIBKERN); 294c1dac77fSApple OSS Distributions assert(mem); 2950f3703acSApple OSS Distributions OSIVAR_ACCUMSIZE(size); 296c1dac77fSApple OSS Distributions 297e13b1fa5SApple OSS Distributions return (void *) mem; 298c1dac77fSApple OSS Distributions } 299c1dac77fSApple OSS Distributions 300a5e72196SApple OSS Distributions void 301a5e72196SApple OSS Distributions OSObject::operator delete(void * mem, size_t size) 302c1dac77fSApple OSS Distributions { 303a5e72196SApple OSS Distributions if (!mem) { 304a5e72196SApple OSS Distributions return; 305a5e72196SApple OSS Distributions } 306e13b1fa5SApple OSS Distributions 3070f3703acSApple OSS Distributions #if IOTRACKING 308a5e72196SApple OSS Distributions if (kIOTracking & gIOKitDebug) { 309a5e72196SApple OSS Distributions return OSMetaClass::trackedDelete(mem, size); 310a5e72196SApple OSS Distributions } 3110f3703acSApple OSS Distributions #endif 312e13b1fa5SApple OSS Distributions 313*bb611c8fSApple OSS Distributions kern_os_kfree(mem, size); 3140f3703acSApple OSS Distributions OSIVAR_ACCUMSIZE(-size); 315e13b1fa5SApple OSS Distributions } 316e13b1fa5SApple OSS Distributions 317*bb611c8fSApple OSS Distributions __BEGIN_DECLS 318*bb611c8fSApple OSS Distributions void *OSObject_operator_new_external(size_t size); 319*bb611c8fSApple OSS Distributions void * 320*bb611c8fSApple OSS Distributions OSObject_operator_new_external(size_t size) 321*bb611c8fSApple OSS Distributions { 322*bb611c8fSApple OSS Distributions #if IOTRACKING 323*bb611c8fSApple OSS Distributions if (kIOTracking & gIOKitDebug) { 324*bb611c8fSApple OSS Distributions return OSMetaClass::trackedNew(size); 325*bb611c8fSApple OSS Distributions } 326*bb611c8fSApple OSS Distributions #endif 327*bb611c8fSApple OSS Distributions 328*bb611c8fSApple OSS Distributions void * mem = kheap_alloc_tag_bt(KHEAP_KEXT, size, 329*bb611c8fSApple OSS Distributions (zalloc_flags_t) (Z_WAITOK | Z_ZERO), VM_KERN_MEMORY_LIBKERN); 330*bb611c8fSApple OSS Distributions assert(mem); 331*bb611c8fSApple OSS Distributions OSIVAR_ACCUMSIZE(size); 332*bb611c8fSApple OSS Distributions 333*bb611c8fSApple OSS Distributions return (void *) mem; 334*bb611c8fSApple OSS Distributions } 335*bb611c8fSApple OSS Distributions 336*bb611c8fSApple OSS Distributions void OSObject_operator_delete_external(void * mem, size_t size); 337*bb611c8fSApple OSS Distributions void 338*bb611c8fSApple OSS Distributions OSObject_operator_delete_external(void * mem, size_t size) 339*bb611c8fSApple OSS Distributions { 340*bb611c8fSApple OSS Distributions if (!mem) { 341*bb611c8fSApple OSS Distributions return; 342*bb611c8fSApple OSS Distributions } 343*bb611c8fSApple OSS Distributions 344*bb611c8fSApple OSS Distributions #if IOTRACKING 345*bb611c8fSApple OSS Distributions if (kIOTracking & gIOKitDebug) { 346*bb611c8fSApple OSS Distributions return OSMetaClass::trackedDelete(mem, size); 347*bb611c8fSApple OSS Distributions } 348*bb611c8fSApple OSS Distributions #endif 349*bb611c8fSApple OSS Distributions 350*bb611c8fSApple OSS Distributions kheap_free(KHEAP_KEXT, mem, size); 351*bb611c8fSApple OSS Distributions OSIVAR_ACCUMSIZE(-size); 352*bb611c8fSApple OSS Distributions } 353*bb611c8fSApple OSS Distributions __END_DECLS 354a5e72196SApple OSS Distributions bool 355a5e72196SApple OSS Distributions OSObject::init() 3560f3703acSApple OSS Distributions { 3570f3703acSApple OSS Distributions #if IOTRACKING 358a5e72196SApple OSS Distributions if (kIOTracking & gIOKitDebug) { 359a5e72196SApple OSS Distributions getMetaClass()->trackedInstance(this); 360a5e72196SApple OSS Distributions } 3610f3703acSApple OSS Distributions #endif 3620f3703acSApple OSS Distributions return true; 3630f3703acSApple OSS Distributions } 364c1dac77fSApple OSS Distributions 365a5e72196SApple OSS Distributions void 366a5e72196SApple OSS Distributions OSObject::free() 3670f3703acSApple OSS Distributions { 3680f3703acSApple OSS Distributions const OSMetaClass *meta = getMetaClass(); 3690f3703acSApple OSS Distributions 370a5e72196SApple OSS Distributions if (meta) { 3710f3703acSApple OSS Distributions meta->instanceDestructed(); 3720f3703acSApple OSS Distributions #if IOTRACKING 373a5e72196SApple OSS Distributions if (kIOTracking & gIOKitDebug) { 374a5e72196SApple OSS Distributions getMetaClass()->trackedFree(this); 375a5e72196SApple OSS Distributions } 3760f3703acSApple OSS Distributions #endif 3770f3703acSApple OSS Distributions } 3780f3703acSApple OSS Distributions delete this; 3790f3703acSApple OSS Distributions } 3800f3703acSApple OSS Distributions 3810f3703acSApple OSS Distributions #if IOTRACKING 382a5e72196SApple OSS Distributions void 383a5e72196SApple OSS Distributions OSObject::trackingAccumSize(size_t size) 3840f3703acSApple OSS Distributions { 385a5e72196SApple OSS Distributions if (kIOTracking & gIOKitDebug) { 386a5e72196SApple OSS Distributions getMetaClass()->trackedAccumSize(this, size); 387a5e72196SApple OSS Distributions } 3880f3703acSApple OSS Distributions } 3890f3703acSApple OSS Distributions #endif 3900f3703acSApple OSS Distributions 3910f3703acSApple OSS Distributions /* Class member functions - Can't use defaults */ 3920f3703acSApple OSS Distributions /* During constructor vtable is always OSObject's - can't call any subclass */ 3930f3703acSApple OSS Distributions 3940f3703acSApple OSS Distributions OSObject::OSObject() 3950f3703acSApple OSS Distributions { 3960f3703acSApple OSS Distributions retainCount = 1; 3970f3703acSApple OSS Distributions // if (kIOTracking & gIOKitDebug) getMetaClass()->trackedInstance(this); 3980f3703acSApple OSS Distributions } 3990f3703acSApple OSS Distributions 4000f3703acSApple OSS Distributions OSObject::OSObject(const OSMetaClass *) 4010f3703acSApple OSS Distributions { 4020f3703acSApple OSS Distributions retainCount = 1; 4030f3703acSApple OSS Distributions // if (kIOTracking & gIOKitDebug) getMetaClass()->trackedInstance(this); 404c1dac77fSApple OSS Distributions } 405a5e72196SApple OSS Distributions 406a5e72196SApple OSS Distributions 407a5e72196SApple OSS Distributions bool 408a5e72196SApple OSS Distributions OSObject::iterateObjects(void * refcon, bool (*callback)(void * refcon, OSObject * object)) 409a5e72196SApple OSS Distributions { 410a5e72196SApple OSS Distributions OSCollection * col; 411a5e72196SApple OSS Distributions if ((col = OSDynamicCast(OSCollection, this))) { 412a5e72196SApple OSS Distributions return col->iterateObjects(refcon, callback); 413a5e72196SApple OSS Distributions } 414a5e72196SApple OSS Distributions return callback(refcon, this); 415a5e72196SApple OSS Distributions } 416a5e72196SApple OSS Distributions 417a5e72196SApple OSS Distributions bool 418a5e72196SApple OSS Distributions OSObject::iterateObjects(bool (^block)(OSObject * object)) 419a5e72196SApple OSS Distributions { 420a5e72196SApple OSS Distributions OSCollection * col; 421a5e72196SApple OSS Distributions if ((col = OSDynamicCast(OSCollection, this))) { 422a5e72196SApple OSS Distributions return col->iterateObjects(block); 423a5e72196SApple OSS Distributions } 424a5e72196SApple OSS Distributions return block(this); 425a5e72196SApple OSS Distributions } 426