Loading...
libkern/c++/OSSymbol.cpp xnu-2422.100.13 xnu-1228
--- xnu/xnu-2422.100.13/libkern/c++/OSSymbol.cpp
+++ xnu/xnu-1228/libkern/c++/OSSymbol.cpp
@@ -40,7 +40,7 @@
 
 #define super OSString
 
-typedef struct { unsigned int i, j; } OSSymbolPoolState;
+typedef struct { int i, j; } OSSymbolPoolState;
 
 #if OSALLOCDEBUG
 extern "C" {
@@ -79,7 +79,7 @@
     Bucket *buckets;
     unsigned int nBuckets;
     unsigned int count;
-    lck_mtx_t *poolGate;
+    mutex_t *poolGate;
 
     static inline void hashSymbol(const char *s,
                                   unsigned int *hashP,
@@ -115,8 +115,8 @@
 
     bool init();
 
-    inline void closeGate() { lck_mtx_lock(poolGate); };
-    inline void openGate()  { lck_mtx_unlock(poolGate); };
+    inline void closeGate() { mutex_lock(poolGate); };
+    inline void openGate()  { mutex_unlock(poolGate); };
 
     OSSymbol *findSymbol(const char *cString) const;
     OSSymbol *insertSymbol(OSSymbol *sym);
@@ -141,8 +141,6 @@
     kfree(mem, size);
     ACCUMSIZE(-size);
 }
-
-extern lck_grp_t *IOLockGroup;
 
 bool OSSymbolPool::init()
 {
@@ -155,7 +153,7 @@
 
     bzero(buckets, nBuckets * sizeof(Bucket));
 
-    poolGate = lck_mtx_alloc_init(IOLockGroup, LCK_ATTR_NULL);
+    poolGate = mutex_alloc(0);
 
     return poolGate != 0;
 }
@@ -172,19 +170,12 @@
 OSSymbolPool::~OSSymbolPool()
 {
     if (buckets) {
-        Bucket *thisBucket;
-        for (thisBucket = &buckets[0]; thisBucket < &buckets[nBuckets]; thisBucket++) {
-            if (thisBucket->count > 1) {
-                kfree(thisBucket->symbolP, thisBucket->count * sizeof(OSSymbol *));
-                ACCUMSIZE(-(thisBucket->count * sizeof(OSSymbol *)));
-            }
-        }
         kfree(buckets, nBuckets * sizeof(Bucket));
         ACCUMSIZE(-(nBuckets * sizeof(Bucket)));
     }
 
     if (poolGate)
-        lck_mtx_free(poolGate, IOLockGroup);
+        kfree(poolGate, 36 * 4);
 }
 
 unsigned long OSSymbolPool::log2(unsigned int x)
@@ -282,7 +273,7 @@
         probeSymbol = (OSSymbol *) thisBucket->symbolP;
 
         if (inLen == probeSymbol->length
-        &&  (strncmp(probeSymbol->string, cString, probeSymbol->length) == 0))
+        &&  (strcmp(probeSymbol->string, cString) == 0))
             return probeSymbol;
 	return 0;
     }
@@ -290,7 +281,7 @@
     for (list = thisBucket->symbolP; j--; list++) {
         probeSymbol = *list;
         if (inLen == probeSymbol->length
-        &&  (strncmp(probeSymbol->string, cString, probeSymbol->length) == 0))
+        &&  (strcmp(probeSymbol->string, cString) == 0))
             return probeSymbol;
     }
 
@@ -319,7 +310,7 @@
         probeSymbol = (OSSymbol *) thisBucket->symbolP;
 
         if (inLen == probeSymbol->length
-        &&  strncmp(probeSymbol->string, cString, probeSymbol->length) == 0)
+        &&  strcmp(probeSymbol->string, cString) == 0)
             return probeSymbol;
 
         list = (OSSymbol **) kalloc(2 * sizeof(OSSymbol *));
@@ -338,7 +329,7 @@
     for (list = thisBucket->symbolP; j--; list++) {
         probeSymbol = *list;
         if (inLen == probeSymbol->length
-        &&  strncmp(probeSymbol->string, cString, probeSymbol->length) == 0)
+        &&  strcmp(probeSymbol->string, cString) == 0)
             return probeSymbol;
     }
 
@@ -368,11 +359,8 @@
     j = thisBucket->count;
     list = thisBucket->symbolP;
 
-    if (!j) {
-	// couldn't find the symbol; probably means string hash changed
-        panic("removeSymbol %s count %d ", sym->string ? sym->string : "no string", count);
+    if (!j)
         return;
-    }
 
     if (j == 1) {
         probeSymbol = (OSSymbol *) list;
@@ -384,8 +372,6 @@
             SHRINK_POOL();
             return;
         }
-	// couldn't find the symbol; probably means string hash changed
-    	panic("removeSymbol %s count %d ", sym->string ? sym->string : "no string", count);
         return;
     }
 
@@ -411,8 +397,6 @@
             SHRINK_POOL();
             return;
         }
-	// couldn't find the symbol; probably means string hash changed
-    	panic("removeSymbol %s count %d ", sym->string ? sym->string : "no string", count);
         return;
     }
 
@@ -438,8 +422,6 @@
             return;
         }
     }
-    // couldn't find the symbol; probably means string hash changed
-    panic("removeSymbol %s count %d ", sym->string ? sym->string : "no string", count);
 }
 
 /*
@@ -608,33 +590,3 @@
     else
 	return false;
 }
-
-unsigned int
-OSSymbol::bsearch(
-	const void *  key,
-	const void *  array,
-	unsigned int  arrayCount,
-	size_t        memberSize)
-{
-    const void **p;
-    unsigned int baseIdx = 0;
-    unsigned int lim;
-
-    for (lim = arrayCount; lim; lim >>= 1)
-    {
-	p = (typeof(p)) (((uintptr_t) array) + (baseIdx + (lim >> 1)) * memberSize);
-	if (key == *p)
-	{
-	    return (baseIdx + (lim >> 1));
-	}
-	if (key > *p) 
-	{	
-	    // move right
-	    baseIdx += (lim >> 1) + 1;
-	    lim--;
-	}
-	// else move left
-    }
-    // not found, insertion point here
-    return (baseIdx + (lim >> 1));
-}