]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IORegistryEntry.cpp
xnu-344.tar.gz
[apple/xnu.git] / iokit / Kernel / IORegistryEntry.cpp
index e309047d4c67e4223ac06641b082b09883c396e8..5d1e530f1a7cb99e607c3b16a44d1e1d7cfce74a 100644 (file)
@@ -61,7 +61,7 @@ enum {
 
 class IORegistryPlane : public OSObject {
 
-    friend IORegistryEntry;
+    friend class IORegistryEntry;
 
     OSDeclareAbstractStructors(IORegistryPlane)
 
@@ -165,8 +165,9 @@ s_lock_write(
                if (l->can_sleep && l->want_write) {
                        l->waiting = TRUE;
                        thread_sleep_simple_lock((event_t) l,
-                                       simple_lock_addr(l->interlock), FALSE);
-                       simple_lock(&l->interlock);
+                                       simple_lock_addr(l->interlock),
+                                       THREAD_UNINT);
+                       /* interlock relocked */
                }
        }
        l->want_write = TRUE;
@@ -187,8 +188,9 @@ s_lock_write(
                if (l->can_sleep && (l->read_count != 0 || l->want_upgrade)) {
                        l->waiting = TRUE;
                        thread_sleep_simple_lock((event_t) l,
-                               simple_lock_addr(l->interlock), FALSE);
-                       simple_lock(&l->interlock);
+                               simple_lock_addr(l->interlock),
+                               THREAD_UNINT);
+                       /* interlock relocked */
                }
        }
 
@@ -257,8 +259,9 @@ s_lock_read(
                     (l->want_upgrade || ((0 == l->read_count) && l->want_write ))) {
                        l->waiting = TRUE;
                        thread_sleep_simple_lock((event_t) l,
-                                       simple_lock_addr(l->interlock), FALSE);
-                       simple_lock(&l->interlock);
+                                       simple_lock_addr(l->interlock),
+                                       THREAD_UNINT);
+                       /* interlock relocked */
                }
        }
 
