Loading...
--- xnu/xnu-792.6.76/iokit/Kernel/IONVRAM.cpp
+++ xnu/xnu-123.5/iokit/Kernel/IONVRAM.cpp
@@ -28,10 +28,6 @@
#define super IOService
-#define kIONVRAMPrivilege kIOClientPrivilegeAdministrator
-//#define kIONVRAMPrivilege kIOClientPrivilegeLocalUser
-
-
OSDefineMetaClassAndStructors(IODTNVRAM, IOService);
bool IODTNVRAM::init(IORegistryEntry *old, const IORegistryPlane *plane)
@@ -46,13 +42,7 @@
_nvramImage = IONew(UInt8, kIODTNVRAMImageSize);
if (_nvramImage == 0) return false;
-
- _nvramPartitionOffsets = OSDictionary::withCapacity(1);
- if (_nvramPartitionOffsets == 0) return false;
-
- _nvramPartitionLengths = OSDictionary::withCapacity(1);
- if (_nvramPartitionLengths == 0) return false;
-
+
_registryPropertiesKey = OSSymbol::withCStringNoCopy("aapl,pci");
if (_registryPropertiesKey == 0) return false;
@@ -61,11 +51,7 @@
void IODTNVRAM::registerNVRAMController(IONVRAMController *nvram)
{
- char partitionID[18];
- UInt32 partitionOffset, partitionLength;
- UInt32 freePartitionOffset, freePartitionSize;
- UInt32 currentLength, currentOffset = 0;
- OSNumber *partitionOffsetNumber, *partitionLengthNumber;
+ UInt32 currentOffset = 0;
if (_nvramController != 0) return;
@@ -73,58 +59,26 @@
_nvramController->read(0, _nvramImage, kIODTNVRAMImageSize);
- // Find the offsets for the OF, XPRAM, NameRegistry and PanicInfo partitions.
+ // Find the offsets for the OF, XPRAM and NameRegistry partitions in NVRAM.
_ofPartitionOffset = 0xFFFFFFFF;
_xpramPartitionOffset = 0xFFFFFFFF;
_nrPartitionOffset = 0xFFFFFFFF;
- _piPartitionOffset = 0xFFFFFFFF;
- freePartitionOffset = 0xFFFFFFFF;
- freePartitionSize = 0;
if (getPlatform()->getBootROMType()) {
// Look through the partitions to find the OF, MacOS partitions.
while (currentOffset < kIODTNVRAMImageSize) {
- currentLength = ((UInt16 *)(_nvramImage + currentOffset))[1] * 16;
-
- partitionOffset = currentOffset + 16;
- partitionLength = currentLength - 16;
-
- if (strncmp((const char *)_nvramImage + currentOffset + 4,
- kIODTNVRAMOFPartitionName, 12) == 0) {
- _ofPartitionOffset = partitionOffset;
- _ofPartitionSize = partitionLength;
- } else if (strncmp((const char *)_nvramImage + currentOffset + 4,
- kIODTNVRAMXPRAMPartitionName, 12) == 0) {
- _xpramPartitionOffset = partitionOffset;
+ if (strcmp((const char *)_nvramImage + currentOffset + 4, "common") == 0) {
+ _ofPartitionOffset = currentOffset + 16;
+ _ofPartitionSize =
+ (((UInt16 *)(_nvramImage + currentOffset))[1] - 1) * 0x10;
+ } else if (strcmp((const char *)_nvramImage + currentOffset + 4, "APL,MacOS75") == 0) {
+ _xpramPartitionOffset = currentOffset + 16;
_xpramPartitionSize = kIODTNVRAMXPRAMSize;
_nrPartitionOffset = _xpramPartitionOffset + _xpramPartitionSize;
- _nrPartitionSize = partitionLength - _xpramPartitionSize;
- } else if (strncmp((const char *)_nvramImage + currentOffset + 4,
- kIODTNVRAMPanicInfoPartitonName, 12) == 0) {
- _piPartitionOffset = partitionOffset;
- _piPartitionSize = partitionLength;
- } else if (strncmp((const char *)_nvramImage + currentOffset + 4,
- kIODTNVRAMFreePartitionName, 12) == 0) {
- freePartitionOffset = currentOffset;
- freePartitionSize = currentLength;
- } else {
- // Construct the partition ID from the signature and name.
- sprintf(partitionID, "0x%02x,",
- *(UInt8 *)(_nvramImage + currentOffset));
- strncpy(partitionID + 5,
- (const char *)(_nvramImage + currentOffset + 4), 12);
- partitionID[17] = '\0';
-
- partitionOffsetNumber = OSNumber::withNumber(partitionOffset, 32);
- partitionLengthNumber = OSNumber::withNumber(partitionLength, 32);
-
- // Save the partition offset and length
- _nvramPartitionOffsets->setObject(partitionID, partitionOffsetNumber);
- _nvramPartitionLengths->setObject(partitionID, partitionLengthNumber);
-
- partitionOffsetNumber->release();
- partitionLengthNumber->release();
+ _nrPartitionSize =
+ (((UInt16 *)(_nvramImage + currentOffset))[1] - 1) * 0x10 -
+ _xpramPartitionSize;
}
- currentOffset += currentLength;
+ currentOffset += ((short *)(_nvramImage + currentOffset))[1] * 16;
}
} else {
// Use the fixed address for old world machines.
@@ -143,60 +97,6 @@
if (_nrPartitionOffset != 0xFFFFFFFF)
_nrImage = _nvramImage + _nrPartitionOffset;
- if (_piPartitionOffset == 0xFFFFFFFF) {
- if (freePartitionSize > 0x20) {
- // Set the signature to 0xa1.
- _nvramImage[freePartitionOffset] = 0xa1;
- // Set the checksum to 0.
- _nvramImage[freePartitionOffset + 1] = 0;
- // Set the name for the Panic Info partition.
- strncpy((char *)(_nvramImage + freePartitionOffset + 4),
- kIODTNVRAMPanicInfoPartitonName, 12);
-
- // Calculate the partition offset and size.
- _piPartitionOffset = freePartitionOffset + 0x10;
- _piPartitionSize = 0x800;
- if (_piPartitionSize + 0x20 > freePartitionSize)
- _piPartitionSize = freePartitionSize - 0x20;
-
- _piImage = _nvramImage + _piPartitionOffset;
-
- // Zero the new partition.
- bzero(_piImage, _piPartitionSize);
-
- // Set the partition size.
- *(UInt16 *)(_nvramImage + freePartitionOffset + 2) =
- (_piPartitionSize / 0x10) + 1;
-
- // Set the partition checksum.
- _nvramImage[freePartitionOffset + 1] =
- calculatePartitionChecksum(_nvramImage + freePartitionOffset);
-
- // Calculate the free partition offset and size.
- freePartitionOffset += _piPartitionSize + 0x10;
- freePartitionSize -= _piPartitionSize + 0x10;
-
- // Set the signature to 0x7f.
- _nvramImage[freePartitionOffset] = 0x7f;
- // Set the checksum to 0.
- _nvramImage[freePartitionOffset + 1] = 0;
- // Set the name for the free partition.
- strncpy((char *)(_nvramImage + freePartitionOffset + 4),
- kIODTNVRAMFreePartitionName, 12);
- // Set the partition size.
- *(UInt16 *)(_nvramImage + freePartitionOffset + 2) =
- freePartitionSize / 0x10;
- // Set the partition checksum.
- _nvramImage[freePartitionOffset + 1] =
- calculatePartitionChecksum(_nvramImage + freePartitionOffset);
-
- // Set the nvram image as dirty.
- _nvramImageDirty = true;
- }
- } else {
- _piImage = _nvramImage + _piPartitionOffset;
- }
-
initOFVariables();
}
@@ -204,8 +104,7 @@
{
if (!_nvramImageDirty && !_ofImageDirty) return;
- // Don't try to sync OF Variables if the system has already paniced.
- if (!_systemPaniced) syncOFVariables();
+ syncOFVariables();
_nvramController->write(0, _nvramImage, kIODTNVRAMImageSize);
_nvramController->sync();
@@ -213,7 +112,7 @@
_nvramImageDirty = false;
}
-bool IODTNVRAM::serializeProperties(OSSerialize *s) const
+bool IODTNVRAM::serializeProperties(OSSerialize *serialize) const
{
bool result;
UInt32 variablePerm;
@@ -224,7 +123,7 @@
if (_ofDict == 0) return false;
// Verify permissions.
- result = IOUserClient::clientHasPrivilege(current_task(), kIONVRAMPrivilege);
+ result = IOUserClient::clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator);
if (result != kIOReturnSuccess) {
tmpDict = OSDictionary::withCapacity(1);
if (tmpDict == 0) return false;
@@ -246,7 +145,7 @@
dict = _ofDict;
}
- result = dict->serialize(s);
+ result = dict->serialize(serialize);
if (tmpDict != 0) tmpDict->release();
if (iter != 0) iter->release();
@@ -262,7 +161,7 @@
if (_ofDict == 0) return 0;
// Verify permissions.
- result = IOUserClient::clientHasPrivilege(current_task(), kIONVRAMPrivilege);
+ result = IOUserClient::clientHasPrivilege(current_task(), "root");
if (result != kIOReturnSuccess) {
variablePerm = getOFVariablePerm(aKey);
if (variablePerm == kOFVariablePermRootOnly) return 0;
@@ -295,7 +194,7 @@
if (_ofDict == 0) return false;
// Verify permissions.
- result = IOUserClient::clientHasPrivilege(current_task(), kIONVRAMPrivilege);
+ result = IOUserClient::clientHasPrivilege(current_task(), "root");
if (result != kIOReturnSuccess) {
propPerm = getOFVariablePerm(aKey);
if (propPerm != kOFVariablePermUserWrite) return false;
@@ -305,9 +204,6 @@
if (getPlatform()->getBootROMType() == 0) {
if (_ofDict->getObject(aKey) == 0) return false;
}
-
- // Don't allow change of 'aapl,panic-info'.
- if (aKey->isEqualTo(kIODTNVRAMPanicInfoKey)) return false;
// Make sure the object is of the correct type.
propType = getOFVariableType(aKey);
@@ -351,41 +247,11 @@
return result;
}
-void IODTNVRAM::removeProperty(const OSSymbol *aKey)
-{
- bool result;
- UInt32 propPerm;
-
- if (_ofDict == 0) return;
-
- // Verify permissions.
- result = IOUserClient::clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator);
- if (result != kIOReturnSuccess) {
- propPerm = getOFVariablePerm(aKey);
- if (propPerm != kOFVariablePermUserWrite) return;
- }
-
- // Don't allow removal of properties on old world machines.
- if (getPlatform()->getBootROMType() == 0) return;
-
- // Don't allow change of 'aapl,panic-info'.
- if (aKey->isEqualTo(kIODTNVRAMPanicInfoKey)) return;
-
- // If the object exists, remove it from the dictionary.
- result = _ofDict->getObject(aKey) != 0;
- if (result) {
- _ofDict->removeObject(aKey);
-
- _ofImageDirty = true;
- }
-}
-
IOReturn IODTNVRAM::setProperties(OSObject *properties)
{
bool result = true;
OSObject *object;
const OSSymbol *key;
- const OSString *tmpStr;
OSDictionary *dict;
OSCollectionIterator *iter;
@@ -402,19 +268,7 @@
object = dict->getObject(key);
if (object == 0) continue;
- if (key->isEqualTo(kIONVRAMDeletePropertyKey)) {
- tmpStr = OSDynamicCast(OSString, object);
- if (tmpStr != 0) {
- key = OSSymbol::withString(tmpStr);
- removeProperty(key);
- key->release();
- result = true;
- } else {
- result = false;
- }
- } else {
- result = setProperty(key, object);
- }
+ result = setProperty(key, object);
}
iter->release();
@@ -426,9 +280,10 @@
IOReturn IODTNVRAM::readXPRAM(IOByteCount offset, UInt8 *buffer,
IOByteCount length)
{
- if (_xpramImage == 0) return kIOReturnUnsupported;
-
- if ((buffer == 0) || (length == 0) ||
+ if ((_nvramImage == 0) || (_xpramPartitionOffset == 0))
+ return kIOReturnNotReady;
+
+ if ((buffer == 0) || (length <= 0) || (offset < 0) ||
(offset + length > kIODTNVRAMXPRAMSize))
return kIOReturnBadArgument;
@@ -440,9 +295,10 @@
IOReturn IODTNVRAM::writeXPRAM(IOByteCount offset, UInt8 *buffer,
IOByteCount length)
{
- if (_xpramImage == 0) return kIOReturnUnsupported;
-
- if ((buffer == 0) || (length == 0) ||
+ if ((_nvramImage == 0) || (_xpramPartitionOffset == 0))
+ return kIOReturnNotReady;
+
+ if ((buffer == 0) || (length <= 0) || (offset < 0) ||
(offset + length > kIODTNVRAMXPRAMSize))
return kIOReturnBadArgument;
@@ -481,101 +337,9 @@
return err;
}
-OSDictionary *IODTNVRAM::getNVRAMPartitions(void)
-{
- return _nvramPartitionLengths;
-}
-
-IOReturn IODTNVRAM::readNVRAMPartition(const OSSymbol *partitionID,
- IOByteCount offset, UInt8 *buffer,
- IOByteCount length)
-{
- OSNumber *partitionOffsetNumber, *partitionLengthNumber;
- UInt32 partitionOffset, partitionLength;
-
- partitionOffsetNumber =
- (OSNumber *)_nvramPartitionOffsets->getObject(partitionID);
- partitionLengthNumber =
- (OSNumber *)_nvramPartitionLengths->getObject(partitionID);
-
- if ((partitionOffsetNumber == 0) || (partitionLengthNumber == 0))
- return kIOReturnNotFound;
-
- partitionOffset = partitionOffsetNumber->unsigned32BitValue();
- partitionLength = partitionLengthNumber->unsigned32BitValue();
-
- if ((buffer == 0) || (length == 0) ||
- (offset + length > partitionLength))
- return kIOReturnBadArgument;
-
- bcopy(_nvramImage + partitionOffset + offset, buffer, length);
-
- return kIOReturnSuccess;
-}
-
-IOReturn IODTNVRAM::writeNVRAMPartition(const OSSymbol *partitionID,
- IOByteCount offset, UInt8 *buffer,
- IOByteCount length)
-{
- OSNumber *partitionOffsetNumber, *partitionLengthNumber;
- UInt32 partitionOffset, partitionLength;
-
- partitionOffsetNumber =
- (OSNumber *)_nvramPartitionOffsets->getObject(partitionID);
- partitionLengthNumber =
- (OSNumber *)_nvramPartitionLengths->getObject(partitionID);
-
- if ((partitionOffsetNumber == 0) || (partitionLengthNumber == 0))
- return kIOReturnNotFound;
-
- partitionOffset = partitionOffsetNumber->unsigned32BitValue();
- partitionLength = partitionLengthNumber->unsigned32BitValue();
-
- if ((buffer == 0) || (length == 0) ||
- (offset + length > partitionLength))
- return kIOReturnBadArgument;
-
- bcopy(buffer, _nvramImage + partitionOffset + offset, length);
-
- _nvramImageDirty = true;
-
- return kIOReturnSuccess;
-}
-
-UInt32 IODTNVRAM::savePanicInfo(UInt8 *buffer, IOByteCount length)
-{
- if ((_piImage == 0) || (length <= 0)) return 0;
-
- if (length > (_piPartitionSize - 4))
- length = _piPartitionSize - 4;
-
- // Save the Panic Info.
- bcopy(buffer, _piImage + 4, length);
-
- // Save the Panic Info length.
- *(UInt32 *)_piImage = length;
-
- _nvramImageDirty = true;
-
- _systemPaniced = true;
-
- return length;
-}
-
-// Private methods
-
-UInt8 IODTNVRAM::calculatePartitionChecksum(UInt8 *partitionHeader)
-{
- UInt8 cnt, isum, csum = 0;
-
- for (cnt = 0; cnt < 0x10; cnt++) {
- isum = csum + partitionHeader[cnt];
- if (isum < csum) isum++;
- csum = isum;
- }
-
- return csum;
-}
+
+
+// Private methods for Open Firmware variable access.
struct OWVariablesHeader {
UInt16 owMagic;
@@ -650,20 +414,6 @@
if (propObject != 0) {
_ofDict->setObject("boot-args", propObject);
propObject->release();
- }
- }
-
- // Create the 'aapl,panic-info' property if needed.
- if (_piImage != 0) {
- propDataLength = *(UInt32 *)_piImage;
- if ((propDataLength != 0) && (propDataLength < (_piPartitionSize - 4))) {
- propObject = OSData::withBytes(_piImage + 4, propDataLength);
- _ofDict->setObject(kIODTNVRAMPanicInfoKey, propObject);
- propObject->release();
-
- // Clear the length from _piImage and mark dirty.
- *(UInt32 *)_piImage = 0;
- _nvramImageDirty = true;
}
}
} else {
@@ -728,8 +478,7 @@
bool ok;
UInt32 cnt, length, maxLength;
UInt32 curOffset, tmpOffset, tmpType, tmpDataLength;
- UInt8 *buffer, *tmpBuffer;
- const UInt8 *tmpData;
+ UInt8 *buffer, *tmpBuffer, *tmpData;
const OSSymbol *tmpSymbol;
OSObject *tmpObject;
OSBoolean *tmpBoolean;
@@ -756,9 +505,6 @@
while (ok) {
tmpSymbol = OSDynamicCast(OSSymbol, iter->getNextObject());
if (tmpSymbol == 0) break;
-
- // Don't save 'aapl,panic-info'.
- if (tmpSymbol->isEqualTo(kIODTNVRAMPanicInfoKey)) continue;
tmpObject = _ofDict->getObject(tmpSymbol);
@@ -813,7 +559,7 @@
case kOFVariableTypeString :
tmpString = OSDynamicCast(OSString, tmpObject);
- tmpData = (const UInt8 *)tmpString->getCStringNoCopy();
+ tmpData = (UInt8 *) tmpString->getCStringNoCopy();
tmpDataLength = tmpString->getLength();
if ((curOffset - tmpDataLength) < sizeof(OWVariablesHeader)) {
@@ -853,10 +599,10 @@
}
struct OFVariable {
- const char *variableName;
- UInt32 variableType;
- UInt32 variablePerm;
- SInt32 variableOffset;
+ char *variableName;
+ UInt32 variableType;
+ UInt32 variablePerm;
+ SInt32 variableOffset;
};
typedef struct OFVariable OFVariable;
@@ -911,7 +657,6 @@
{"aapl,pci", kOFVariableTypeData, kOFVariablePermRootOnly, -1},
{"security-mode", kOFVariableTypeString, kOFVariablePermUserRead, -1},
{"security-password", kOFVariableTypeData, kOFVariablePermRootOnly, -1},
- {"boot-image", kOFVariableTypeData, kOFVariablePermUserWrite, -1},
{0, kOFVariableTypeData, kOFVariablePermUserRead, -1}
};
@@ -1038,7 +783,7 @@
bool IODTNVRAM::convertObjectToProp(UInt8 *buffer, UInt32 *length,
const OSSymbol *propSymbol, OSObject *propObject)
{
- const UInt8 *propName;
+ UInt8 *propName;
UInt32 propNameLength, propDataLength;
UInt32 propType, tmpValue;
OSBoolean *tmpBoolean = 0;
@@ -1046,7 +791,7 @@
OSString *tmpString = 0;
OSData *tmpData = 0;
- propName = (const UInt8 *)propSymbol->getCStringNoCopy();
+ propName = (UInt8 *)propSymbol->getCStringNoCopy();
propNameLength = propSymbol->getLength();
propType = getOFVariableType(propSymbol);
@@ -1151,12 +896,11 @@
void IODTNVRAM::updateOWBootArgs(const OSSymbol *key, OSObject *value)
{
- bool wasBootArgs, bootr = false;
- UInt32 cnt;
- OSString *tmpString, *bootCommand, *bootArgs = 0;
- const UInt8 *bootCommandData, *bootArgsData;
- UInt8 *tmpData;
- UInt32 bootCommandDataLength, bootArgsDataLength, tmpDataLength;
+ bool wasBootArgs, bootr = false;
+ UInt32 cnt;
+ OSString *tmpString, *bootCommand, *bootArgs = 0;
+ UInt8 *bootCommandData, *bootArgsData, *tmpData;
+ UInt32 bootCommandDataLength, bootArgsDataLength, tmpDataLength;
tmpString = OSDynamicCast(OSString, value);
if (tmpString == 0) return;
@@ -1171,7 +915,7 @@
if (bootCommand == 0) return;
} else return;
- bootCommandData = (const UInt8 *)bootCommand->getCStringNoCopy();
+ bootCommandData = (UInt8 *)bootCommand->getCStringNoCopy();
bootCommandDataLength = bootCommand->getLength();
if (bootCommandData == 0) return;
@@ -1191,7 +935,7 @@
}
if (wasBootArgs) {
- bootArgsData = (const UInt8 *)bootArgs->getCStringNoCopy();
+ bootArgsData = (UInt8 *)bootArgs->getCStringNoCopy();
bootArgsDataLength = bootArgs->getLength();
if (bootArgsData == 0) return;
@@ -1357,7 +1101,7 @@
return err;
}
-OSData *IODTNVRAM::unescapeBytesToData(const UInt8 *bytes, UInt32 length)
+OSData *IODTNVRAM::unescapeBytesToData(UInt8 *bytes, UInt32 length)
{
OSData *data = 0;
UInt32 totalLength = 0;
@@ -1404,29 +1148,29 @@
OSData * IODTNVRAM::escapeDataToData(OSData * value)
{
- OSData * result;
- const UInt8 * startPtr;
- const UInt8 * endPtr;
- const UInt8 * wherePtr;
- UInt8 byte;
- bool ok = true;
-
- wherePtr = (const UInt8 *) value->getBytesNoCopy();
- endPtr = wherePtr + value->getLength();
-
- result = OSData::withCapacity(endPtr - wherePtr);
+ OSData * result;
+ UInt8 * start;
+ UInt8 * end;
+ UInt8 * where;
+ UInt8 byte;
+ bool ok = true;
+
+ where = (UInt8 *) value->getBytesNoCopy();
+ end = where + value->getLength();
+
+ result = OSData::withCapacity(end - where);
if (!result)
return result;
- while (wherePtr < endPtr) {
- startPtr = wherePtr;
- byte = *wherePtr++;
+ while (where < end) {
+ start = where;
+ byte = *where++;
if ((byte == 0x00) || (byte == 0xFF)) {
for (;
- ((wherePtr - startPtr) < 0x80) && (wherePtr < endPtr) && (byte == *wherePtr);
- wherePtr++) {}
+ ((where - start) < 0x80) && (where < end) && (byte == *where);
+ where++) {}
ok &= result->appendByte(0xff, 1);
- byte = (byte & 0x80) | (wherePtr - startPtr);
+ byte = (byte & 0x80) | (where - start);
}
ok &= result->appendByte(byte, 1);
}
@@ -1440,77 +1184,51 @@
return result;
}
-static bool IsApplePropertyName(const char * propName)
-{
- char c;
- while ((c = *propName++)) {
- if ((c >= 'A') && (c <= 'Z'))
- break;
- }
-
- return (c == 0);
-}
-
IOReturn IODTNVRAM::readNVRAMPropertyType1(IORegistryEntry *entry,
const OSSymbol **name,
OSData **value)
{
- IOReturn err = kIOReturnNoResources;
- OSData *data;
- const UInt8 *startPtr;
- const UInt8 *endPtr;
- const UInt8 *wherePtr;
- const UInt8 *nvPath = 0;
- const char *nvName = 0;
- const char *resultName = 0;
- const UInt8 *resultValue = 0;
- UInt32 resultValueLen = 0;
- UInt8 byte;
+ IOReturn err = kIOReturnNoResources;
+ OSData *data;
+ UInt8 *start;
+ UInt8 *end;
+ UInt8 *where;
+ UInt8 *nvPath = 0;
+ UInt8 *nvName = 0;
+ UInt8 byte;
if (_ofDict == 0) return err;
data = OSDynamicCast(OSData, _ofDict->getObject(_registryPropertiesKey));
if (data == 0) return err;
- startPtr = (const UInt8 *) data->getBytesNoCopy();
- endPtr = startPtr + data->getLength();
-
- wherePtr = startPtr;
- while (wherePtr < endPtr) {
- byte = *(wherePtr++);
+ start = (UInt8 *) data->getBytesNoCopy();
+ end = start + data->getLength();
+
+ where = start;
+ while (where < end) {
+ byte = *(where++);
if (byte)
continue;
if (nvPath == 0)
- nvPath = startPtr;
+ nvPath = start;
else if (nvName == 0)
- nvName = (const char *) startPtr;
- else {
- IORegistryEntry * compareEntry = IORegistryEntry::fromPath((const char *) nvPath, gIODTPlane);
- if (compareEntry)
- compareEntry->release();
- if (entry == compareEntry) {
- bool appleProp = IsApplePropertyName(nvName);
- if (!appleProp || !resultName) {
- resultName = nvName;
- resultValue = startPtr;
- resultValueLen = wherePtr - startPtr - 1;
- }
- if (!appleProp)
- break;
- }
- nvPath = 0;
- nvName = 0;
- }
- startPtr = wherePtr;
- }
- if (resultName) {
- *name = OSSymbol::withCString(resultName);
- *value = unescapeBytesToData(resultValue, resultValueLen);
- if ((*name != 0) && (*value != 0))
- err = kIOReturnSuccess;
- else
- err = kIOReturnNoMemory;
- }
+ nvName = start;
+ else if (entry ==
+ IORegistryEntry::fromPath((const char *) nvPath, gIODTPlane)) {
+ *name = OSSymbol::withCString((const char *) nvName);
+ *value = unescapeBytesToData(start, where - start - 1);
+ if ((*name != 0) && (*value != 0))
+ err = kIOReturnSuccess;
+ else
+ err = kIOReturnNoMemory;
+ break;
+ } else
+ nvPath = nvName = 0;
+
+ start = where;
+ }
+
return err;
}
@@ -1518,60 +1236,49 @@
const OSSymbol *propName,
OSData *value)
{
- OSData *oldData;
- OSData *data = 0;
- const UInt8 *startPtr;
- const UInt8 *propStart;
- const UInt8 *endPtr;
- const UInt8 *wherePtr;
- const UInt8 *nvPath = 0;
- const char *nvName = 0;
+ OSData *oldData;
+ OSData *data = 0;
+ UInt8 *start;
+ UInt8 *propStart;
+ UInt8 *end;
+ UInt8 *where;
+ UInt8 *nvPath = 0;
+ UInt8 *nvName = 0;
const char * comp;
const char * name;
- UInt8 byte;
- bool ok = true;
- bool settingAppleProp;
+ UInt8 byte;
+ bool ok = true;
if (_ofDict == 0) return kIOReturnNoResources;
-
- settingAppleProp = IsApplePropertyName(propName->getCStringNoCopy());
// copy over existing properties for other entries
oldData = OSDynamicCast(OSData, _ofDict->getObject(_registryPropertiesKey));
if (oldData) {
- startPtr = (const UInt8 *) oldData->getBytesNoCopy();
- endPtr = startPtr + oldData->getLength();
-
- propStart = startPtr;
- wherePtr = startPtr;
- while (wherePtr < endPtr) {
- byte = *(wherePtr++);
+ start = (UInt8 *) oldData->getBytesNoCopy();
+ end = start + oldData->getLength();
+
+ propStart = start;
+ where = start;
+ while (where < end) {
+ byte = *(where++);
if (byte)
continue;
if (nvPath == 0)
- nvPath = startPtr;
+ nvPath = start;
else if (nvName == 0)
- nvName = (const char *) startPtr;
- else {
- IORegistryEntry * compareEntry = IORegistryEntry::fromPath((const char *) nvPath, gIODTPlane);
- if (compareEntry)
- compareEntry->release();
- if (entry == compareEntry) {
- if ((settingAppleProp && propName->isEqualTo(nvName))
- || (!settingAppleProp && !IsApplePropertyName(nvName))) {
- // delete old property (nvPath -> wherePtr)
- data = OSData::withBytes(propStart, nvPath - propStart);
- if (data)
- ok &= data->appendBytes(wherePtr, endPtr - wherePtr);
- break;
- }
- }
- nvPath = 0;
- nvName = 0;
- }
+ nvName = start;
+ else if (entry ==
+ IORegistryEntry::fromPath((const char *) nvPath, gIODTPlane)) {
+ // delete old property (nvPath -> where)
+ data = OSData::withBytes(propStart, nvPath - propStart);
+ if (data)
+ ok &= data->appendBytes(where, end - where);
+ break;
+ } else
+ nvPath = nvName = 0;
- startPtr = wherePtr;
+ start = where;
}
}
@@ -1586,52 +1293,51 @@
return kIOReturnNoMemory;
}
- if (value && value->getLength()) {
- // get entries in path
- OSArray *array = OSArray::withCapacity(5);
- if (!array) {
- data->release();
- return kIOReturnNoMemory;
- }
- do
- array->setObject(entry);
- while ((entry = entry->getParentEntry(gIODTPlane)));
-
- // append path
- for (int i = array->getCount() - 3;
- (entry = (IORegistryEntry *) array->getObject(i));
- i--) {
-
- name = entry->getName(gIODTPlane);
- comp = entry->getLocation(gIODTPlane);
- if( comp && (0 == strcmp("pci", name))
- && (0 == strcmp("80000000", comp))) {
- // yosemite hack
- comp = "/pci@80000000";
- } else {
- if (comp)
- ok &= data->appendBytes("/@", 2);
- else {
- if (!name)
- continue;
- ok &= data->appendByte('/', 1);
- comp = name;
- }
- }
- ok &= data->appendBytes(comp, strlen(comp));
- }
- ok &= data->appendByte(0, 1);
- array->release();
-
- // append prop name
- ok &= data->appendBytes(propName->getCStringNoCopy(), propName->getLength() + 1);
-
- // append escaped data
- oldData = escapeDataToData(value);
- ok &= (oldData != 0);
- if (ok)
- ok &= data->appendBytes(oldData);
- }
+ // get entries in path
+ OSArray *array = OSArray::withCapacity(5);
+ if (!array) {
+ data->release();
+ return kIOReturnNoMemory;
+ }
+ do
+ array->setObject(entry);
+ while ((entry = entry->getParentEntry(gIODTPlane)));
+
+ // append path
+ for (int i = array->getCount() - 3;
+ (entry = (IORegistryEntry *) array->getObject(i));
+ i--) {
+
+ name = entry->getName(gIODTPlane);
+ comp = entry->getLocation(gIODTPlane);
+ if( comp && (0 == strcmp("pci", name))
+ && (0 == strcmp("80000000", comp))) {
+ // yosemite hack
+ comp = "/pci@80000000";
+ } else {
+ if (comp)
+ ok &= data->appendBytes("/@", 2);
+ else {
+ if (!name)
+ continue;
+ ok &= data->appendByte('/', 1);
+ comp = name;
+ }
+ }
+ ok &= data->appendBytes(comp, strlen(comp));
+ }
+ ok &= data->appendByte(0, 1);
+ array->release();
+
+ // append prop name
+ ok &= data->appendBytes(propName->getCStringNoCopy(), propName->getLength() + 1);
+
+ // append escaped data
+ oldData = escapeDataToData(value);
+ ok &= (oldData != 0);
+ if (ok)
+ ok &= data->appendBytes(oldData);
+
if (ok) {
ok = _ofDict->setObject(_registryPropertiesKey, data);
if (ok)