Loading...
--- xnu/xnu-792.2.4/libsa/kext.cpp
+++ xnu/xnu-792.25.20/libsa/kext.cpp
@@ -166,7 +166,6 @@
if (!uncompressModule(compressedCode, &driverCode)) {
IOLog("extension \"%s\": couldn't uncompress code\n",
bundleid);
- LOG_DELAY(1);
result = false;
goto finish;
}
@@ -317,7 +316,7 @@
extDict->getObject("compressedCode"));
if ((driverCode || compressedCode) && is_kernel && *is_kernel) {
- *is_kernel = 2;
+ *is_kernel = 2;
}
if (!driverCode && !compressedCode && !isKernelResourceObj) {
@@ -333,8 +332,8 @@
/*********************************************************************
*********************************************************************/
static bool
-figureDependenciesForKext(OSDictionary * kextPlist,
- OSDictionary * dependencies,
+addDependenciesForKext(OSDictionary * kextPlist,
+ OSArray * dependencyList,
OSString * trueParent,
Boolean skipKernelDependencies)
{
@@ -344,6 +343,7 @@
OSDictionary * libraries = 0; // don't release
OSCollectionIterator * keyIterator = 0; // must release
OSString * libraryName = 0; // don't release
+ OSString * dependentName = 0; // don't release
kextName = OSDynamicCast(OSString,
kextPlist->getObject("CFBundleIdentifier"));
@@ -367,6 +367,8 @@
goto finish;
}
+ dependentName = trueParent ? trueParent : kextName;
+
while ( (libraryName = OSDynamicCast(OSString,
keyIterator->getNextObject())) ) {
@@ -383,12 +385,15 @@
} else {
char is_kernel_component;
- if (!kextIsDependency(libraryName->getCStringNoCopy(), &is_kernel_component))
+ if (!kextIsDependency(libraryName->getCStringNoCopy(),
+ &is_kernel_component)) {
+
is_kernel_component = false;
+ }
if (!skipKernelDependencies || !is_kernel_component) {
- dependencies->setObject(libraryName,
- trueParent ? trueParent : kextName);
+ dependencyList->setObject(dependentName);
+ dependencyList->setObject(libraryName);
}
if (!hasDirectKernelDependency && is_kernel_component) {
hasDirectKernelDependency = true;
@@ -396,11 +401,22 @@
}
}
if (!hasDirectKernelDependency) {
+ const OSSymbol * kernelName = 0;
+
/* a kext without any kernel dependency is assumed dependent on 6.0 */
- dependencies->setObject("com.apple.kernel.libkern",
- trueParent ? trueParent : kextName);
+ dependencyList->setObject(dependentName);
+
+ kernelName = OSSymbol::withCString("com.apple.kernel.libkern");
+ if (!kernelName) {
+ // XXX: Add log message
+ result = false;
+ goto finish;
+ }
+ dependencyList->setObject(kernelName);
+ kernelName->release();
+
IOLog("Extension \"%s\" has no kernel dependency.\n",
- kextName->getCStringNoCopy());
+ kextName->getCStringNoCopy());
}
finish:
@@ -446,14 +462,8 @@
{
bool result = true;
OSDictionary * kextPlist = 0; // don't release
- OSDictionary * workingDependencies = 0; // must release
- OSDictionary * pendingDependencies = 0; // must release
- OSDictionary * swapDict = 0; // don't release
- OSString * dependentName = 0; // don't release
- const char * dependent_name = 0; // don't free
- OSString * libraryName = 0; // don't release
- const char * library_name = 0; // don't free
- OSCollectionIterator * dependencyIterator = 0; // must release
+ unsigned int index = 0;
+ OSArray * dependencyList = 0; // must release
unsigned char * code = 0;
unsigned long code_length = 0;
bool code_is_kmem = false;
@@ -461,9 +471,11 @@
char is_kernel_component = false;
dgraph_entry_t * dgraph_entry = 0; // don't free
dgraph_entry_t * dgraph_dependency = 0; // don't free
- unsigned int graph_depth = 0;
bool kext_is_dependency = true;
+ /*****
+ * Set up the root kmod.
+ */
if (!getKext(kmod_name, &kextPlist, &code, &code_length,
&code_is_kmem)) {
IOLog("can't find extension %s\n", kmod_name);
@@ -495,8 +507,7 @@
}
// pass ownership of code to kld patcher
- if (code)
- {
+ if (code) {
if (kload_map_entry(dgraph_entry) != kload_error_none) {
IOLog("can't map %s in preparation for loading\n", kmod_name);
result = false;
@@ -509,95 +520,78 @@
code_length = 0;
code_is_kmem = false;
- workingDependencies = OSDictionary::withCapacity(5);
- if (!workingDependencies) {
+ /*****
+ * Now handle all the dependencies.
+ */
+ dependencyList = OSArray::withCapacity(5);
+ if (!dependencyList) {
IOLog("memory allocation failure\n");
result = false;
goto finish;
}
- pendingDependencies = OSDictionary::withCapacity(5);
- if (!pendingDependencies) {
- IOLog("memory allocation failure\n");
- result = false;
- goto finish;
- }
-
- if (!figureDependenciesForKext(kextPlist, workingDependencies, NULL, false)) {
+ index = 0;
+ if (!addDependenciesForKext(kextPlist, dependencyList, NULL, false)) {
IOLog("can't determine immediate dependencies for extension %s\n",
kmod_name);
result = false;
goto finish;
}
- graph_depth = 0;
- while (workingDependencies->getCount()) {
- if (graph_depth > 255) {
+ /* IMPORTANT: loop condition gets list count every time through, as the
+ * array CAN change each iteration.
+ */
+ for (index = 0; index < dependencyList->getCount(); index += 2) {
+ OSString * dependentName = 0;
+ OSString * libraryName = 0;
+ const char * dependent_name = 0;
+ const char * library_name = 0;
+
+ /* 255 is an arbitrary limit. Multiplied by 2 because the dependency
+ * list is stocked with pairs (dependent -> dependency).
+ */
+ if (index > (2 * 255)) {
IOLog("extension dependency graph ridiculously long, indicating a loop\n");
result = false;
goto finish;
}
- if (dependencyIterator) {
- dependencyIterator->release();
- dependencyIterator = 0;
- }
-
- dependencyIterator = OSCollectionIterator::withCollection(
- workingDependencies);
- if (!dependencyIterator) {
- IOLog("memory allocation failure\n");
+ dependentName = OSDynamicCast(OSString,
+ dependencyList->getObject(index));
+ libraryName = OSDynamicCast(OSString,
+ dependencyList->getObject(index + 1));
+
+ if (!dependentName || !libraryName) {
+ IOLog("malformed dependency list\n");
result = false;
goto finish;
}
- while ( (libraryName =
- OSDynamicCast(OSString, dependencyIterator->getNextObject())) ) {
-
- library_name = libraryName->getCStringNoCopy();
-
- dependentName = OSDynamicCast(OSString,
- workingDependencies->getObject(libraryName));
-
- dependent_name = dependentName->getCStringNoCopy();
-
+ dependent_name = dependentName->getCStringNoCopy();
+ library_name = libraryName->getCStringNoCopy();
+
+ if (!getKext(library_name, &kextPlist, NULL, NULL, NULL)) {
+
+ IOLog("can't find extension %s\n", library_name);
+ result = false;
+ goto finish;
+ }
+
+ OSString * string = OSDynamicCast(OSString,
+ kextPlist->getObject("OSBundleSharedExecutableIdentifier"));
+ if (string) {
+ library_name = string->getCStringNoCopy();
if (!getKext(library_name, &kextPlist, NULL, NULL, NULL)) {
IOLog("can't find extension %s\n", library_name);
result = false;
goto finish;
}
-
- OSString * string;
- if ((string = OSDynamicCast(OSString,
- kextPlist->getObject("OSBundleSharedExecutableIdentifier"))))
- {
- library_name = string->getCStringNoCopy();
- if (!getKext(library_name, &kextPlist, NULL, NULL, NULL)) {
- IOLog("can't find extension %s\n", library_name);
- result = false;
- goto finish;
- }
- }
-
- kext_is_dependency = kextIsDependency(library_name,
- &is_kernel_component);
-
- if (!kext_is_dependency) {
-
- /* For binaryless kexts, add a new pending dependency from the
- * original dependent onto the dependencies of the current,
- * binaryless, dependency.
- */
- if (!figureDependenciesForKext(kextPlist, pendingDependencies,
- dependentName, true)) {
-
- IOLog("can't determine immediate dependencies for extension %s\n",
- library_name);
- result = false;
- goto finish;
- }
- continue;
- } else {
+ }
+
+ kext_is_dependency = kextIsDependency(library_name,
+ &is_kernel_component);
+
+ if (kext_is_dependency) {
dgraph_entry = dgraph_find_dependent(dgraph, dependent_name);
if (!dgraph_entry) {
IOLog("internal error with dependency graph\n");
@@ -652,8 +646,8 @@
/* Now put the library's dependencies onto the pending set.
*/
- if (!figureDependenciesForKext(kextPlist, pendingDependencies,
- NULL, false)) {
+ if (!addDependenciesForKext(kextPlist, dependencyList,
+ kext_is_dependency ? NULL : dependentName, !kext_is_dependency)) {
IOLog("can't determine immediate dependencies for extension %s\n",
library_name);
@@ -662,23 +656,12 @@
}
}
- dependencyIterator->release();
- dependencyIterator = 0;
-
- workingDependencies->flushCollection();
- swapDict = workingDependencies;
- workingDependencies = pendingDependencies;
- pendingDependencies = swapDict;
- graph_depth++;
- }
-
finish:
if (code && code_is_kmem) {
kmem_free(kernel_map, (unsigned int)code, code_length);
}
- if (workingDependencies) workingDependencies->release();
- if (pendingDependencies) pendingDependencies->release();
- if (dependencyIterator) dependencyIterator->release();
+ if (dependencyList) dependencyList->release();
+
return result;
}
@@ -706,7 +689,7 @@
/* See if the kmod is already loaded.
*/
if ((kmod_info = kmod_lookupbyname_locked(kmod_name))) {
- kfree((vm_offset_t) kmod_info, sizeof(kmod_info_t));
+ kfree(kmod_info, sizeof(kmod_info_t));
return KERN_SUCCESS;
}