2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* OSMetaClass.cpp created by gvdl on Fri 1998-11-17 */
34 #include <libkern/OSReturn.h>
36 #include <libkern/c++/OSMetaClass.h>
38 #include <libkern/c++/OSObject.h>
39 #include <libkern/c++/OSCollectionIterator.h>
40 #include <libkern/c++/OSDictionary.h>
41 #include <libkern/c++/OSArray.h>
42 #include <libkern/c++/OSSet.h>
43 #include <libkern/c++/OSSymbol.h>
44 #include <libkern/c++/OSNumber.h>
45 #include <libkern/c++/OSSerialize.h>
46 #include <libkern/c++/OSLib.h>
47 #include <libkern/OSAtomic.h>
49 #include <IOKit/pwr_mgt/RootDomain.h>
50 #include <IOKit/IOMessage.h>
54 #include <sys/systm.h>
55 #include <mach/mach_types.h>
56 #include <kern/lock.h>
57 #include <kern/clock.h>
58 #include <kern/thread_call.h>
59 #include <kern/host.h>
60 #include <mach/kmod.h>
61 #include <mach/mach_interface.h>
63 extern void OSRuntimeUnloadCPP(kmod_info_t
*ki
, void *);
66 extern int debug_container_malloc_size
;
67 #define ACCUMSIZE(s) do { debug_container_malloc_size += (s); } while(0)
70 #endif /* OSALLOCDEBUG */
75 kCompletedBootstrap
= 0,
77 kMakingDictionaries
= 2
78 } sBootstrapState
= kNoDictionaries
;
80 static const int kClassCapacityIncrement
= 40;
81 static const int kKModCapacityIncrement
= 10;
82 static OSDictionary
*sAllClassesDict
, *sKModClassesDict
, *sSortedByClassesDict
;
84 static mutex_t
*loadLock
= 0;
85 static struct StalledData
{
88 unsigned int capacity
;
90 OSMetaClass
**classes
;
93 static unsigned int sConsiderUnloadDelay
= 60; /* secs */
94 static bool unloadsEnabled
= true; // set to false when system going to sleep
95 static thread_call_t unloadCallout
= 0;
97 static const char OSMetaClassBasePanicMsg
[] =
98 "OSMetaClassBase::_RESERVEDOSMetaClassBase%d called\n";
101 void OSMetaClassBase::_RESERVEDOSMetaClassBase0()
102 { panic(OSMetaClassBasePanicMsg
, 0); }
103 void OSMetaClassBase::_RESERVEDOSMetaClassBase1()
104 { panic(OSMetaClassBasePanicMsg
, 1); }
105 void OSMetaClassBase::_RESERVEDOSMetaClassBase2()
106 { panic(OSMetaClassBasePanicMsg
, 2); }
107 #endif /* SLOT_USED */
109 // As these slots are used move them up inside the #if above
110 void OSMetaClassBase::_RESERVEDOSMetaClassBase3()
111 { panic(OSMetaClassBasePanicMsg
, 3); }
112 void OSMetaClassBase::_RESERVEDOSMetaClassBase4()
113 { panic(OSMetaClassBasePanicMsg
, 4); }
114 void OSMetaClassBase::_RESERVEDOSMetaClassBase5()
115 { panic(OSMetaClassBasePanicMsg
, 5); }
116 void OSMetaClassBase::_RESERVEDOSMetaClassBase6()
117 { panic(OSMetaClassBasePanicMsg
, 6); }
120 * These used to be inline in the header but gcc didn't believe us
121 * Now we MUST pull the inline out at least until the compiler is
124 // Helper inlines for runtime type preprocessor macros
125 OSMetaClassBase
*OSMetaClassBase::
126 safeMetaCast(const OSMetaClassBase
*me
, const OSMetaClass
*toType
)
127 { return (me
)? me
->metaCast(toType
) : 0; }
129 bool OSMetaClassBase::
130 checkTypeInst(const OSMetaClassBase
*inst
, const OSMetaClassBase
*typeinst
)
132 const OSMetaClass
*toType
= OSTypeIDInst(typeinst
);
133 return typeinst
&& inst
&& (0 != inst
->metaCast(toType
));
137 // If you need this slot you had better setup an IOCTL style interface.
138 // 'Cause the whole kernel world depends on OSMetaClassBase and YOU
139 // CANT change the VTABLE size ever.
140 void OSMetaClassBase::_RESERVEDOSMetaClassBase7()
141 { panic(OSMetaClassBasePanicMsg
, 7); }
143 OSMetaClassBase::OSMetaClassBase()
147 OSMetaClassBase::~OSMetaClassBase()
151 thisVTable
= (void **) this;
152 *thisVTable
= (void *) -1UL;
155 bool OSMetaClassBase::isEqualTo(const OSMetaClassBase
*anObj
) const
157 return this == anObj
;
160 OSMetaClassBase
*OSMetaClassBase::metaCast(const OSMetaClass
*toMeta
) const
162 return toMeta
->checkMetaCast(this);
165 OSMetaClassBase
*OSMetaClassBase::metaCast(const OSSymbol
*toMetaSymb
) const
167 return OSMetaClass::checkMetaCastWithName(toMetaSymb
, this);
170 OSMetaClassBase
*OSMetaClassBase::metaCast(const OSString
*toMetaStr
) const
172 const OSSymbol
*tempSymb
= OSSymbol::withString(toMetaStr
);
173 OSMetaClassBase
*ret
= 0;
175 ret
= metaCast(tempSymb
);
181 OSMetaClassBase
*OSMetaClassBase::metaCast(const char *toMetaCStr
) const
183 const OSSymbol
*tempSymb
= OSSymbol::withCString(toMetaCStr
);
184 OSMetaClassBase
*ret
= 0;
186 ret
= metaCast(tempSymb
);
192 class OSMetaClassMeta
: public OSMetaClass
196 OSObject
*alloc() const;
198 OSMetaClassMeta::OSMetaClassMeta()
199 : OSMetaClass("OSMetaClass", 0, sizeof(OSMetaClass
))
201 OSObject
*OSMetaClassMeta::alloc() const { return 0; }
203 static OSMetaClassMeta sOSMetaClassMeta
;
205 const OSMetaClass
* const OSMetaClass::metaClass
= &sOSMetaClassMeta
;
206 const OSMetaClass
* OSMetaClass::getMetaClass() const
207 { return &sOSMetaClassMeta
; }
209 static const char OSMetaClassPanicMsg
[] =
210 "OSMetaClass::_RESERVEDOSMetaClass%d called\n";
212 void OSMetaClass::_RESERVEDOSMetaClass0()
213 { panic(OSMetaClassPanicMsg
, 0); }
214 void OSMetaClass::_RESERVEDOSMetaClass1()
215 { panic(OSMetaClassPanicMsg
, 1); }
216 void OSMetaClass::_RESERVEDOSMetaClass2()
217 { panic(OSMetaClassPanicMsg
, 2); }
218 void OSMetaClass::_RESERVEDOSMetaClass3()
219 { panic(OSMetaClassPanicMsg
, 3); }
220 void OSMetaClass::_RESERVEDOSMetaClass4()
221 { panic(OSMetaClassPanicMsg
, 4); }
222 void OSMetaClass::_RESERVEDOSMetaClass5()
223 { panic(OSMetaClassPanicMsg
, 5); }
224 void OSMetaClass::_RESERVEDOSMetaClass6()
225 { panic(OSMetaClassPanicMsg
, 6); }
226 void OSMetaClass::_RESERVEDOSMetaClass7()
227 { panic(OSMetaClassPanicMsg
, 7); }
229 void OSMetaClass::logError(OSReturn result
)
234 case kOSMetaClassNoInit
:
235 msg
="OSMetaClass::preModLoad wasn't called, runtime internal error";
237 case kOSMetaClassNoDicts
:
238 msg
="Allocation failure for Metaclass internal dictionaries"; break;
239 case kOSMetaClassNoKModSet
:
240 msg
="Allocation failure for internal kmodule set"; break;
241 case kOSMetaClassNoInsKModSet
:
242 msg
="Can't insert the KMod set into the module dictionary"; break;
243 case kOSMetaClassDuplicateClass
:
244 msg
="Duplicate class"; break;
245 case kOSMetaClassNoSuper
:
246 msg
="Can't associate a class with its super class"; break;
247 case kOSMetaClassInstNoSuper
:
248 msg
="Instance construction, unknown super class."; break;
250 case kOSMetaClassInternal
:
251 msg
="runtime internal error"; break;
252 case kOSReturnSuccess
:
258 OSMetaClass::OSMetaClass(const char *inClassName
,
259 const OSMetaClass
*inSuperClass
,
260 unsigned int inClassSize
)
263 classSize
= inClassSize
;
264 superClassLink
= inSuperClass
;
266 className
= (const OSSymbol
*) inClassName
;
269 printf("OSMetaClass::preModLoad wasn't called for %s, "
270 "runtime internal error\n", inClassName
);
271 } else if (!sStalled
->result
) {
272 // Grow stalled array if neccessary
273 if (sStalled
->count
>= sStalled
->capacity
) {
274 OSMetaClass
**oldStalled
= sStalled
->classes
;
275 int oldSize
= sStalled
->capacity
* sizeof(OSMetaClass
*);
276 int newSize
= oldSize
277 + kKModCapacityIncrement
* sizeof(OSMetaClass
*);
279 sStalled
->classes
= (OSMetaClass
**) kalloc(newSize
);
280 if (!sStalled
->classes
) {
281 sStalled
->classes
= oldStalled
;
282 sStalled
->result
= kOSMetaClassNoTempData
;
286 sStalled
->capacity
+= kKModCapacityIncrement
;
287 memmove(sStalled
->classes
, oldStalled
, oldSize
);
288 kfree(oldStalled
, oldSize
);
289 ACCUMSIZE(newSize
- oldSize
);
292 sStalled
->classes
[sStalled
->count
++] = this;
296 OSMetaClass::~OSMetaClass()
299 OSCollectionIterator
*iter
;
301 if (sAllClassesDict
) {
302 sAllClassesDict
->removeObject(className
);
303 className
->release();
306 iter
= OSCollectionIterator::withCollection(sKModClassesDict
);
311 while ( (iterKey
= (OSSymbol
*) iter
->getNextObject()) ) {
313 kmodClassSet
= (OSSet
*) sKModClassesDict
->getObject(iterKey
);
314 if (kmodClassSet
&& kmodClassSet
->containsObject(this)) {
315 kmodClassSet
->removeObject(this);
325 // First pass find class in stalled list
326 for (i
= 0; i
< sStalled
->count
; i
++)
327 if (this == sStalled
->classes
[i
])
330 if (i
< sStalled
->count
) {
332 if (i
< sStalled
->count
)
333 memmove(&sStalled
->classes
[i
], &sStalled
->classes
[i
+1],
334 (sStalled
->count
- i
) * sizeof(OSMetaClass
*));
339 void *OSMetaClass::operator new(size_t size
) { return 0; }
340 void OSMetaClass::retain() const { }
341 void OSMetaClass::release() const { }
342 void OSMetaClass::release(int when
) const { }
343 void OSMetaClass::taggedRetain(const void *tag
) const { }
344 void OSMetaClass::taggedRelease(const void *tag
) const { }
345 void OSMetaClass::taggedRelease(const void *tag
, const int when
) const { }
346 int OSMetaClass::getRetainCount() const { return 0; }
348 const char *OSMetaClass::getClassName() const
350 return className
->getCStringNoCopy();
353 unsigned int OSMetaClass::getClassSize() const
358 void *OSMetaClass::preModLoad(const char *kmodName
)
361 loadLock
= mutex_alloc(0);
362 mutex_lock(loadLock
);
365 mutex_lock(loadLock
);
367 sStalled
= (StalledData
*) kalloc(sizeof(*sStalled
));
369 sStalled
->classes
= (OSMetaClass
**)
370 kalloc(kKModCapacityIncrement
* sizeof(OSMetaClass
*));
371 if (!sStalled
->classes
) {
372 kfree(sStalled
, sizeof(*sStalled
));
375 ACCUMSIZE((kKModCapacityIncrement
* sizeof(OSMetaClass
*)) + sizeof(*sStalled
));
377 sStalled
->result
= kOSReturnSuccess
;
378 sStalled
->capacity
= kKModCapacityIncrement
;
380 sStalled
->kmodName
= kmodName
;
381 bzero(sStalled
->classes
, kKModCapacityIncrement
* sizeof(OSMetaClass
*));
387 bool OSMetaClass::checkModLoad(void *loadHandle
)
389 return sStalled
&& loadHandle
== sStalled
390 && sStalled
->result
== kOSReturnSuccess
;
393 OSReturn
OSMetaClass::postModLoad(void *loadHandle
)
395 OSReturn result
= kOSReturnSuccess
;
397 OSSymbol
*myname
= 0;
399 if (!sStalled
|| loadHandle
!= sStalled
) {
400 logError(kOSMetaClassInternal
);
401 return kOSMetaClassInternal
;
404 if (sStalled
->result
)
405 result
= sStalled
->result
;
406 else switch (sBootstrapState
) {
407 case kNoDictionaries
:
408 sBootstrapState
= kMakingDictionaries
;
409 // No break; fall through
411 case kMakingDictionaries
:
412 sKModClassesDict
= OSDictionary::withCapacity(kKModCapacityIncrement
);
413 sAllClassesDict
= OSDictionary::withCapacity(kClassCapacityIncrement
);
414 sSortedByClassesDict
= OSDictionary::withCapacity(kClassCapacityIncrement
);
415 if (!sAllClassesDict
|| !sKModClassesDict
|| !sSortedByClassesDict
) {
416 result
= kOSMetaClassNoDicts
;
419 // No break; fall through
421 case kCompletedBootstrap
:
424 myname
= (OSSymbol
*)OSSymbol::withCStringNoCopy(sStalled
->kmodName
);
426 if (!sStalled
->count
)
427 break; // Nothing to do so just get out
429 // First pass checking classes aren't already loaded
430 for (i
= 0; i
< sStalled
->count
; i
++) {
431 OSMetaClass
*me
= sStalled
->classes
[i
];
433 if (0 != sAllClassesDict
->getObject((const char *) me
->className
)) {
434 printf("Class \"%s\" is duplicate\n", (const char *) me
->className
);
435 result
= kOSMetaClassDuplicateClass
;
439 if (i
!= sStalled
->count
)
442 kmodSet
= OSSet::withCapacity(sStalled
->count
);
444 result
= kOSMetaClassNoKModSet
;
448 if (!sKModClassesDict
->setObject(myname
, kmodSet
)) {
449 result
= kOSMetaClassNoInsKModSet
;
453 // Second pass symbolling strings and inserting classes in dictionary
454 for (i
= 0; i
< sStalled
->count
; i
++) {
455 OSMetaClass
*me
= sStalled
->classes
[i
];
457 OSSymbol::withCStringNoCopy((const char *) me
->className
);
459 sAllClassesDict
->setObject(me
->className
, me
);
460 kmodSet
->setObject(me
);
461 sSortedByClassesDict
->setObject((const OSSymbol
*)me
, myname
);
463 sBootstrapState
= kCompletedBootstrap
;
468 result
= kOSMetaClassInternal
;
479 ACCUMSIZE(-(sStalled
->capacity
* sizeof(OSMetaClass
*)
480 + sizeof(*sStalled
)));
481 kfree(sStalled
->classes
,
482 sStalled
->capacity
* sizeof(OSMetaClass
*));
483 kfree(sStalled
, sizeof(*sStalled
));
488 mutex_unlock(loadLock
);
493 void OSMetaClass::instanceConstructed() const
495 // if ((0 == OSIncrementAtomic((SInt32 *)&(((OSMetaClass *) this)->instanceCount))) && superClassLink)
496 if ((0 == OSIncrementAtomic((SInt32
*) &instanceCount
)) && superClassLink
)
497 superClassLink
->instanceConstructed();
500 void OSMetaClass::instanceDestructed() const
502 if ((1 == OSDecrementAtomic((SInt32
*) &instanceCount
)) && superClassLink
)
503 superClassLink
->instanceDestructed();
505 if( ((int) instanceCount
) < 0)
506 printf("%s: bad retain(%d)", getClassName(), instanceCount
);
509 bool OSMetaClass::modHasInstance(const char *kmodName
)
514 loadLock
= mutex_alloc(0);
515 mutex_lock(loadLock
);
518 mutex_lock(loadLock
);
522 OSCollectionIterator
*iter
;
523 OSMetaClass
*checkClass
;
525 kmodClasses
= OSDynamicCast(OSSet
,
526 sKModClassesDict
->getObject(kmodName
));
530 iter
= OSCollectionIterator::withCollection(kmodClasses
);
534 while ( (checkClass
= (OSMetaClass
*) iter
->getNextObject()) )
535 if (checkClass
->getInstanceCount()) {
543 mutex_unlock(loadLock
);
548 void OSMetaClass::reportModInstances(const char *kmodName
)
551 OSCollectionIterator
*iter
;
552 OSMetaClass
*checkClass
;
554 kmodClasses
= OSDynamicCast(OSSet
,
555 sKModClassesDict
->getObject(kmodName
));
559 iter
= OSCollectionIterator::withCollection(kmodClasses
);
563 while ( (checkClass
= (OSMetaClass
*) iter
->getNextObject()) )
564 if (checkClass
->getInstanceCount()) {
565 printf("%s: %s has %d instance(s)\n",
567 checkClass
->getClassName(),
568 checkClass
->getInstanceCount());
577 IOReturn
OSMetaClassSystemSleepOrWake(UInt32 messageType
)
579 mutex_lock(loadLock
);
581 /* If the system is going to sleep, cancel the reaper thread timer
582 * and mark unloads disabled in case it just fired but hasn't
583 * taken the lock yet. If we are coming back from sleep, just
584 * set unloads enabled; IOService's normal operation will cause
585 * unloads to be considered soon enough.
587 if (messageType
== kIOMessageSystemWillSleep
) {
589 thread_call_cancel(unloadCallout
);
591 unloadsEnabled
= false;
592 } else if (messageType
== kIOMessageSystemHasPoweredOn
) {
593 unloadsEnabled
= true;
595 mutex_unlock(loadLock
);
597 return kIOReturnSuccess
;
602 extern "C" kern_return_t
kmod_unload_cache(void);
604 static void _OSMetaClassConsiderUnloads(thread_call_param_t p0
,
605 thread_call_param_t p1
)
609 OSCollectionIterator
*kmods
;
610 OSCollectionIterator
*classes
;
611 OSMetaClass
*checkClass
;
616 mutex_lock(loadLock
);
618 if (!unloadsEnabled
) {
619 mutex_unlock(loadLock
);
625 kmods
= OSCollectionIterator::withCollection(sKModClassesDict
);
630 while ( (kmodName
= (OSSymbol
*) kmods
->getNextObject()) ) {
633 kfree(ki
, sizeof(kmod_info_t
));
637 ki
= kmod_lookupbyname_locked((char *)kmodName
->getCStringNoCopy());
641 if (ki
->reference_count
) {
645 kmodClasses
= OSDynamicCast(OSSet
,
646 sKModClassesDict
->getObject(kmodName
));
647 classes
= OSCollectionIterator::withCollection(kmodClasses
);
651 while ((checkClass
= (OSMetaClass
*) classes
->getNextObject())
652 && (0 == checkClass
->getInstanceCount()))
656 if (0 == checkClass
) {
657 OSRuntimeUnloadCPP(ki
, 0); // call destructors
658 ret
= kmod_destroy(host_priv_self(), ki
->id
);
668 mutex_unlock(loadLock
);
673 void OSMetaClass::considerUnloads()
677 mutex_lock(loadLock
);
680 unloadCallout
= thread_call_allocate(&_OSMetaClassConsiderUnloads
, 0);
682 thread_call_cancel(unloadCallout
);
683 clock_interval_to_deadline(sConsiderUnloadDelay
, 1000 * 1000 * 1000, &when
);
684 thread_call_enter_delayed(unloadCallout
, when
);
686 mutex_unlock(loadLock
);
689 const OSMetaClass
*OSMetaClass::getMetaClassWithName(const OSSymbol
*name
)
691 OSMetaClass
*retMeta
= 0;
697 retMeta
= (OSMetaClass
*) sAllClassesDict
->getObject(name
);
699 if (!retMeta
&& sStalled
)
701 // Oh dear we have to scan the stalled list and walk the
702 // the stalled list manually.
703 const char *cName
= name
->getCStringNoCopy();
706 // find class in stalled list
707 for (i
= 0; i
< sStalled
->count
; i
++) {
708 retMeta
= sStalled
->classes
[i
];
709 if (0 == strcmp(cName
, (const char *) retMeta
->className
))
713 if (i
< sStalled
->count
)
720 OSObject
*OSMetaClass::allocClassWithName(const OSSymbol
*name
)
723 mutex_lock(loadLock
);
725 const OSMetaClass
* const meta
= getMetaClassWithName(name
);
728 result
= meta
->alloc();
732 mutex_unlock(loadLock
);
737 OSObject
*OSMetaClass::allocClassWithName(const OSString
*name
)
739 const OSSymbol
*tmpKey
= OSSymbol::withString(name
);
740 OSObject
*result
= allocClassWithName(tmpKey
);
745 OSObject
*OSMetaClass::allocClassWithName(const char *name
)
747 const OSSymbol
*tmpKey
= OSSymbol::withCStringNoCopy(name
);
748 OSObject
*result
= allocClassWithName(tmpKey
);
754 OSMetaClassBase
*OSMetaClass::
755 checkMetaCastWithName(const OSSymbol
*name
, const OSMetaClassBase
*in
)
757 OSMetaClassBase
* result
;
758 mutex_lock(loadLock
);
759 const OSMetaClass
* const meta
= getMetaClassWithName(name
);
762 result
= meta
->checkMetaCast(in
);
766 mutex_unlock(loadLock
);
770 OSMetaClassBase
*OSMetaClass::
771 checkMetaCastWithName(const OSString
*name
, const OSMetaClassBase
*in
)
773 const OSSymbol
*tmpKey
= OSSymbol::withString(name
);
774 OSMetaClassBase
*result
= checkMetaCastWithName(tmpKey
, in
);
779 OSMetaClassBase
*OSMetaClass::
780 checkMetaCastWithName(const char *name
, const OSMetaClassBase
*in
)
782 const OSSymbol
*tmpKey
= OSSymbol::withCStringNoCopy(name
);
783 OSMetaClassBase
*result
= checkMetaCastWithName(tmpKey
, in
);
789 OSMetaClass::checkMetaCast
790 checkMetaCast(const OSMetaClassBase *check)
792 Check to see if the 'check' object has this object in it's metaclass chain. Returns check if it is indeed a kind of the current meta class, 0 otherwise.
794 Generally this method is not invoked directly but is used to implement the OSMetaClassBase::metaCast member function.
796 See also OSMetaClassBase::metaCast
799 OSMetaClassBase
*OSMetaClass::checkMetaCast(const OSMetaClassBase
*check
) const
801 const OSMetaClass
* const toMeta
= this;
802 const OSMetaClass
*fromMeta
;
804 for (fromMeta
= check
->getMetaClass(); ; fromMeta
= fromMeta
->superClassLink
) {
805 if (toMeta
== fromMeta
)
806 return (OSMetaClassBase
*) check
; // Discard const
808 if (!fromMeta
->superClassLink
)
815 void OSMetaClass::reservedCalled(int ind
) const
817 const char *cname
= className
->getCStringNoCopy();
818 panic("%s::_RESERVED%s%d called\n", cname
, cname
, ind
);
821 const OSMetaClass
*OSMetaClass::getSuperClass() const
823 return superClassLink
;
826 const OSSymbol
*OSMetaClass::getKmodName() const
828 return (const OSSymbol
*)sSortedByClassesDict
->getObject((OSSymbol
*)this);
831 unsigned int OSMetaClass::getInstanceCount() const
833 return instanceCount
;
836 void OSMetaClass::printInstanceCounts()
838 OSCollectionIterator
*classes
;
842 classes
= OSCollectionIterator::withCollection(sAllClassesDict
);
846 while( (className
= (OSSymbol
*)classes
->getNextObject())) {
847 meta
= (OSMetaClass
*) sAllClassesDict
->getObject(className
);
850 printf("%24s count: %03d x 0x%03x = 0x%06x\n",
851 className
->getCStringNoCopy(),
852 meta
->getInstanceCount(),
853 meta
->getClassSize(),
854 meta
->getInstanceCount() * meta
->getClassSize() );
860 OSDictionary
* OSMetaClass::getClassDictionary()
862 panic("OSMetaClass::getClassDictionary(): Obsoleted\n");
866 bool OSMetaClass::serialize(OSSerialize
*s
) const
868 panic("OSMetaClass::serialize(): Obsoleted\n");
872 void OSMetaClass::serializeClassDictionary(OSDictionary
*serializeDictionary
)
874 OSDictionary
*classDict
;
876 classDict
= OSDictionary::withCapacity(sAllClassesDict
->getCount());
880 mutex_lock(loadLock
);
882 OSCollectionIterator
*classes
;
883 const OSSymbol
*className
;
885 classes
= OSCollectionIterator::withCollection(sAllClassesDict
);
889 while ((className
= (const OSSymbol
*) classes
->getNextObject())) {
890 const OSMetaClass
*meta
;
893 meta
= (OSMetaClass
*) sAllClassesDict
->getObject(className
);
894 count
= OSNumber::withNumber(meta
->getInstanceCount(), 32);
896 classDict
->setObject(className
, count
);
902 serializeDictionary
->setObject("Classes", classDict
);
905 mutex_unlock(loadLock
);
907 classDict
->release();