]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IODeviceTreeSupport.cpp
xnu-3248.40.184.tar.gz
[apple/xnu.git] / iokit / Kernel / IODeviceTreeSupport.cpp
index 5d61880867fbf17a9b6dd9f6195496e0a4fd6ec1..ce4a65ef70d3b678c918509141ba592a78775386 100644 (file)
@@ -37,6 +37,8 @@
 
 #include <pexpert/device_tree.h>
 
+typedef UInt32  dtptr_t;
+
 #include <machine/machine_routines.h>
 
 extern "C" {
@@ -61,6 +63,7 @@ const OSSymbol *      gIODTUnitKey;
 const OSSymbol *       gIODTCompatibleKey;
 const OSSymbol *       gIODTTypeKey;
 const OSSymbol *       gIODTModelKey;
+const OSSymbol *       gIODTTargetTypeKey;
 
 const OSSymbol *       gIODTSizeCellKey;
 const OSSymbol *       gIODTAddressCellKey;
@@ -106,6 +109,7 @@ IODeviceTreeAlloc( void * dtTop )
     gIODTCompatibleKey         = OSSymbol::withCStringNoCopy( "compatible" );
     gIODTTypeKey               = OSSymbol::withCStringNoCopy( "device_type" );
     gIODTModelKey              = OSSymbol::withCStringNoCopy( "model" );
+    gIODTTargetTypeKey         = OSSymbol::withCStringNoCopy( "target-type" );
     gIODTSizeCellKey   = OSSymbol::withCStringNoCopy( "#size-cells" );
     gIODTAddressCellKey = OSSymbol::withCStringNoCopy( "#address-cells" );
     gIODTRangeKey              = OSSymbol::withCStringNoCopy( "ranges" );
@@ -251,7 +255,7 @@ int IODTGetLoaderInfo( const char *key, void **infoAddr, int *infoSize )
 {
     IORegistryEntry            *chosen;
     OSData                             *propObj;
-    unsigned int               *propPtr;
+    dtptr_t                            *propPtr;
     unsigned int               propSize;
 
     chosen = IORegistryEntry::fromPath( "/chosen/memory-map", gIODTPlane );
@@ -261,9 +265,9 @@ int IODTGetLoaderInfo( const char *key, void **infoAddr, int *infoSize )
     if ( propObj == 0 ) return -1;
 
     propSize = propObj->getLength();
-    if ( propSize != (2 * sizeof(UInt32)) ) return -1;
+    if ( propSize != (2 * sizeof(dtptr_t)) ) return -1;
  
-    propPtr = (unsigned int *)propObj->getBytesNoCopy();
+    propPtr = (dtptr_t *)propObj->getBytesNoCopy();
     if ( propPtr == 0 ) return -1;
 
     *infoAddr = (void *)(uintptr_t) (propPtr[0]);
@@ -776,6 +780,7 @@ CompareKey( OSString * key,
     OSString           *string;
     const char         *ckey;
     UInt32                     keyLen;
+    UInt32          nlen;
     const char         *names;
     const char         *lastName;
     bool                       wild;
@@ -800,16 +805,16 @@ CompareKey( OSString * key,
 
     do {
         // for each name in the property
+        nlen = strnlen(names, lastName - names);
         if( wild)
-            matched = (0 == strncmp( ckey, names, keyLen - 1 ));
+            matched = ((nlen >= (keyLen - 1)) && (0 == strncmp(ckey, names, keyLen - 1)));
         else
-            matched = (keyLen == strlen( names ))
-                    && (0 == strncmp( ckey, names, keyLen ));
+            matched = (keyLen == nlen) && (0 == strncmp(ckey, names, keyLen));
 
         if( matched)
             result = names;
 
-        names = names + strlen( names) + 1;
+        names = names + nlen + 1;
 
     } while( (names < lastName) && (false == matched));
 
@@ -897,7 +902,7 @@ OSCollectionIterator * IODTFindMatchingEntries( IORegistryEntry * from,
     }
 
     cIter = OSCollectionIterator::withCollection( result);
-    result->release();
+    if (result) result->release();
 
     return( cIter);
 }
@@ -927,7 +932,7 @@ void IODTSetResolving( IORegistryEntry *    regEntry,
     return;
 }
 
-#if defined(__arm__) || defined(__i386__) || defined(__x86_64__)
+#if   defined(__arm__) || defined(__i386__) || defined(__x86_64__)
 static SInt32 DefaultCompare( UInt32 cellCount, UInt32 left[], UInt32 right[] )
 {
        cellCount--;
@@ -1239,6 +1244,7 @@ OSData * IODTFindSlotName( IORegistryEntry * regEntry, UInt32 deviceNumber )
     OSData                             *ret = 0;
     UInt32                             *bits;
     UInt32                             i;
+    size_t              nlen;
     char                               *names;
     char                               *lastName;
     UInt32                             mask;
@@ -1266,15 +1272,16 @@ OSData * IODTFindSlotName( IORegistryEntry * regEntry, UInt32 deviceNumber )
     for( i = 0; (i <= deviceNumber) && (names < lastName); i++ ) {
 
         if( mask & (1 << i)) {
+            nlen = 1 + strnlen(names, lastName - names);
             if( i == deviceNumber) {
-                data = OSData::withBytesNoCopy( names, 1 + strlen( names));
+                data = OSData::withBytesNoCopy(names, nlen);
                 if( data) {
                     regEntry->setProperty("AAPL,slot-name", data);
                     ret = data;
                     data->release();
                 }
             } else
-                names += 1 + strlen( names);
+                names += nlen;
         }
     }