Loading...
--- xnu/xnu-2422.100.13/iokit/Kernel/IONVRAM.cpp
+++ xnu/xnu-517/iokit/Kernel/IONVRAM.cpp
@@ -1,20 +1,16 @@
/*
- * Copyright (c) 1998-2006 Apple Computer, Inc. All rights reserved.
- * Copyright (c) 2007-2012 Apple Inc. All rights reserved.
+ * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
*
- * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. The rights granted to you under the License
- * may not be used to create, or enable the creation or redistribution of,
- * unlawful or unlicensed copies of an Apple operating system, or to
- * circumvent, violate, or enable the circumvention or violation of, any
- * terms of an Apple operating system software license agreement.
- *
- * Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
@@ -24,7 +20,7 @@
* Please see the License for the specific language governing rights and
* limitations under the License.
*
- * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ * @APPLE_LICENSE_HEADER_END@
*/
#include <IOKit/IOLib.h>
@@ -32,13 +28,8 @@
#include <IOKit/IOPlatformExpert.h>
#include <IOKit/IOUserClient.h>
#include <IOKit/IOKitKeys.h>
-#include <kern/debug.h>
-#include <pexpert/pexpert.h>
#define super IOService
-
-#define kIONVRAMPrivilege kIOClientPrivilegeAdministrator
-//#define kIONVRAMPrivilege kIOClientPrivilegeLocalUser
OSDefineMetaClassAndStructors(IODTNVRAM, IOService);
@@ -64,61 +55,22 @@
_registryPropertiesKey = OSSymbol::withCStringNoCopy("aapl,pci");
if (_registryPropertiesKey == 0) return false;
- // <rdar://problem/9529235> race condition possible between
- // IODTNVRAM and IONVRAMController (restore loses boot-args)
- initProxyData();
-
return true;
}
-void IODTNVRAM::initProxyData(void)
-{
- IORegistryEntry *entry;
- const char *key = "nvram-proxy-data";
- OSObject *prop;
- OSData *data;
- const void *bytes;
-
- entry = IORegistryEntry::fromPath("/chosen", gIODTPlane);
- if (entry != 0) {
- prop = entry->getProperty(key);
- if (prop != 0) {
- data = OSDynamicCast(OSData, prop);
- if (data != 0) {
- bytes = data->getBytesNoCopy();
- if (bytes != 0) {
- bcopy(bytes, _nvramImage, data->getLength());
- initNVRAMImage();
- _isProxied = true;
- }
- }
- }
- entry->removeProperty(key);
- entry->release();
- }
-}
-
void IODTNVRAM::registerNVRAMController(IONVRAMController *nvram)
-{
- if (_nvramController != 0) return;
-
- _nvramController = nvram;
-
- // <rdar://problem/9529235> race condition possible between
- // IODTNVRAM and IONVRAMController (restore loses boot-args)
- if (!_isProxied) {
- _nvramController->read(0, _nvramImage, kIODTNVRAMImageSize);
- initNVRAMImage();
- }
-}
-
-void IODTNVRAM::initNVRAMImage(void)
{
char partitionID[18];
UInt32 partitionOffset, partitionLength;
UInt32 freePartitionOffset, freePartitionSize;
UInt32 currentLength, currentOffset = 0;
OSNumber *partitionOffsetNumber, *partitionLengthNumber;
+
+ if (_nvramController != 0) return;
+
+ _nvramController = nvram;
+
+ _nvramController->read(0, _nvramImage, kIODTNVRAMImageSize);
// Find the offsets for the OF, XPRAM, NameRegistry and PanicInfo partitions.
_ofPartitionOffset = 0xFFFFFFFF;
@@ -155,7 +107,7 @@
freePartitionSize = currentLength;
} else {
// Construct the partition ID from the signature and name.
- snprintf(partitionID, sizeof(partitionID), "0x%02x,",
+ sprintf(partitionID, "0x%02x,",
*(UInt8 *)(_nvramImage + currentOffset));
strncpy(partitionID + 5,
(const char *)(_nvramImage + currentOffset + 4), 12);
@@ -244,9 +196,6 @@
_piImage = _nvramImage + _piPartitionOffset;
}
- _lastDeviceSync = 0;
- _freshInterval = TRUE; // we will allow sync() even before the first 15 minutes have passed.
-
initOFVariables();
}
@@ -257,53 +206,48 @@
// Don't try to sync OF Variables if the system has already paniced.
if (!_systemPaniced) syncOFVariables();
- // Don't try to perform controller operations if none has been registered.
- if (_nvramController == 0) return;
-
_nvramController->write(0, _nvramImage, kIODTNVRAMImageSize);
_nvramController->sync();
_nvramImageDirty = false;
}
-bool IODTNVRAM::serializeProperties(OSSerialize *s) const
-{
- bool result, hasPrivilege;
+bool IODTNVRAM::serializeProperties(OSSerialize *serialize) const
+{
+ bool result;
UInt32 variablePerm;
const OSSymbol *key;
- OSDictionary *dict;
+ OSDictionary *dict, *tmpDict = 0;
OSCollectionIterator *iter = 0;
+ if (_ofDict == 0) return false;
+
// Verify permissions.
- hasPrivilege = (kIOReturnSuccess == IOUserClient::clientHasPrivilege(current_task(), kIONVRAMPrivilege));
-
- dict = OSDictionary::withCapacity(1);
- if (dict == 0) return false;
-
- if (_ofDict == 0) {
- /* No nvram. Return an empty dictionary. */
- } else {
- /* Copy properties with client privilege. */
+ result = IOUserClient::clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator);
+ if (result != kIOReturnSuccess) {
+ tmpDict = OSDictionary::withCapacity(1);
+ if (tmpDict == 0) return false;
+
iter = OSCollectionIterator::withCollection(_ofDict);
- if (iter == 0) {
- dict->release();
- return false;
- }
+ if (iter == 0) return false;
+
while (1) {
key = OSDynamicCast(OSSymbol, iter->getNextObject());
if (key == 0) break;
variablePerm = getOFVariablePerm(key);
- if ((hasPrivilege || (variablePerm != kOFVariablePermRootOnly)) &&
- ( ! (variablePerm == kOFVariablePermKernelOnly && current_task() != kernel_task) )) {
- dict->setObject(key, _ofDict->getObject(key));
- }
- }
- }
-
- result = dict->serialize(s);
-
- dict->release();
+ if (variablePerm != kOFVariablePermRootOnly) {
+ tmpDict->setObject(key, _ofDict->getObject(key));
+ }
+ }
+ dict = tmpDict;
+ } else {
+ dict = _ofDict;
+ }
+
+ result = dict->serialize(serialize);
+
+ if (tmpDict != 0) tmpDict->release();
if (iter != 0) iter->release();
return result;
@@ -317,12 +261,11 @@
if (_ofDict == 0) return 0;
// Verify permissions.
- variablePerm = getOFVariablePerm(aKey);
- result = IOUserClient::clientHasPrivilege(current_task(), kIONVRAMPrivilege);
+ result = IOUserClient::clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator);
if (result != kIOReturnSuccess) {
+ variablePerm = getOFVariablePerm(aKey);
if (variablePerm == kOFVariablePermRootOnly) return 0;
}
- if (variablePerm == kOFVariablePermKernelOnly && current_task() != kernel_task) return 0;
return _ofDict->getObject(aKey);
}
@@ -351,13 +294,12 @@
if (_ofDict == 0) return false;
// Verify permissions.
- propPerm = getOFVariablePerm(aKey);
- result = IOUserClient::clientHasPrivilege(current_task(), kIONVRAMPrivilege);
+ result = IOUserClient::clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator);
if (result != kIOReturnSuccess) {
+ propPerm = getOFVariablePerm(aKey);
if (propPerm != kOFVariablePermUserWrite) return false;
}
- if (propPerm == kOFVariablePermKernelOnly && current_task() != kernel_task) return 0;
-
+
// Don't allow creation of new properties on old world machines.
if (getPlatform()->getBootROMType() == 0) {
if (_ofDict->getObject(aKey) == 0) return false;
@@ -408,42 +350,11 @@
return result;
}
-void IODTNVRAM::removeProperty(const OSSymbol *aKey)
-{
- bool result;
- UInt32 propPerm;
-
- if (_ofDict == 0) return;
-
- // Verify permissions.
- propPerm = getOFVariablePerm(aKey);
- result = IOUserClient::clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator);
- if (result != kIOReturnSuccess) {
- if (propPerm != kOFVariablePermUserWrite) return;
- }
- if (propPerm == kOFVariablePermKernelOnly && current_task() != kernel_task) 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;
@@ -460,33 +371,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 if(key->isEqualTo(kIONVRAMSyncNowPropertyKey)) {
- tmpStr = OSDynamicCast(OSString, object);
- if (tmpStr != 0) {
-
- result = true; // We are not going to gaurantee sync, this is best effort
-
- if(safeToSync())
- sync();
-
- } else {
- result = false;
- }
- }
- else {
- result = setProperty(key, object);
- }
-
+ result = setProperty(key, object);
}
iter->release();
@@ -500,7 +385,7 @@
{
if (_xpramImage == 0) return kIOReturnUnsupported;
- if ((buffer == 0) || (length == 0) ||
+ if ((buffer == 0) || (length <= 0) || (offset < 0) ||
(offset + length > kIODTNVRAMXPRAMSize))
return kIOReturnBadArgument;
@@ -514,7 +399,7 @@
{
if (_xpramImage == 0) return kIOReturnUnsupported;
- if ((buffer == 0) || (length == 0) ||
+ if ((buffer == 0) || (length <= 0) || (offset < 0) ||
(offset + length > kIODTNVRAMXPRAMSize))
return kIOReturnBadArgument;
@@ -576,7 +461,7 @@
partitionOffset = partitionOffsetNumber->unsigned32BitValue();
partitionLength = partitionLengthNumber->unsigned32BitValue();
- if ((buffer == 0) || (length == 0) ||
+ if ((buffer == 0) || (length <= 0) || (offset < 0) ||
(offset + length > partitionLength))
return kIOReturnBadArgument;
@@ -603,7 +488,7 @@
partitionOffset = partitionOffsetNumber->unsigned32BitValue();
partitionLength = partitionLengthNumber->unsigned32BitValue();
- if ((buffer == 0) || (length == 0) ||
+ if ((buffer == 0) || (length <= 0) || (offset < 0) ||
(offset + length > partitionLength))
return kIOReturnBadArgument;
@@ -614,7 +499,7 @@
return kIOReturnSuccess;
}
-IOByteCount IODTNVRAM::savePanicInfo(UInt8 *buffer, IOByteCount length)
+UInt32 IODTNVRAM::savePanicInfo(UInt8 *buffer, IOByteCount length)
{
if ((_piImage == 0) || (length <= 0)) return 0;
@@ -628,15 +513,9 @@
*(UInt32 *)_piImage = length;
_nvramImageDirty = true;
- /*
- * This prevents OF variables from being committed if the system has panicked
- */
+
_systemPaniced = true;
- /* The call to sync() forces the NVRAM controller to write the panic info
- * partition to NVRAM.
- */
- sync();
-
+
return length;
}
@@ -734,7 +613,7 @@
// Create the 'aapl,panic-info' property if needed.
if (_piImage != 0) {
propDataLength = *(UInt32 *)_piImage;
- if ((propDataLength != 0) && (propDataLength <= (_piPartitionSize - 4))) {
+ if ((propDataLength != 0) && (propDataLength < (_piPartitionSize - 4))) {
propObject = OSData::withBytes(_piImage + 4, propDataLength);
_ofDict->setObject(kIODTNVRAMPanicInfoKey, propObject);
propObject->release();
@@ -806,8 +685,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;
@@ -891,7 +769,7 @@
case kOFVariableTypeString :
tmpString = OSDynamicCast(OSString, tmpObject);
- tmpData = (const UInt8 *)tmpString->getCStringNoCopy();
+ tmpData = (UInt8 *) tmpString->getCStringNoCopy();
tmpDataLength = tmpString->getLength();
if ((curOffset - tmpDataLength) < sizeof(OWVariablesHeader)) {
@@ -931,10 +809,10 @@
}
struct OFVariable {
- const char *variableName;
- UInt32 variableType;
- UInt32 variablePerm;
- SInt32 variableOffset;
+ char *variableName;
+ UInt32 variableType;
+ UInt32 variablePerm;
+ SInt32 variableOffset;
};
typedef struct OFVariable OFVariable;
@@ -989,8 +867,6 @@
{"aapl,pci", kOFVariableTypeData, kOFVariablePermRootOnly, -1},
{"security-mode", kOFVariableTypeString, kOFVariablePermUserRead, -1},
{"security-password", kOFVariableTypeData, kOFVariablePermRootOnly, -1},
- {"boot-image", kOFVariableTypeData, kOFVariablePermUserWrite, -1},
- {"com.apple.System.fp-state", kOFVariableTypeData, kOFVariablePermKernelOnly, -1},
{0, kOFVariableTypeData, kOFVariablePermUserRead, -1}
};
@@ -1117,7 +993,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;
@@ -1125,7 +1001,7 @@
OSString *tmpString = 0;
OSData *tmpData = 0;
- propName = (const UInt8 *)propSymbol->getCStringNoCopy();
+ propName = (UInt8 *)propSymbol->getCStringNoCopy();
propNameLength = propSymbol->getLength();
propType = getOFVariableType(propSymbol);
@@ -1161,30 +1037,31 @@
if ((propNameLength + propDataLength + 2) > *length) return false;
// Copy the property name equal sign.
- buffer += snprintf((char *)buffer, *length, "%s=", propName);
+ sprintf((char *)buffer, "%s=", propName);
+ buffer += propNameLength + 1;
switch (propType) {
case kOFVariableTypeBoolean :
if (tmpBoolean->getValue()) {
- strlcpy((char *)buffer, "true", *length - propNameLength);
+ strcpy((char *)buffer, "true");
} else {
- strlcpy((char *)buffer, "false", *length - propNameLength);
+ strcpy((char *)buffer, "false");
}
break;
case kOFVariableTypeNumber :
tmpValue = tmpNumber->unsigned32BitValue();
if (tmpValue == 0xFFFFFFFF) {
- strlcpy((char *)buffer, "-1", *length - propNameLength);
+ strcpy((char *)buffer, "-1");
} else if (tmpValue < 1000) {
- snprintf((char *)buffer, *length - propNameLength, "%d", (uint32_t)tmpValue);
+ sprintf((char *)buffer, "%ld", tmpValue);
} else {
- snprintf((char *)buffer, *length - propNameLength, "0x%x", (uint32_t)tmpValue);
+ sprintf((char *)buffer, "0x%lx", tmpValue);
}
break;
case kOFVariableTypeString :
- strlcpy((char *)buffer, tmpString->getCStringNoCopy(), *length - propNameLength);
+ strcpy((char *)buffer, tmpString->getCStringNoCopy());
break;
case kOFVariableTypeData :
@@ -1229,12 +1106,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;
@@ -1249,7 +1125,7 @@
if (bootCommand == 0) return;
} else return;
- bootCommandData = (const UInt8 *)bootCommand->getCStringNoCopy();
+ bootCommandData = (UInt8 *)bootCommand->getCStringNoCopy();
bootCommandDataLength = bootCommand->getLength();
if (bootCommandData == 0) return;
@@ -1269,7 +1145,7 @@
}
if (wasBootArgs) {
- bootArgsData = (const UInt8 *)bootArgs->getCStringNoCopy();
+ bootArgsData = (UInt8 *)bootArgs->getCStringNoCopy();
bootArgsDataLength = bootArgs->getLength();
if (bootArgsData == 0) return;
@@ -1277,8 +1153,9 @@
tmpData = IONew(UInt8, tmpDataLength + 1);
if (tmpData == 0) return;
- cnt -= strlcpy((char *)tmpData, (const char *)bootCommandData, cnt);
- strlcat((char *)tmpData, (const char *)bootArgsData, cnt);
+ strncpy((char *)tmpData, (const char *)bootCommandData, cnt);
+ tmpData[cnt] = '\0';
+ strcat((char *)tmpData, (const char *)bootArgsData);
bootCommand = OSString::withCString((const char *)tmpData);
if (bootCommand != 0) {
@@ -1304,6 +1181,7 @@
kMaxNVDataLength = 8
};
+#pragma options align=mac68k
struct NVRAMProperty
{
IONVRAMDescriptor header;
@@ -1312,6 +1190,7 @@
UInt8 dataLength;
UInt8 data[ kMaxNVDataLength ];
};
+#pragma options align=reset
bool IODTNVRAM::searchNVRAMProperty(IONVRAMDescriptor *hdr, UInt32 *where)
{
@@ -1432,7 +1311,7 @@
return err;
}
-OSData *IODTNVRAM::unescapeBytesToData(const UInt8 *bytes, UInt32 length)
+OSData *IODTNVRAM::unescapeBytesToData(UInt8 *bytes, UInt32 length)
{
OSData *data = 0;
UInt32 totalLength = 0;
@@ -1479,29 +1358,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);
}
@@ -1515,77 +1394,56 @@
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;
+ nvName = start;
else {
IORegistryEntry * compareEntry = IORegistryEntry::fromPath((const char *) nvPath, gIODTPlane);
+ if (entry == compareEntry) {
+ if (compareEntry)
+ compareEntry->release();
+ *name = OSSymbol::withCString((const char *) nvName);
+ *value = unescapeBytesToData(start, where - start - 1);
+ if ((*name != 0) && (*value != 0))
+ err = kIOReturnSuccess;
+ else
+ err = kIOReturnNoMemory;
+ break;
+ }
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;
- }
+ nvPath = nvName = 0;
+ }
+ start = where;
+ }
+
return err;
}
@@ -1593,60 +1451,55 @@
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;
+ nvName = start;
else {
IORegistryEntry * compareEntry = IORegistryEntry::fromPath((const char *) nvPath, gIODTPlane);
+ if (entry == compareEntry) {
+ if (compareEntry)
+ compareEntry->release();
+ // delete old property (nvPath -> where)
+ data = OSData::withBytes(propStart, nvPath - propStart);
+ if (data)
+ ok &= data->appendBytes(where, end - where);
+ break;
+ }
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;
+ nvPath = nvName = 0;
}
- startPtr = wherePtr;
+ start = where;
}
}
@@ -1661,52 +1514,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 == strncmp("pci", name, sizeof("pci")))
- && (0 == strncmp("80000000", comp, sizeof("80000000")))) {
- // 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)
@@ -1716,26 +1568,3 @@
return ok ? kIOReturnSuccess : kIOReturnNoMemory;
}
-
-bool IODTNVRAM::safeToSync(void)
-{
- AbsoluteTime delta;
- UInt64 delta_ns;
- SInt32 delta_secs;
-
- // delta interval went by
- clock_get_uptime(&delta);
-
- // Figure it in seconds.
- absolutetime_to_nanoseconds(delta, &delta_ns);
- delta_secs = (SInt32)(delta_ns / NSEC_PER_SEC);
-
- if ((delta_secs > (_lastDeviceSync + MIN_SYNC_NOW_INTERVAL)) || _freshInterval)
- {
- _lastDeviceSync = delta_secs;
- _freshInterval = FALSE;
- return TRUE;
- }
-
- return FALSE;
-}