Loading...
--- xnu/xnu-12377.101.15/iokit/Kernel/IOStatistics.cpp
+++ xnu/xnu-6153.41.3/iokit/Kernel/IOStatistics.cpp
@@ -151,10 +151,6 @@
int error = EINVAL;
uint32_t request = arg2;
- if (!IOStatistics::isEnabled()) {
- return ENOENT;
- }
-
switch (request) {
case kIOStatisticsGeneral:
error = IOStatistics::getStatistics(req);
@@ -175,17 +171,16 @@
SYSCTL_NODE(_debug, OID_AUTO, iokit_statistics, CTLFLAG_RW | CTLFLAG_LOCKED, NULL, "IOStatistics");
static SYSCTL_PROC(_debug_iokit_statistics, OID_AUTO, general,
- CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN | CTLFLAG_LOCKED,
NULL, kIOStatisticsGeneral, oid_sysctl, "S", "");
static SYSCTL_PROC(_debug_iokit_statistics, OID_AUTO, workloop,
- CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN | CTLFLAG_LOCKED,
NULL, kIOStatisticsWorkLoop, oid_sysctl, "S", "");
static SYSCTL_PROC(_debug_iokit_statistics, OID_AUTO, userclient,
- CTLTYPE_STRUCT | CTLFLAG_RW | CTLFLAG_KERN | CTLFLAG_LOCKED,
+ CTLTYPE_STRUCT | CTLFLAG_RW | CTLFLAG_NOAUTO | CTLFLAG_KERN | CTLFLAG_LOCKED,
NULL, kIOStatisticsUserClient, oid_sysctl, "S", "");
-
void
IOStatistics::initialize()
@@ -199,12 +194,16 @@
return;
}
+ sysctl_register_oid(&sysctl__debug_iokit_statistics_general);
+ sysctl_register_oid(&sysctl__debug_iokit_statistics_workloop);
+ sysctl_register_oid(&sysctl__debug_iokit_statistics_userclient);
+
lock = IORWLockAlloc();
if (!lock) {
return;
}
- nextWorkLoopDependency = kalloc_type(IOWorkLoopDependency, Z_WAITOK);
+ nextWorkLoopDependency = (IOWorkLoopDependency*)kalloc(sizeof(IOWorkLoopDependency));
if (!nextWorkLoopDependency) {
return;
}
@@ -226,10 +225,12 @@
LOG(1, "IOStatistics::onKextLoad: %s, tag %d, address 0x%llx, address end 0x%llx\n",
kext->getIdentifierCString(), kmod_info->id, (uint64_t)kmod_info->address, (uint64_t)(kmod_info->address + kmod_info->size));
- ke = kalloc_type(KextNode, (zalloc_flags_t)(Z_WAITOK | Z_ZERO));
+ ke = (KextNode *)kalloc(sizeof(KextNode));
if (!ke) {
return;
}
+
+ memset(ke, 0, sizeof(KextNode));
ke->kext = kext;
ke->loadTag = kmod_info->id;
@@ -281,7 +282,7 @@
/* Free up the user client list */
while ((uce = TAILQ_FIRST(&found->userClientCallList))) {
TAILQ_REMOVE(&found->userClientCallList, uce, link);
- kfree_type(IOUserClientProcessEntry, uce);
+ kfree(uce, sizeof(IOUserClientProcessEntry));
}
/* Remove from kext trees */
@@ -297,7 +298,7 @@
}
/* Finally, free the class node */
- kfree_type(KextNode, found);
+ kfree(found, sizeof(KextNode));
sequenceID++;
loadedKexts--;
@@ -322,10 +323,12 @@
LOG(1, "IOStatistics::onClassAdded: %s\n", metaClass->getClassName());
- ce = kalloc_type(ClassNode, (zalloc_flags_t)(Z_WAITOK | Z_ZERO));
+ ce = (ClassNode *)kalloc(sizeof(ClassNode));
if (!ce) {
return;
}
+
+ memset(ce, 0, sizeof(ClassNode));
IORWLockWrite(lock);
@@ -396,13 +399,13 @@
/* Free up the list of counters */
while ((esc = SLIST_FIRST(&found->counterList))) {
SLIST_REMOVE_HEAD(&found->counterList, link);
- kfree_type(IOEventSourceCounter, esc);
+ kfree(esc, sizeof(IOEventSourceCounter));
}
/* Free up the user client list */
while ((ucc = SLIST_FIRST(&found->userClientList))) {
SLIST_REMOVE_HEAD(&found->userClientList, link);
- kfree_type(IOUserClientCounter, ucc);
+ kfree(ucc, sizeof(IOUserClientCounter));
}
/* Remove from class tree */
@@ -412,7 +415,7 @@
SLIST_REMOVE(&found->parentKext->classList, found, ClassNode, lLink);
/* Finally, free the class node */
- kfree_type(ClassNode, found);
+ kfree(found, sizeof(ClassNode));
sequenceID++;
registeredClasses--;
@@ -436,10 +439,12 @@
return NULL;
}
- counter = kalloc_type(IOEventSourceCounter, (zalloc_flags_t)(Z_WAITOK | Z_ZERO));
+ counter = (IOEventSourceCounter*)kalloc(sizeof(IOEventSourceCounter));
if (!counter) {
return NULL;
}
+
+ memset(counter, 0, sizeof(IOEventSourceCounter));
IORWLockWrite(lock);
@@ -482,7 +487,7 @@
SLIST_REMOVE(&counter->parentClass->counterList, counter, IOEventSourceCounter, link);
registeredCounters--;
}
- kfree_type(IOEventSourceCounter, counter);
+ kfree(counter, sizeof(IOEventSourceCounter));
IORWLockUnlock(lock);
}
@@ -499,10 +504,12 @@
return NULL;
}
- counter = kalloc_type(IOWorkLoopCounter, (zalloc_flags_t)(Z_WAITOK | Z_ZERO));
+ counter = (IOWorkLoopCounter*)kalloc(sizeof(IOWorkLoopCounter));
if (!counter) {
return NULL;
}
+
+ memset(counter, 0, sizeof(IOWorkLoopCounter));
found = getKextNodeFromBacktrace(TRUE);
if (!found) {
@@ -531,7 +538,7 @@
if (counter->parentKext) {
SLIST_REMOVE(&counter->parentKext->workLoopList, counter, IOWorkLoopCounter, link);
}
- kfree_type(IOWorkLoopCounter, counter);
+ kfree(counter, sizeof(IOWorkLoopCounter));
registeredWorkloops--;
IORWLockUnlock(lock);
@@ -549,10 +556,12 @@
return NULL;
}
- counter = kalloc_type(IOUserClientCounter, (zalloc_flags_t)(Z_WAITOK | Z_ZERO));
+ counter = (IOUserClientCounter*)kalloc(sizeof(IOUserClientCounter));
if (!counter) {
return NULL;
}
+
+ memset(counter, 0, sizeof(IOUserClientCounter));
IORWLockWrite(lock);
@@ -581,7 +590,7 @@
IORWLockWrite(lock);
SLIST_REMOVE(&counter->parentClass->userClientList, counter, IOUserClientCounter, link);
- kfree_type(IOUserClientCounter, counter);
+ kfree(counter, sizeof(IOUserClientCounter));
IORWLockUnlock(lock);
}
@@ -605,7 +614,7 @@
/* Track the kext dependency */
nextWorkLoopDependency->loadTag = esc->parentClass->parentKext->loadTag;
if (NULL == RB_INSERT(IOWorkLoopCounter::DependencyTree, &wlc->dependencyHead, nextWorkLoopDependency)) {
- nextWorkLoopDependency = kalloc_type(IOWorkLoopDependency, Z_WAITOK);
+ nextWorkLoopDependency = (IOWorkLoopDependency*)kalloc(sizeof(IOWorkLoopDependency));
}
IORWLockUnlock(lock);
@@ -630,7 +639,7 @@
found = RB_FIND(IOWorkLoopCounter::DependencyTree, &wlc->dependencyHead, &sought);
if (found) {
RB_REMOVE(IOWorkLoopCounter::DependencyTree, &wlc->dependencyHead, found);
- kfree_type(IOWorkLoopDependency, found);
+ kfree(found, sizeof(IOWorkLoopDependency));
}
IORWLockUnlock(lock);
@@ -670,11 +679,13 @@
goto exit;
}
- buffer = (char*)kalloc_data(calculatedSize, (zalloc_flags_t)(Z_WAITOK | Z_ZERO));
+ buffer = (char*)kalloc(calculatedSize);
if (!buffer) {
error = ENOMEM;
goto exit;
}
+
+ memset(buffer, 0, calculatedSize);
ptr = buffer;
@@ -729,7 +740,7 @@
error = SYSCTL_OUT(req, buffer, calculatedSize);
- kfree_data(buffer, calculatedSize);
+ kfree(buffer, calculatedSize);
exit:
IORWLockUnlock(IOStatistics::lock);
@@ -764,11 +775,12 @@
goto exit;
}
- buffer = (char*)kalloc_data(calculatedSize, (zalloc_flags_t)(Z_WAITOK | Z_ZERO));
+ buffer = (char*)kalloc(calculatedSize);
if (!buffer) {
error = ENOMEM;
goto exit;
}
+ memset(buffer, 0, calculatedSize);
header = (IOStatisticsWorkLoopHeader*)((void*)buffer);
header->sig = IOSTATISTICS_SIG_WORKLOOP;
@@ -786,7 +798,7 @@
error = SYSCTL_OUT(req, buffer, size);
- kfree_data(buffer, calculatedSize);
+ kfree(buffer, calculatedSize);
exit:
IORWLockUnlock(IOStatistics::lock);
@@ -829,11 +841,12 @@
LOG(2, "IOStatistics::getUserClientStatistics - requesting kext w/load tag: %d\n", requestedLoadTag);
- buffer = (char*)kalloc_data(calculatedSize, (zalloc_flags_t)(Z_WAITOK | Z_ZERO));
+ buffer = (char*)kalloc(calculatedSize);
if (!buffer) {
error = ENOMEM;
goto exit;
}
+ memset(buffer, 0, calculatedSize);
header = (IOStatisticsUserClientHeader*)((void*)buffer);
header->sig = IOSTATISTICS_SIG_USERCLIENT;
@@ -853,7 +866,7 @@
error = EINVAL;
}
- kfree_data(buffer, calculatedSize);
+ kfree(buffer, calculatedSize);
exit:
IORWLockUnlock(IOStatistics::lock);
@@ -1179,9 +1192,10 @@
TAILQ_REMOVE(&parentKext->userClientCallList, entry, link);
} else {
/* Otherwise, allocate a new entry */
- entry = kalloc_type(IOUserClientProcessEntry, Z_WAITOK);
+ entry = (IOUserClientProcessEntry*)kalloc(sizeof(IOUserClientProcessEntry));
if (!entry) {
- goto err_unlock;
+ IORWLockUnlock(lock);
+ return;
}
}
@@ -1246,7 +1260,7 @@
* overhead. OSBacktrace does many safety checks that
* are not needed in this situation.
*/
- btCount = backtrace((uintptr_t*)bt, btCount, NULL, NULL);
+ btCount = backtrace((uintptr_t*)bt, btCount, NULL);
if (write) {
IORWLockWrite(lock);
@@ -1298,13 +1312,10 @@
if (!enabled) {
return;
}
- if (size > INT_MAX) {
- return;
- }
ke = getKextNodeFromBacktrace(FALSE);
if (ke) {
- OSAddAtomic((SInt32) size, &ke->memoryCounters[index]);
+ OSAddAtomic(size, &ke->memoryCounters[index]);
releaseKextNode(ke);
}
}