]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/RootDomainUserClient.cpp
xnu-2422.100.13.tar.gz
[apple/xnu.git] / iokit / Kernel / RootDomainUserClient.cpp
index 92097acdef15cfb9790aa6f2b90c456084bbd165..cfc365b5149d9dfdce99a6fab6c0b6316f5c93af 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1998-2012 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -36,6 +36,8 @@
 #include <IOKit/IOBufferMemoryDescriptor.h>
 #include "RootDomainUserClient.h"
 #include <IOKit/pwr_mgt/IOPMLibDefs.h>
+#include <IOKit/pwr_mgt/IOPMPrivate.h>
+#include <sys/proc.h>
 
 #define super IOUserClient
 
@@ -78,7 +80,7 @@ IOReturn RootDomainUserClient::secureSleepSystem( uint32_t *return_code )
 
 IOReturn RootDomainUserClient::secureSleepSystemOptions( 
     const void      *inOptions, 
-    IOByteCount     inOptionsSize __unused,
+    IOByteCount     inOptionsSize,
     uint32_t        *returnCode)
 {
 
@@ -98,7 +100,7 @@ IOReturn RootDomainUserClient::secureSleepSystemOptions(
     if (inOptions)
     {
         unserializedOptions = OSDynamicCast( OSDictionary,
-                                             OSUnserializeXML((const char *)inOptions, &unserializeErrorString));
+                                             OSUnserializeXML((const char *)inOptions, inOptionsSize, &unserializeErrorString));
     
         if (!unserializedOptions) {
             IOLog("IOPMRootDomain SleepSystem unserialization failure: %s\n", 
@@ -106,9 +108,14 @@ IOReturn RootDomainUserClient::secureSleepSystemOptions(
         }
     }
 
-    if ( (local_priv || admin_priv) 
-          && fOwner ) 
+    if ( (local_priv || admin_priv) && fOwner )
     {
+        proc_t p;
+        p = (proc_t)get_bsdtask_info(fOwningTask);
+        if (p) {
+            fOwner->setProperty("SleepRequestedByPID", proc_pid(p), 32);
+        }
+        
         if (unserializedOptions) 
         {
             // Publish Sleep Options in registry under root_domain
@@ -190,6 +197,23 @@ IOReturn RootDomainUserClient::secureSetUserAssertionLevels(
     return kIOReturnSuccess;
 }
 
+IOReturn RootDomainUserClient::secureGetSystemSleepType(
+    uint32_t    *outSleepType)
+{
+    int                     admin_priv = 0;
+    IOReturn                ret;
+
+    ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
+    admin_priv = (kIOReturnSuccess == ret);
+
+    if (admin_priv && fOwner) {
+        ret = fOwner->getSystemSleepType(outSleepType);
+    } else {
+        ret = kIOReturnNotPrivileged;
+    }
+    return ret;
+}
+
 IOReturn RootDomainUserClient::clientClose( void )
 {
     detach(fOwner);
@@ -310,10 +334,48 @@ IOReturn RootDomainUserClient::externalMethod(
             break;
             
         case kPMActivityTickle:
-            fOwner->reportUserInput( );
+            if ( fOwner->checkSystemCanSustainFullWake() )
+            {
+               fOwner->reportUserInput( );
+               fOwner->setProperty(kIOPMRootDomainWakeTypeKey, "UserActivity Assertion");
+            }
             ret = kIOReturnSuccess;
             break;
-            
+
+        case kPMSetClamshellSleepState:
+            fOwner->setDisableClamShellSleep(arguments->scalarInput[0] ? true : false);
+            ret = kIOReturnSuccess;
+            break;
+
+        case kPMGetSystemSleepType:
+            if (1 == arguments->scalarOutputCount)
+            {
+                ret = this->secureGetSystemSleepType(
+                        (uint32_t *) &arguments->scalarOutput[0]);
+            }
+            break;
+
+        case kPMSleepWakeWatchdogEnable:
+            ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
+            if (ret == kIOReturnSuccess)
+               fOwner->sleepWakeDebugEnableWdog();
+            break;
+
+
+        case kPMSleepWakeDebugTrig:
+            ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
+            if (ret == kIOReturnSuccess)
+               fOwner->sleepWakeDebugTrig(false);
+            break;
+
+        case kPMSetDisplayPowerOn:
+            if (1 == arguments->scalarInputCount)
+            {
+                ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
+                if (ret == kIOReturnSuccess)
+                    fOwner->setDisplayPowerOn((uint32_t)arguments->scalarInput[0]);
+            }
+            break;
 /*
         case kPMMethodCopySystemTimeline:
             // intentional fallthrough