Loading...
iokit/Kernel/IONVRAM.cpp xnu-1699.32.7 xnu-1228
--- xnu/xnu-1699.32.7/iokit/Kernel/IONVRAM.cpp
+++ xnu/xnu-1228/iokit/Kernel/IONVRAM.cpp
@@ -31,13 +31,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);
 
@@ -204,9 +203,6 @@
     _piImage = _nvramImage + _piPartitionOffset;
   }
   
-  _lastDeviceSync = 0;
-  _freshInterval = TRUE;		// we will allow sync() even before the first 15 minutes have passed.
-
   initOFVariables();
 }
 
@@ -225,23 +221,20 @@
 
 bool IODTNVRAM::serializeProperties(OSSerialize *s) const
 {
-  bool                 result, hasPrivilege;
+  bool                 result;
   UInt32               variablePerm;
   const OSSymbol       *key;
-  OSDictionary         *dict = 0, *tmpDict = 0;
+  OSDictionary         *dict, *tmpDict = 0;
   OSCollectionIterator *iter = 0;
   
+  if (_ofDict == 0) return false;
+  
   // Verify permissions.
-  hasPrivilege = (kIOReturnSuccess == IOUserClient::clientHasPrivilege(current_task(), kIONVRAMPrivilege));
-
-  tmpDict = OSDictionary::withCapacity(1);
-  if (tmpDict == 0) return false;
-
-  if (_ofDict == 0) {
-    /* No nvram. Return an empty dictionary. */
-    dict = tmpDict;
-  } 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) return false;
     
@@ -250,14 +243,15 @@
       if (key == 0) break;
       
       variablePerm = getOFVariablePerm(key);
-      if ((hasPrivilege || (variablePerm != kOFVariablePermRootOnly)) &&
-	  ( ! (variablePerm == kOFVariablePermKernelOnly && current_task() != kernel_task) )) {
+      if (variablePerm != kOFVariablePermRootOnly) {
 	tmpDict->setObject(key, _ofDict->getObject(key));
       }
-      dict = tmpDict;
-    }
-  }
-
+    }
+    dict = tmpDict;
+  } else {
+    dict = _ofDict;
+  }
+  
   result = dict->serialize(s);
   
   if (tmpDict != 0) tmpDict->release();
@@ -274,12 +268,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);
 }
@@ -308,13 +301,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;
@@ -373,12 +365,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;
@@ -418,32 +409,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();
@@ -571,7 +548,7 @@
   return kIOReturnSuccess;
 }
 
-IOByteCount IODTNVRAM::savePanicInfo(UInt8 *buffer, IOByteCount length)
+UInt32 IODTNVRAM::savePanicInfo(UInt8 *buffer, IOByteCount length)
 {
   if ((_piImage == 0) || (length <= 0)) return 0;
   
@@ -947,10 +924,6 @@
   {"security-mode", kOFVariableTypeString, kOFVariablePermUserRead, -1},
   {"security-password", kOFVariableTypeData, kOFVariablePermRootOnly, -1},
   {"boot-image", kOFVariableTypeData, kOFVariablePermUserWrite, -1},
-  {"com.apple.System.fp-state", kOFVariableTypeData, kOFVariablePermKernelOnly, -1},
-#if CONFIG_EMBEDDED
-  {"backlight-level", kOFVariableTypeData, kOFVariablePermUserWrite, -1},
-#endif
   {0, kOFVariableTypeData, kOFVariablePermUserRead, -1}
 };
 
@@ -1137,9 +1110,9 @@
     if (tmpValue == 0xFFFFFFFF) {
       strlcpy((char *)buffer, "-1", *length - propNameLength);
     } else if (tmpValue < 1000) {
-      snprintf((char *)buffer, *length - propNameLength, "%d", (uint32_t)tmpValue);
+      snprintf((char *)buffer, *length - propNameLength, "%ld", tmpValue);
     } else {
-      snprintf((char *)buffer, *length - propNameLength, "0x%x", (uint32_t)tmpValue);
+      snprintf((char *)buffer, *length - propNameLength, "0x%lx", tmpValue);
     }
     break;
     
@@ -1264,6 +1237,7 @@
   kMaxNVDataLength = 8
 };
 
+#pragma options align=mac68k
 struct NVRAMProperty
 {
   IONVRAMDescriptor   header;
@@ -1272,6 +1246,7 @@
   UInt8               dataLength;
   UInt8               data[ kMaxNVDataLength ];
 };
+#pragma options align=reset
 
 bool IODTNVRAM::searchNVRAMProperty(IONVRAMDescriptor *hdr, UInt32 *where)
 {
@@ -1676,26 +1651,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;
-}