Loading...
--- xnu/xnu-6153.11.26/iokit/Kernel/IOInterruptEventSource.cpp
+++ xnu/xnu-8792.61.2/iokit/Kernel/IOInterruptEventSource.cpp
@@ -26,6 +26,9 @@
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
+#define IOKIT_ENABLE_SHARED_PTR
+
+#include <ptrauth.h>
#include <IOKit/IOInterruptEventSource.h>
#include <IOKit/IOKitDebug.h>
#include <IOKit/IOLib.h>
@@ -34,6 +37,7 @@
#include <IOKit/IOTimeStamp.h>
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IOInterruptAccountingPrivate.h>
+#include <libkern/Block_private.h>
#if IOKITSTATS
@@ -80,17 +84,15 @@
{
bool res = true;
+ if (inIntIndex < 0) {
+ return false;
+ }
+
if (!super::init(inOwner, (IOEventSourceAction) inAction)) {
return false;
}
- reserved = IONew(ExpansionData, 1);
-
- if (!reserved) {
- return false;
- }
-
- bzero(reserved, sizeof(ExpansionData));
+ reserved = IOMallocType(ExpansionData);
provider = inProvider;
producerCount = consumerCount = 0;
@@ -109,17 +111,7 @@
* We also avoid try to avoid interrupt accounting overhead if none of
* the statistics are enabled.
*/
- reserved->statistics = IONew(IOInterruptAccountingData, 1);
-
- if (!reserved->statistics) {
- /*
- * We rely on the free() routine to clean up after us if init fails
- * midway.
- */
- return false;
- }
-
- bzero(reserved->statistics, sizeof(IOInterruptAccountingData));
+ reserved->statistics = IOMallocType(IOInterruptAccountingData);
reserved->statistics->owner = this;
}
@@ -208,29 +200,28 @@
}
-IOInterruptEventSource *
+OSSharedPtr<IOInterruptEventSource>
IOInterruptEventSource::interruptEventSource(OSObject *inOwner,
Action inAction,
IOService *inProvider,
int inIntIndex)
{
- IOInterruptEventSource *me = new IOInterruptEventSource;
+ OSSharedPtr<IOInterruptEventSource> me = OSMakeShared<IOInterruptEventSource>();
if (me && !me->init(inOwner, inAction, inProvider, inIntIndex)) {
- me->release();
- return NULL;
+ return nullptr;
}
return me;
}
-IOInterruptEventSource *
+OSSharedPtr<IOInterruptEventSource>
IOInterruptEventSource::interruptEventSource(OSObject *inOwner,
IOService *inProvider,
int inIntIndex,
ActionBlock inAction)
{
- IOInterruptEventSource * ies;
+ OSSharedPtr<IOInterruptEventSource> ies;
ies = IOInterruptEventSource::interruptEventSource(inOwner, (Action) NULL, inProvider, inIntIndex);
if (ies) {
ies->setActionBlock((IOEventSource::ActionBlock) inAction);
@@ -248,10 +239,10 @@
if (reserved) {
if (reserved->statistics) {
- IODelete(reserved->statistics, IOInterruptAccountingData, 1);
- }
-
- IODelete(reserved, ExpansionData, 1);
+ IOFreeType(reserved->statistics, IOInterruptAccountingData);
+ }
+
+ IOFreeType(reserved, ExpansionData);
}
super::free();
@@ -331,16 +322,24 @@
uint64_t endCPUTime = 0;
unsigned int cacheProdCount = producerCount;
int numInts = cacheProdCount - consumerCount;
- IOInterruptEventAction intAction = (IOInterruptEventAction) action;
+ IOEventSource::Action intAction = action;
ActionBlock intActionBlock = (ActionBlock) actionBlock;
+ void *address;
bool trace = (gIOKitTrace & kIOTraceIntEventSource) ? true : false;
+
+ if (kActionBlock & flags) {
+ address = ptrauth_nop_cast(void *, _Block_get_invoke_fn((struct Block_layout *)intActionBlock));
+ } else {
+ address = ptrauth_nop_cast(void *, intAction);
+ }
IOStatisticsCheckForWork();
if (numInts > 0) {
if (trace) {
IOTimeStampStartConstant(IODBG_INTES(IOINTES_ACTION),
- VM_KERNEL_ADDRHIDE(intAction), VM_KERNEL_ADDRHIDE(owner),
+ VM_KERNEL_ADDRHIDE(address),
+ VM_KERNEL_ADDRHIDE(owner),
VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop));
}
@@ -358,7 +357,7 @@
if (kActionBlock & flags) {
(intActionBlock)(this, numInts);
} else {
- (*intAction)(owner, this, numInts);
+ ((IOInterruptEventAction)intAction)(owner, this, numInts);
}
if (reserved->statistics) {
@@ -379,7 +378,8 @@
if (trace) {
IOTimeStampEndConstant(IODBG_INTES(IOINTES_ACTION),
- VM_KERNEL_ADDRHIDE(intAction), VM_KERNEL_ADDRHIDE(owner),
+ VM_KERNEL_ADDRHIDE(address),
+ VM_KERNEL_ADDRHIDE(owner),
VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop));
}
@@ -390,7 +390,8 @@
} else if (numInts < 0) {
if (trace) {
IOTimeStampStartConstant(IODBG_INTES(IOINTES_ACTION),
- VM_KERNEL_ADDRHIDE(intAction), VM_KERNEL_ADDRHIDE(owner),
+ VM_KERNEL_ADDRHIDE(address),
+ VM_KERNEL_ADDRHIDE(owner),
VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop));
}
@@ -408,12 +409,13 @@
if (kActionBlock & flags) {
(intActionBlock)(this, numInts);
} else {
- (*intAction)(owner, this, numInts);
+ ((IOInterruptEventAction)intAction)(owner, this, numInts);
}
if (reserved->statistics) {
- if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingSecondLevelCountIndex)) {
- IA_ADD_VALUE(&reserved->statistics->interruptStatistics[kInterruptAccountingSecondLevelCountIndex], 1);
+ if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingSecondLevelSystemTimeIndex)) {
+ endSystemTime = mach_absolute_time();
+ IA_ADD_VALUE(&reserved->statistics->interruptStatistics[kInterruptAccountingSecondLevelSystemTimeIndex], endSystemTime - startSystemTime);
}
if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingSecondLevelCPUTimeIndex)) {
@@ -421,15 +423,15 @@
IA_ADD_VALUE(&reserved->statistics->interruptStatistics[kInterruptAccountingSecondLevelCPUTimeIndex], endCPUTime - startCPUTime);
}
- if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingSecondLevelSystemTimeIndex)) {
- endSystemTime = mach_absolute_time();
- IA_ADD_VALUE(&reserved->statistics->interruptStatistics[kInterruptAccountingSecondLevelSystemTimeIndex], endSystemTime - startSystemTime);
+ if (IA_GET_STATISTIC_ENABLED(kInterruptAccountingSecondLevelCountIndex)) {
+ IA_ADD_VALUE(&reserved->statistics->interruptStatistics[kInterruptAccountingSecondLevelCountIndex], 1);
}
}
if (trace) {
IOTimeStampEndConstant(IODBG_INTES(IOINTES_ACTION),
- VM_KERNEL_ADDRHIDE(intAction), VM_KERNEL_ADDRHIDE(owner),
+ VM_KERNEL_ADDRHIDE(address),
+ VM_KERNEL_ADDRHIDE(owner),
VM_KERNEL_ADDRHIDE(this), VM_KERNEL_ADDRHIDE(workLoop));
}
@@ -529,7 +531,7 @@
}
uint64_t
-IOInterruptEventSource::getPimaryInterruptTimestamp()
+IOInterruptEventSource::getPrimaryInterruptTimestamp()
{
if (reserved->statistics && reserved->statistics->enablePrimaryTimestamp) {
return reserved->statistics->primaryTimestamp;