]> git.saurik.com Git - apple/xnu.git/blobdiff - libkern/c++/OSMetaClass.cpp
xnu-517.tar.gz
[apple/xnu.git] / libkern / c++ / OSMetaClass.cpp
index c3019b599bc00a099ede5dc3d0b29daad2be085b..4184b82b0a927a33b287d4bfa38f3b0c6b3e8ac9 100644 (file)
@@ -554,6 +554,8 @@ void OSMetaClass::reportModInstances(const char *kmodName)
     iter->release();
 }
 
+extern "C" kern_return_t kmod_unload_cache(void);
+
 static void _OSMetaClassConsiderUnloads(thread_call_param_t p0,
                                         thread_call_param_t p1)
 {
@@ -578,7 +580,7 @@ static void _OSMetaClassConsiderUnloads(thread_call_param_t p0,
         while ( (kmodName = (OSSymbol *) kmods->getNextObject()) ) {
 
             if (ki) {
-                kfree(ki, sizeof(kmod_info_t));
+                kfree((vm_offset_t) ki, sizeof(kmod_info_t));
                 ki = 0;
             }
 
@@ -614,6 +616,8 @@ static void _OSMetaClassConsiderUnloads(thread_call_param_t p0,
     } while (didUnload);
 
     mutex_unlock(loadLock);
+
+    kmod_unload_cache();
 }
 
 void OSMetaClass::considerUnloads()
@@ -801,31 +805,50 @@ void OSMetaClass::printInstanceCounts()
 
 OSDictionary * OSMetaClass::getClassDictionary()
 {
-    return sAllClassesDict;
+    panic("OSMetaClass::getClassDictionary(): Obsoleted\n");
+    return 0;
 }
 
 bool OSMetaClass::serialize(OSSerialize *s) const
 {
-    OSDictionary *     dict;
-    OSNumber *         off;
-    bool               ok = false;
+    panic("OSMetaClass::serialize(): Obsoleted\n");
+    return false;
+}
+
+void OSMetaClass::serializeClassDictionary(OSDictionary *serializeDictionary)
+{
+    OSDictionary *classDict;
+
+    classDict = OSDictionary::withCapacity(sAllClassesDict->getCount());
+    if (!classDict)
+        return;
 
-    if (s->previouslySerialized(this)) return true;
+    mutex_lock(loadLock);
+    do {
+        OSCollectionIterator *classes;
+        const OSSymbol *className;
 
-    dict = 0;// IODictionary::withCapacity(2);
-    off = OSNumber::withNumber(getInstanceCount(), 32);
+        classes = OSCollectionIterator::withCollection(sAllClassesDict);
+        if (!classes)
+            break;
+    
+        while ((className = (const OSSymbol *) classes->getNextObject())) {
+            const OSMetaClass *meta;
+            OSNumber *count;
+
+            meta = (OSMetaClass *) sAllClassesDict->getObject(className);
+            count = OSNumber::withNumber(meta->getInstanceCount(), 32);
+            if (count) {
+                classDict->setObject(className, count);
+                count->release();
+            }
+        }
+        classes->release();
 
-    if (dict) {
-       dict->setObject("InstanceCount", off );
-       ok = dict->serialize(s);
-    } else if( off)
-       ok = off->serialize(s);
+        serializeDictionary->setObject("Classes", classDict);
+    } while (0);
 
-    if (dict)
-       dict->release();
-    if (off)
-       off->release();
+    mutex_unlock(loadLock);
 
-    return ok;
+    classDict->release();
 }
-