Loading...
--- xnu/xnu-2050.22.13/libkern/c++/OSMetaClass.cpp
+++ xnu/xnu-1504.3.12/libkern/c++/OSMetaClass.cpp
@@ -46,6 +46,8 @@
#include <libkern/c++/OSLib.h>
#include <libkern/OSAtomic.h>
+#include <IOKit/pwr_mgt/RootDomain.h>
+#include <IOKit/IOMessage.h>
#include <IOKit/IOLib.h>
__BEGIN_DECLS
@@ -93,9 +95,7 @@
static const int kClassCapacityIncrement = 40;
static const int kKModCapacityIncrement = 10;
static OSDictionary * sAllClassesDict;
-static unsigned int sDeepestClass;
IOLock * sAllClassesLock = NULL;
-IOLock * sInstancesLock = NULL;
/*
* While loading a kext and running all its constructors to register
@@ -111,13 +111,6 @@
} * sStalled;
IOLock * sStalledClassesLock = NULL;
-
-struct ExpansionData {
- OSOrderedSet * instances;
- OSKext * kext;
-};
-
-
#if PRAGMA_MARK
#pragma mark OSMetaClassBase
#endif /* PRAGMA_MARK */
@@ -125,7 +118,6 @@
* OSMetaClassBase.
*********************************************************************/
-#if APPLE_KEXT_VTABLE_PADDING
/*********************************************************************
* Reserved vtable functions.
*********************************************************************/
@@ -147,8 +139,7 @@
{ panic("OSMetaClassBase::_RESERVEDOSMetaClassBase%d called.", 5); }
void OSMetaClassBase::_RESERVEDOSMetaClassBase6()
{ panic("OSMetaClassBase::_RESERVEDOSMetaClassBase%d called.", 6); }
-#endif
-
+
/*********************************************************************
* These used to be inline in the header but gcc didn't believe us
* Now we MUST pull the inline out at least until the compiler is
@@ -185,10 +176,8 @@
{
sAllClassesLock = IOLockAlloc();
sStalledClassesLock = IOLockAlloc();
- sInstancesLock = IOLockAlloc();
-}
-
-#if APPLE_KEXT_VTABLE_PADDING
+}
+
/*********************************************************************
* If you need this slot you had better setup an IOCTL style interface.
* 'Cause the whole kernel world depends on OSMetaClassBase and YOU
@@ -197,7 +186,6 @@
void
OSMetaClassBase::_RESERVEDOSMetaClassBase7()
{ panic("OSMetaClassBase::_RESERVEDOSMetaClassBase%d called.", 7); }
-#endif
/*********************************************************************
*********************************************************************/
@@ -297,7 +285,6 @@
* OSMetaClass
*********************************************************************/
-#if APPLE_KEXT_VTABLE_PADDING
/*********************************************************************
* Reserved functions.
*********************************************************************/
@@ -317,7 +304,6 @@
{ panic("OSMetaClass::_RESERVEDOSMetaClass%d called", 6); }
void OSMetaClass::_RESERVEDOSMetaClass7()
{ panic("OSMetaClass::_RESERVEDOSMetaClass%d called", 7); }
-#endif
/*********************************************************************
*********************************************************************/
@@ -391,9 +377,6 @@
classSize = inClassSize;
superClassLink = inSuperClass;
- reserved = IONew(ExpansionData, 1);
- bzero(reserved, sizeof(ExpansionData));
-
/* Hack alert: We are just casting inClassName and storing it in
* an OSString * instance variable. This may be because you can't
* create C++ objects in static constructors, but I really don't know!
@@ -437,7 +420,7 @@
*********************************************************************/
OSMetaClass::~OSMetaClass()
{
- OSKext * myKext = reserved ? reserved->kext : 0; // do not release
+ OSKext * myKext = (OSKext *)reserved; // do not release
/* Hack alert: 'className' is a C string during early C++ init, and
* is converted to a real OSSymbol only when we record the OSKext in
@@ -508,16 +491,9 @@
const char *
OSMetaClass::getClassName() const
{
- if (!className) return NULL;
return className->getCStringNoCopy();
}
-/*********************************************************************
-*********************************************************************/
-const OSSymbol *
-OSMetaClass::getClassNameSymbol() const
-{
- return className;
-}
+
/*********************************************************************
*********************************************************************/
unsigned int
@@ -594,7 +570,6 @@
result = kOSMetaClassNoDicts;
break;
}
- sAllClassesDict->setOptions(OSCollection::kSort, OSCollection::kSort);
// No break; fall through
@@ -629,7 +604,7 @@
*/
IOLockLock(sAllClassesLock);
for (i = 0; i < sStalled->count; i++) {
- const OSMetaClass * me = sStalled->classes[i];
+ OSMetaClass * me = sStalled->classes[i];
OSMetaClass * orig = OSDynamicCast(OSMetaClass,
sAllClassesDict->getObject((const char *)me->className));
@@ -642,13 +617,10 @@
"OSMetaClass: Kext %s class %s is a duplicate;"
"kext %s already has a class by that name.",
sStalled->kextIdentifier, (const char *)me->className,
- ((OSKext *)orig->reserved->kext)->getIdentifierCString());
+ ((OSKext *)orig->reserved)->getIdentifierCString());
result = kOSMetaClassDuplicateClass;
break;
}
- unsigned int depth = 1;
- while ((me = me->superClassLink)) depth++;
- if (depth > sDeepestClass) sDeepestClass = depth;
}
IOLockUnlock(sAllClassesLock);
@@ -676,7 +648,7 @@
/* Do not retain the kext object here.
*/
- me->reserved->kext = myKext;
+ me->reserved = (ExpansionData *)myKext;
if (myKext) {
result = myKext->addClass(me, sStalled->count);
if (result != kOSReturnSuccess) {
@@ -745,7 +717,7 @@
}
if (((int)instanceCount) < 0) {
- OSKext * myKext = reserved->kext;
+ OSKext * myKext = (OSKext *)reserved;
OSKextLog(myKext, kOSMetaClassLogSpec,
// xxx - this phrasing is rather cryptic
@@ -782,138 +754,6 @@
OSKext::reportOSMetaClassInstances(kextIdentifier,
kOSKextLogExplicitLevel);
return;
-}
-/*********************************************************************
-*********************************************************************/
-
-void
-OSMetaClass::addInstance(const OSObject * instance, bool super) const
-{
- if (!super) IOLockLock(sInstancesLock);
-
- if (!reserved->instances) {
- reserved->instances = OSOrderedSet::withCapacity(16);
- if (superClassLink) {
- superClassLink->addInstance(reserved->instances, true);
- }
- }
- reserved->instances->setLastObject(instance);
-
- if (!super) IOLockUnlock(sInstancesLock);
-}
-
-void
-OSMetaClass::removeInstance(const OSObject * instance, bool super) const
-{
- if (!super) IOLockLock(sInstancesLock);
-
- if (reserved->instances) {
- reserved->instances->removeObject(instance);
- if (0 == reserved->instances->getCount()) {
- if (superClassLink) {
- superClassLink->removeInstance(reserved->instances, true);
- }
- reserved->instances->release();
- reserved->instances = 0;
- }
- }
-
- if (!super) IOLockUnlock(sInstancesLock);
-}
-
-void
-OSMetaClass::applyToInstances(OSOrderedSet * set,
- OSMetaClassInstanceApplierFunction applier,
- void * context)
-{
- enum { kLocalDepth = 24 };
- unsigned int _nextIndex[kLocalDepth];
- OSOrderedSet * _sets[kLocalDepth];
- unsigned int * nextIndex = &_nextIndex[0];
- OSOrderedSet ** sets = &_sets[0];
- OSObject * obj;
- OSOrderedSet * childSet;
- unsigned int maxDepth;
- unsigned int idx;
- unsigned int level;
- bool done;
-
- maxDepth = sDeepestClass;
- if (maxDepth > kLocalDepth)
- {
- nextIndex = IONew(typeof(nextIndex[0]), maxDepth);
- sets = IONew(typeof(sets[0]), maxDepth);
- }
- done = false;
- level = 0;
- idx = 0;
- do
- {
- while (!done && (obj = set->getObject(idx++)))
- {
- if ((childSet = OSDynamicCast(OSOrderedSet, obj)))
- {
- if (level >= maxDepth) panic(">maxDepth");
- sets[level] = set;
- nextIndex[level] = idx;
- level++;
- set = childSet;
- idx = 0;
- break;
- }
- done = (*applier)(obj, context);
- }
- if (!obj)
- {
- if (!done && level)
- {
- level--;
- set = sets[level];
- idx = nextIndex[level];
- } else done = true;
- }
- }
- while (!done);
- if (maxDepth > kLocalDepth)
- {
- IODelete(nextIndex, typeof(nextIndex[0]), maxDepth);
- IODelete(sets, typeof(sets[0]), maxDepth);
- }
-}
-
-void
-OSMetaClass::applyToInstances(OSMetaClassInstanceApplierFunction applier,
- void * context) const
-{
- IOLockLock(sInstancesLock);
- if (reserved->instances) applyToInstances(reserved->instances, applier, context);
- IOLockUnlock(sInstancesLock);
-}
-
-void
-OSMetaClass::applyToInstancesOfClassName(
- const OSSymbol * name,
- OSMetaClassInstanceApplierFunction applier,
- void * context)
-{
- OSMetaClass * meta;
- OSOrderedSet * set = 0;
-
- IOLockLock(sAllClassesLock);
- if (sAllClassesDict
- && (meta = (OSMetaClass *) sAllClassesDict->getObject(name))
- && (set = meta->reserved->instances))
- {
- set->retain();
- }
- IOLockUnlock(sAllClassesLock);
-
- if (!set) return;
-
- IOLockLock(sInstancesLock);
- applyToInstances(set, applier, context);
- IOLockUnlock(sInstancesLock);
- set->release();
}
/*********************************************************************
@@ -1081,7 +921,7 @@
const OSSymbol *
OSMetaClass::getKmodName() const
{
- OSKext * myKext = reserved ? reserved->kext : 0;
+ OSKext * myKext = (OSKext *)reserved;
if (myKext) {
return myKext->getIdentifier();
}