Loading...
--- xnu/xnu-2422.100.13/iokit/Kernel/IONVRAM.cpp
+++ xnu/xnu-792.2.4/iokit/Kernel/IONVRAM.cpp
@@ -1,30 +1,23 @@
/*
- * 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@
*
- * 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.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * 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
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. 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 +25,12 @@
#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 +56,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 +108,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 +197,6 @@
_piImage = _nvramImage + _piPartitionOffset;
}
- _lastDeviceSync = 0;
- _freshInterval = TRUE; // we will allow sync() even before the first 15 minutes have passed.
-
initOFVariables();
}
@@ -257,9 +207,6 @@
// 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();
@@ -268,42 +215,40 @@
bool IODTNVRAM::serializeProperties(OSSerialize *s) const
{
- bool result, hasPrivilege;
+ 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(), kIONVRAMPrivilege);
+ 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));
+ if (variablePerm != kOFVariablePermRootOnly) {
+ tmpDict->setObject(key, _ofDict->getObject(key));
}
}
- }
-
+ dict = tmpDict;
+ } else {
+ dict = _ofDict;
+ }
+
result = dict->serialize(s);
-
- dict->release();
+
+ if (tmpDict != 0) tmpDict->release();
if (iter != 0) iter->release();
return result;
@@ -317,12 +262,11 @@
if (_ofDict == 0) return 0;
// Verify permissions.
- variablePerm = getOFVariablePerm(aKey);
result = IOUserClient::clientHasPrivilege(current_task(), kIONVRAMPrivilege);
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 +295,12 @@
if (_ofDict == 0) return false;
// Verify permissions.
- propPerm = getOFVariablePerm(aKey);
result = IOUserClient::clientHasPrivilege(current_task(), kIONVRAMPrivilege);
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;
@@ -416,12 +359,11 @@
if (_ofDict == 0) return;
// Verify permissions.
- propPerm = getOFVariablePerm(aKey);
result = IOUserClient::clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator);
if (result != kIOReturnSuccess) {
+ propPerm = getOFVariablePerm(aKey);
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;
@@ -461,32 +403,18 @@
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);
- }
-
+ 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);
+ }
}
iter->release();
@@ -614,7 +542,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 +556,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 +656,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();
@@ -990,7 +912,6 @@
{"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}
};
@@ -1161,30 +1082,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 :
@@ -1277,8 +1199,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 +1227,7 @@
kMaxNVDataLength = 8
};
+#pragma options align=mac68k
struct NVRAMProperty
{
IONVRAMDescriptor header;
@@ -1312,6 +1236,7 @@
UInt8 dataLength;
UInt8 data[ kMaxNVDataLength ];
};
+#pragma options align=reset
bool IODTNVRAM::searchNVRAMProperty(IONVRAMDescriptor *hdr, UInt32 *where)
{
@@ -1679,8 +1604,8 @@
name = entry->getName(gIODTPlane);
comp = entry->getLocation(gIODTPlane);
- if( comp && (0 == strncmp("pci", name, sizeof("pci")))
- && (0 == strncmp("80000000", comp, sizeof("80000000")))) {
+ if( comp && (0 == strcmp("pci", name))
+ && (0 == strcmp("80000000", comp))) {
// yosemite hack
comp = "/pci@80000000";
} else {
@@ -1716,26 +1641,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;
-}