Loading...
--- xnu/xnu-2050.18.24/iokit/Kernel/RootDomainUserClient.cpp
+++ xnu/xnu-2422.110.17/iokit/Kernel/RootDomainUserClient.cpp
@@ -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@
*
@@ -37,6 +37,7 @@
#include "RootDomainUserClient.h"
#include <IOKit/pwr_mgt/IOPMLibDefs.h>
#include <IOKit/pwr_mgt/IOPMPrivate.h>
+#include <sys/proc.h>
#define super IOUserClient
@@ -79,7 +80,7 @@
IOReturn RootDomainUserClient::secureSleepSystemOptions(
const void *inOptions,
- IOByteCount inOptionsSize __unused,
+ IOByteCount inOptionsSize,
uint32_t *returnCode)
{
@@ -99,7 +100,7 @@
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",
@@ -107,9 +108,14 @@
}
}
- 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
@@ -189,6 +195,23 @@
ret = kIOReturnNotPrivileged;
}
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 )
@@ -311,11 +334,48 @@
break;
case kPMActivityTickle:
- fOwner->reportUserInput( );
- fOwner->setProperty(kIOPMRootDomainWakeTypeKey, "UserActivity Assertion");
+ 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