- OWVariablesHeader *owHeader, *owHeaderOld;
-
- if ((_ofImage == 0) || (_ofDict == 0)) return kIOReturnNotReady;
-
- if (!_ofImageDirty) return kIOReturnSuccess;
-
- if (getPlatform()->getBootROMType()) {
- buffer = tmpBuffer = IONew(UInt8, _ofPartitionSize);
- if (buffer == 0) return kIOReturnNoMemory;
- bzero(buffer, _ofPartitionSize);
-
- ok = true;
- maxLength = _ofPartitionSize;
-
- iter = OSCollectionIterator::withCollection(_ofDict);
- if (iter == 0) ok = false;
-
- while (ok) {
- tmpSymbol = OSDynamicCast(OSSymbol, iter->getNextObject());
- if (tmpSymbol == 0) break;
-
- tmpObject = _ofDict->getObject(tmpSymbol);
-
- length = maxLength;
- ok = convertObjectToProp(tmpBuffer, &length, tmpSymbol, tmpObject);
- if (ok) {
- tmpBuffer += length;
- maxLength -= length;
- }
- }
- iter->release();
-
- if (ok) {
- bcopy(buffer, _ofImage, _ofPartitionSize);
- }
-
- IODelete(buffer, UInt8, _ofPartitionSize);
-
- if (!ok) return kIOReturnBadArgument;
- } else {
- buffer = IONew(UInt8, _ofPartitionSize);
- if (buffer == 0) return kIOReturnNoMemory;
- bzero(buffer, _ofPartitionSize);
-
- owHeader = (OWVariablesHeader *)buffer;
- owHeaderOld = (OWVariablesHeader *)_ofImage;
-
- owHeader->owMagic = owHeaderOld->owMagic;
- owHeader->owVersion = owHeaderOld->owVersion;
- owHeader->owPages = owHeaderOld->owPages;
-
- curOffset = _ofPartitionSize;
-
- ok = true;
- cnt = 0;
- while (ok) {
- if (!getOWVariableInfo(cnt++, &tmpSymbol, &tmpType, &tmpOffset))
- break;
-
- tmpObject = _ofDict->getObject(tmpSymbol);
-
- switch (tmpType) {
- case kOFVariableTypeBoolean :
- tmpBoolean = OSDynamicCast(OSBoolean, tmpObject);
- if (tmpBoolean->getValue()) owHeader->owFlags |= tmpOffset;
- break;
-
- case kOFVariableTypeNumber :
- tmpNumber = OSDynamicCast(OSNumber, tmpObject);
- owHeader->owNumbers[tmpOffset] = tmpNumber->unsigned32BitValue();
- break;
-
- case kOFVariableTypeString :
- tmpString = OSDynamicCast(OSString, tmpObject);
- tmpData = (UInt8 *) tmpString->getCStringNoCopy();
- tmpDataLength = tmpString->getLength();
-
- if ((curOffset - tmpDataLength) < sizeof(OWVariablesHeader)) {
- ok = false;
- break;
- }
-
- owHeader->owStrings[tmpOffset].length = tmpDataLength;
- curOffset -= tmpDataLength;
- owHeader->owStrings[tmpOffset].offset = curOffset + _ofPartitionOffset;
- if (tmpDataLength != 0)
- bcopy(tmpData, buffer + curOffset, tmpDataLength);
- break;
- }
- }
-
+
+ IOLockAssert(_ofLock, kIOLockAssertOwned);
+
+ if ((_ofImage == 0) || (_ofDict == 0) || _systemPaniced) return kIOReturnNotReady;
+
+ buffer = tmpBuffer = IONew(UInt8, _ofPartitionSize);
+ if (buffer == 0) return kIOReturnNoMemory;
+ bzero(buffer, _ofPartitionSize);
+
+ ok = true;
+ maxLength = _ofPartitionSize;
+
+ iter = OSCollectionIterator::withCollection(_ofDict);
+ if (iter == 0) ok = false;
+
+ 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);
+
+ length = maxLength;
+ ok = convertObjectToProp(tmpBuffer, &length, tmpSymbol, tmpObject);