void OSDictionary::removeObject(const OSSymbol *aKey) { unsigned int i; bool exists; if (!aKey) return; // if the key exists, remove the object if (fOptions & kSort) { i = OSSymbol::bsearch(aKey, &dictionary[0], count, sizeof(dictionary[0])); exists = (i < count) && (aKey == dictionary[i].key); } else for (exists = false, i = 0; i < count; i++) { if ((exists = (aKey == dictionary[i].key))) break; } if (exists) { dictEntry oldEntry = dictionary[i]; haveUpdated(); count--; bcopy(&dictionary[i+1], &dictionary[i], (count - i) * sizeof(dictionary[0])); oldEntry.key->taggedRelease(OSTypeID(OSCollection)); oldEntry.value->taggedRelease(OSTypeID(OSCollection)); return; } }
// GetPlistValue UInt32 VoodooPState::getPlistValue(OSDictionary * dictionary, const char * symbol) { OSObject * object = 0; OSBoolean * boolean = false; OSNumber * number = 0; OSString * string = 0; object = dictionary->getObject(symbol); if (object && (OSTypeIDInst(object) == OSTypeID(OSBoolean))) { boolean = OSDynamicCast(OSBoolean, object); return boolean->getValue(); } if (object && (OSTypeIDInst(object) == OSTypeID(OSNumber))) { number = OSDynamicCast(OSNumber, object); return number->unsigned32BitValue(); } if (object && (OSTypeIDInst(object) == OSTypeID(OSString))) { string = OSDynamicCast(OSString, object); // Implement string to number conversion } return 0; }
bool OSDictionary:: setObject(const OSSymbol *aKey, const OSMetaClassBase *anObject) { if (!anObject || !aKey) return false; // if the key exists, replace the object for (unsigned int i = 0; i < count; i++) { if (aKey == dictionary[i].key) { const OSMetaClassBase *oldObject = dictionary[i].value; anObject->taggedRetain(OSTypeID(OSCollection)); dictionary[i].value = anObject; haveUpdated(); oldObject->taggedRelease(OSTypeID(OSCollection)); return true; } } // add new key, possibly extending our capacity if (count >= capacity && count >= ensureCapacity(count+1)) return 0; aKey->taggedRetain(OSTypeID(OSCollection)); anObject->taggedRetain(OSTypeID(OSCollection)); dictionary[count].key = aKey; dictionary[count].value = anObject; count++; haveUpdated(); return true; }
bool OSDictionary::initWithDictionary(const OSDictionary *dict, unsigned int theCapacity) { unsigned int capacity; if ( !dict ) return false; capacity = dict->count; if ( theCapacity ) { if ( dict->count > theCapacity ) return false; capacity = theCapacity; } if (!initWithCapacity(capacity)) return false; count = dict->count; bcopy(dict->dictionary, dictionary, count * sizeof(dictEntry)); for (unsigned int i = 0; i < count; i++) { dictionary[i].key->taggedRetain(OSTypeID(OSCollection)); dictionary[i].value->taggedRetain(OSTypeID(OSCollection)); } return true; }
OSCollection * OSDictionary::copyCollection(OSDictionary *cycleDict) { bool allocDict = !cycleDict; OSCollection *ret = 0; OSDictionary *newDict = 0; if (allocDict) { cycleDict = OSDictionary::withCapacity(16); if (!cycleDict) return 0; } do { // Check for a cycle ret = super::copyCollection(cycleDict); if (ret) continue; newDict = OSDictionary::withDictionary(this); if (!newDict) continue; // Insert object into cycle Dictionary cycleDict->setObject((const OSSymbol *) this, newDict); for (unsigned int i = 0; i < count; i++) { const OSMetaClassBase *obj = dictionary[i].value; OSCollection *coll = OSDynamicCast(OSCollection, EXT_CAST(obj)); if (coll) { OSCollection *newColl = coll->copyCollection(cycleDict); if (!newColl) goto abortCopy; newDict->dictionary[i].value = newColl; coll->taggedRelease(OSTypeID(OSCollection)); newColl->taggedRetain(OSTypeID(OSCollection)); newColl->release(); }; } ret = newDict; newDict = 0; } while (false); abortCopy: if (newDict) newDict->release(); if (allocDict) cycleDict->release(); return ret; }
void OSDictionary::flushCollection() { haveUpdated(); for (unsigned int i = 0; i < count; i++) { dictionary[i].key->taggedRelease(OSTypeID(OSCollection)); dictionary[i].value->taggedRelease(OSTypeID(OSCollection)); } count = 0; }
bool OSDictionary:: setObject(const OSSymbol *aKey, const OSMetaClassBase *anObject, bool onlyAdd) { unsigned int i; bool exists; if (!anObject || !aKey) return false; // if the key exists, replace the object if (fOptions & kSort) { i = OSSymbol::bsearch(aKey, &dictionary[0], count, sizeof(dictionary[0])); exists = (i < count) && (aKey == dictionary[i].key); } else for (exists = false, i = 0; i < count; i++) { if ((exists = (aKey == dictionary[i].key))) break; } if (exists) { if (onlyAdd) return false; const OSMetaClassBase *oldObject = dictionary[i].value; haveUpdated(); anObject->taggedRetain(OSTypeID(OSCollection)); dictionary[i].value = anObject; oldObject->taggedRelease(OSTypeID(OSCollection)); return true; } // add new key, possibly extending our capacity if (count >= capacity && count >= ensureCapacity(count+1)) return false; haveUpdated(); bcopy(&dictionary[i], &dictionary[i+1], (count - i) * sizeof(dictionary[0])); aKey->taggedRetain(OSTypeID(OSCollection)); anObject->taggedRetain(OSTypeID(OSCollection)); dictionary[i].key = aKey; dictionary[i].value = anObject; count++; return true; }
void OSArray:: replaceObject(unsigned int index, const OSMetaClassBase *anObject) { const OSMetaClassBase *oldObject; if ((index >= count) || !anObject) return; haveUpdated(); oldObject = array[index]; array[index] = anObject; anObject->taggedRetain(OSTypeID(OSCollection)); oldObject->taggedRelease(OSTypeID(OSCollection)); }
/* internal */ bool OSOrderedSet::setObject(unsigned int index, const OSMetaClassBase *anObject) { unsigned int i; unsigned int newCount = count + 1; if ((index > count) || !anObject) return false; if (containsObject(anObject)) return false; // do we need more space? if (newCount > capacity && newCount > ensureCapacity(newCount)) return false; haveUpdated(); if (index != count) { for (i = count; i > index; i--) array[i] = array[i-1]; } array[index].obj = anObject; // array[index].pri = pri; anObject->taggedRetain(OSTypeID(OSCollection)); count++; return true; }
OSSymbol * GetSymbolFromArray(OSArray * array, UInt8 index) { const OSMetaClass *typeID; char stringBuf[255]; typeID = OSTypeIDInst(array->getObject(index)); if (typeID == OSTypeID(OSString)) { return (OSSymbol *)OSDynamicCast(OSString, array->getObject(index)); } else if (typeID == OSTypeID(OSData)) { bzero(stringBuf, sizeof(stringBuf)); snprintf(stringBuf, sizeof(stringBuf), "%s", (char *)OSDynamicCast(OSData, array->getObject(index))->getBytesNoCopy()); return (OSSymbol *)OSSymbol::withCStringNoCopy(stringBuf); } return (OSSymbol *)unknownObjectKey; }
bool OSArray::initWithObjects(const OSObject *objects[], unsigned int theCount, unsigned int theCapacity) { unsigned int initCapacity; if (!theCapacity) initCapacity = theCount; else if (theCount > theCapacity) return false; else initCapacity = theCapacity; if (!objects || !initWithCapacity(initCapacity)) return false; for ( unsigned int i = 0; i < theCount; i++ ) { const OSMetaClassBase *newObject = *objects++; if (!newObject) return false; array[count++] = newObject; newObject->taggedRetain(OSTypeID(OSCollection)); } return true; }
UInt32 GetValueFromArray(OSArray * array, UInt8 index) { OSObject * object = array->getObject(index); if (object && (OSTypeIDInst(object) == OSTypeID(OSNumber))) { OSNumber * number = OSDynamicCast(OSNumber, object); if (number) return number->unsigned32BitValue(); } return -1; }
void OSArray::flushCollection() { unsigned int i; haveUpdated(); for (i = 0; i < count; i++) { array[i]->taggedRelease(OSTypeID(OSCollection)); } count = 0; }
void OSOrderedSet::flushCollection() { unsigned int i; haveUpdated(); for (i = 0; i < count; i++) array[i].obj->taggedRelease(OSTypeID(OSCollection)); count = 0; }
void OSDictionary::removeObject(const OSSymbol *aKey) { if (!aKey) return; // if the key exists, remove the object for (unsigned int i = 0; i < count; i++) if (aKey == dictionary[i].key) { dictEntry oldEntry = dictionary[i]; haveUpdated(); count--; for (; i < count; i++) dictionary[i] = dictionary[i+1]; oldEntry.key->taggedRelease(OSTypeID(OSCollection)); oldEntry.value->taggedRelease(OSTypeID(OSCollection)); return; } }
// GetPlistValue UInt32 VoodooPState::getPlistValue(OSDictionary * dictionary, const char * symbol, const char * subdictionary) { OSObject * object = dictionary->getObject(subdictionary); if (object && (OSTypeIDInst(object) == OSTypeID(OSDictionary))) { OSDictionary * newdictionary = OSDynamicCast(OSDictionary, object); return getPlistValue(newdictionary, symbol); } return 0; }
bool OSDictionary::initWithDictionary(const OSDictionary *dict, unsigned int theCapacity) { unsigned int newCapacity; if ( !dict ) return false; newCapacity = dict->count; if ( theCapacity ) { if ( dict->count > theCapacity ) return false; newCapacity = theCapacity; } if (!initWithCapacity(newCapacity)) return false; if ((kSort & fOptions) && !(kSort & dict->fOptions)) { for (unsigned int i = 0; i < dict->count; i++) { if (!setObject(dict->dictionary[i].key, dict->dictionary[i].value)) { return false; } } return true; } count = dict->count; bcopy(dict->dictionary, dictionary, count * sizeof(dictEntry)); for (unsigned int i = 0; i < count; i++) { dictionary[i].key->taggedRetain(OSTypeID(OSCollection)); dictionary[i].value->taggedRetain(OSTypeID(OSCollection)); } return true; }
void OSArray::removeObject(unsigned int index) { unsigned int i; const OSMetaClassBase *oldObject; if (index >= count) return; haveUpdated(); oldObject = array[index]; count--; for (i = index; i < count; i++) array[i] = array[i+1]; oldObject->taggedRelease(OSTypeID(OSCollection)); }
void OSOrderedSet::removeObject(const OSMetaClassBase *anObject) { bool deleted = false; unsigned int i; for (i = 0; i < count; i++) { if (deleted) array[i-1] = array[i]; else if (array[i].obj == anObject) { deleted = true; haveUpdated(); // Pity we can't flush the log array[i].obj->taggedRelease(OSTypeID(OSCollection)); } } if (deleted) count--; }
bool OSArray::merge(const OSArray * otherArray) { unsigned int otherCount = otherArray->getCount(); unsigned int newCount = count + otherCount; if (!otherCount) return true; // do we need more space? if (newCount > capacity && newCount > ensureCapacity(newCount)) return false; haveUpdated(); for (unsigned int i = 0; i < otherCount; i++) { const OSMetaClassBase *newObject = otherArray->getObject(i); array[count++] = newObject; newObject->taggedRetain(OSTypeID(OSCollection)); } return true; }
// Class probe IOService * VoodooPState::probe(IOService * provider, SInt32 * score) { Ready = false; // Probe the superclass if (IOService::probe(provider, score) != this) return NULL; // Read our own values from the property list OSDictionary * dictionary = OSDynamicCast(OSDictionary, getProperty(keyPowerControl)); if (!dictionary) return NULL; UseEfiFsb = getPlistValue(dictionary, keyUseEfiFsb); VoltageOverride = getPlistValue(dictionary, keyVoltageOverride); VoltageProbe = getPlistValue(dictionary, keyVoltageProbe); UserVoltageMax = getPlistValue(dictionary, keyUserVoltageMax); UserVoltageMin = getPlistValue(dictionary, keyUserVoltageMin); ColdStart = getPlistValue(dictionary, keyColdStart); TimerInterval = getPlistValue(dictionary, keyTimerInterval); UseACPI = getPlistValue(dictionary, keyUseACPI); if(TimerInterval < 50){ TimerInterval = 50; } // Get CPU's from I/O Kit CpuCount = getCpuCount(); // No CPU's found -> bailout if (CpuCount == 0) return NULL; // Get FSB from /efi/platform CpuFSB = gPEClockFrequencyInfo.bus_frequency_max_hz >> 2; if (UseEfiFsb) { IORegistryEntry * entry = fromPath(keyEfiPlatform, gIODTPlane); if (entry) { OSObject * object = entry->getProperty(keyEfiFsbFrequency); if (object && (OSTypeIDInst(object) == OSTypeID(OSData))) { OSData * data = OSDynamicCast(OSData, object); if (data) { CpuFSB = * (UInt32 *) data->getBytesNoCopy(); gPEClockFrequencyInfo.bus_frequency_max_hz = CpuFSB << 2; } } } } CpuFSB = (CpuFSB+Mega/2) / Mega; // Mega is enough #if SUPPORT_VOODOO_KERNEL { UInt64 magic; nanoseconds_to_absolutetime(~(0), &magic); VoodooKernel = (magic == 2); } #endif // Enumerate CPU's CpuCoreTech = Unknown; { uint32_t data[4]; do_cpuid(0, data); ((uint32_t*)vendor)[0] = data[1]; ((uint32_t*)vendor)[1] = data[3]; ((uint32_t*)vendor)[2] = data[2]; vendor[15] = 0; do_cpuid(1, data); CpuSignature = data[0]; // Features ((uint32_t*)&Features)[0] = data[3]; ((uint32_t*)&Features)[1] = data[2]; for( int i = 0; i < 3; i++ ){ do_cpuid(0x80000002+i, data); memcpy( &brand_string[i*16], data, 16 ); } brand_string[16*3] = 0; } // Find core technology and cross core vendor specifics // Intel if (!strncmp(vendor, CPUID_VID_INTEL, sizeof(CPUID_VID_INTEL))) { if(!intel_probe(this)) return NULL; } // AMD else if (!strncmp(vendor, CPUID_VID_AMD, sizeof(CPUID_VID_AMD))) { if(!amd_probe(this)) return NULL; } // Unknown CPU or core technology else { ErrorLog("CPU: Core Technology Unknown - Signature %x (%s)(%s)", (unsigned int)CpuSignature, vendor, brand_string); return NULL; } return this; }