@@ -399,9 +402,11 @@ bool IORegistryEntry::init( OSDictionary * dict = 0 )
 
     if( dict) {
        dict->retain();
+       if( fPropertyTable)
+           fPropertyTable->release();
        fPropertyTable = dict;
 
-    } else {
+    } else if( !fPropertyTable) {
         fPropertyTable = OSDictionary::withCapacity( kIORegCapacityIncrement );
        if( fPropertyTable)
             fPropertyTable->setCapacityIncrement( kIORegCapacityIncrement );
@@ -411,9 +416,11 @@ bool IORegistryEntry::init( OSDictionary * dict = 0 )
         return( false);
 
 #ifdef IOREGSPLITTABLES
-    fRegistryTable = OSDictionary::withCapacity( kIORegCapacityIncrement );
-    if( fRegistryTable)
-        fRegistryTable->setCapacityIncrement( kIORegCapacityIncrement );
+    if( !fRegistryTable) {
+       fRegistryTable = OSDictionary::withCapacity( kIORegCapacityIncrement );
+       if( fRegistryTable)
+           fRegistryTable->setCapacityIncrement( kIORegCapacityIncrement );
+    }
 
     if( (prop = OSDynamicCast( OSString, getProperty( gIONameKey)))) {
         OSSymbol * sym = (OSSymbol *)OSSymbol::withString( prop);
@@ -440,12 +447,15 @@ bool IORegistryEntry::init( IORegistryEntry * old,
     WLOCK;
 
     fPropertyTable = old->getPropertyTable();
-    old->fPropertyTable = 0;
+    fPropertyTable->retain();
 #ifdef IOREGSPLITTABLES
     fRegistryTable = old->fRegistryTable;
-    old->fRegistryTable = 0;
+    old->fRegistryTable = OSDictionary::withDictionary( fRegistryTable );
 #endif /* IOREGSPLITTABLES */
 
+    old->registryTable()->removeObject( plane->keys[ kParentSetIndex ] );
+    old->registryTable()->removeObject( plane->keys[ kChildSetIndex ] );
+
     all = getParentSetReference( plane );
     if( all) for( index = 0;
               (next = (IORegistryEntry *) all->getObject(index));
@@ -510,7 +520,7 @@ void IORegistryEntry::setPropertyTable( OSDictionary * dict )
 
 /* Wrappers to synchronize property table */
 
-#define wrap1(func,type,constant)                                      \
+#define wrap1(func, type, constant)                                    \
 OSObject *                                                             \
 IORegistryEntry::func ## Property( type * aKey) constant               \
 {                                                                      \
@@ -523,14 +533,14 @@ IORegistryEntry::func ## Property( type * aKey) constant          \
     return( obj );                                                     \
 }
 
-#define wrap2(type,constant)                                           \
+#define wrap2(type, constant)                                          \
 OSObject *                                                             \
 IORegistryEntry::copyProperty( type * aKey) constant                   \
 {                                                                      \
     OSObject * obj;                                                    \
                                                                        \
     PLOCK;                                                             \
-    obj = getPropertyTable()->getObject( aKey );                       \
+    obj = getProperty( aKey );                                         \
     if( obj)                                                           \
         obj->retain();                                                 \
     PUNLOCK;                                                           \
@@ -1231,6 +1241,7 @@ IORegistryEntry * IORegistryEntry::fromPath(
                         IORegistryEntry *      fromEntry = 0 )
 {
     IORegistryEntry *  where = 0;
+    IORegistryEntry *  aliasEntry = 0;
     IORegistryEntry *  next;
     const char *       alias;
     const char *       end;
@@ -1260,8 +1271,9 @@ IORegistryEntry * IORegistryEntry::fromPath(
     if( (alias = dealiasPath( &end, plane))) {
         if( length)
             len = *length;
-        where = IORegistryEntry::fromPath( alias, plane,
+        aliasEntry = IORegistryEntry::fromPath( alias, plane,
                                     opath, &len, fromEntry );
+        where = aliasEntry;
         if( where)
             path = end;
         else
@@ -1309,6 +1321,8 @@ IORegistryEntry * IORegistryEntry::fromPath(
 
     if( where)
        where->retain();
+    if( aliasEntry)
+        aliasEntry->release();
 
     UNLOCK;
 
@@ -1815,6 +1829,8 @@ unsigned int IORegistryEntry::getDepth( const IORegistryPlane * plane ) const
 
 OSDefineMetaClassAndStructors(IORegistryIterator, OSIterator)
 
+enum { kIORegistryIteratorInvalidFlag = 0x80000000 };
+
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 IORegistryIterator *
@@ -1838,7 +1854,7 @@ IORegistryIterator::iterateOver( IORegistryEntry * root,
             create->where = &create->start;
             create->start.current = root;
             create->plane = plane;
-            create->options = options;
+            create->options = options & ~kIORegistryIteratorInvalidFlag;
 
        } else {
            create->release();
@@ -1860,10 +1876,12 @@ bool IORegistryIterator::isValid( void )
     bool               ok;
     IORegCursor *      next;
 
-    ok = true;
     next = where;
 
     RLOCK;
+
+    ok = (0 == (kIORegistryIteratorInvalidFlag & options));
+
     while( ok && next) {
        if( where->iter)
             ok = where->iter->isValid();
@@ -1927,6 +1945,7 @@ void IORegistryIterator::reset( void )
     }
 
     where->current = root;
+    options &= ~kIORegistryIteratorInvalidFlag;
 }
 
 void IORegistryIterator::free( void )
@@ -1962,11 +1981,15 @@ IORegistryEntry * IORegistryIterator::getNextObjectFlat( void )
         if( where->current)
             where->current->release();
 
-    if( where->iter)
+    if( where->iter) {
+
         next = (IORegistryEntry *) where->iter->getNextObject();
 
-    if( next)
-       next->retain();
+        if( next)
+            next->retain();
+        else if( !where->iter->isValid())
+            options |= kIORegistryIteratorInvalidFlag;
+    }
 
     where->current = next;
 
@@ -2053,3 +2076,7 @@ OSMetaClassDefineReservedUnused(IORegistryEntry, 28);
 OSMetaClassDefineReservedUnused(IORegistryEntry, 29);
 OSMetaClassDefineReservedUnused(IORegistryEntry, 30);
 OSMetaClassDefineReservedUnused(IORegistryEntry, 31);
+
+/* inline function implementation */
+OSDictionary * IORegistryEntry::getPropertyTable( void ) const
+{ return(fPropertyTable); }