- kmod_info_t * k_info;
-
- if ( !moduleName )
- return false;
-
- // Is the module already loaded?
- k_info = kmod_lookupbyname((char *)moduleName);
- if ( !k_info ) {
- kern_return_t ret;
-
- /* To make sure this operation completes even if a bad extension needs
- * to be removed, take the kld lock for this whole block, spanning the
- * kmod_load_function() and remove_startup_extension_function() calls.
- */
- IOLockLock(kld_lock);
-
- // If the module hasn't been loaded, then load it.
- if (kmod_load_function != 0) {
-
- ret = kmod_load_function((char *)moduleName);
-
- if ( ret != kIOReturnSuccess ) {
- IOLog("IOCatalogue: %s cannot be loaded.\n", moduleName);
-
- /* If the extension couldn't be loaded this time,
- * make it unavailable so that no more requests are
- * made in vain. This also enables other matching
- * extensions to have a chance.
- */
- if (kernelLinkerPresent && remove_startup_extension_function) {
- (*remove_startup_extension_function)(moduleName);
- }
- IOLockUnlock(kld_lock);
- return false;
- } else if (kernelLinkerPresent) {
- // If kern linker is here, the driver is actually loaded,
- // so return true.
- IOLockUnlock(kld_lock);
- return true;
- } else {
- // kern linker isn't here, a request has been queued
- // but the module isn't necessarily loaded yet, so stall.
- IOLockUnlock(kld_lock);
- return false;
- }
- } else {
- IOLog("IOCatalogue: %s cannot be loaded "
- "(kmod load function not set).\n",
- moduleName);
- }
-
- IOLockUnlock(kld_lock);