I'm using some of the functions from IOKit/kext/KextManager.h to programmatically load kernel a extension, and I'm encountering new error values. For example:
OSReturn osr = KextManagerLoadKextWithIdentifier(...);
// => -603947004
How can I translate this value to one of the human-readable definitions found in libkern/OSReturn.h?
Per @pmjordan's comment, I just created a simple mapping function using definitions from OSReturn.h.
- (void)human_readable_libkern_metaclass_error_message:(int) n {
switch(n){
case 0:
printf("%s", "no error");
break;
case kOSMetaClassInternal:
// libkern_metaclass_err(1) -603979775
printf("%s", "Internal OSMetaClass run-time error.");
break;
case kOSMetaClassHasInstances:
// libkern_metaclass_err(2) -603979774
printf("%s", "A kext cannot be unloaded because there are instances derived from Libkern C++ classes that it defines.");
break;
case kOSMetaClassNoInit:
// libkern_metaclass_err(3) -603979773
printf("%s", "Internal error: The Libkern C++ class registration system was not properly initialized during kext loading.");
break;
case kOSMetaClassNoTempData:
// libkern_metaclass_err(4) -603979772
printf("%s", "Internal error: An allocation failure occurred registering Libkern C++ classes during kext loading.");
break;
case kOSMetaClassNoDicts:
// libkern_metaclass_err(5) -603979771
printf("%s", "Internal error: An allocation failure occurred registering Libkern C++ classes during kext loading.");
break;
case kOSMetaClassNoKModSet:
// libkern_metaclass_err(6) -603979770
printf("%s", "Internal error: An allocation failure occurred registering Libkern C++ classes during kext loading.");
break;
case kOSMetaClassNoInsKModSet:
// libkern_metaclass_err(7) -603979769
printf("%s", "Internal error: An error occurred registering a specific Libkern C++ class during kext loading.");
break;
case kOSMetaClassNoSuper:
// libkern_metaclass_err(8) -603979768
printf("%s", "Internal error: No superclass can be found for a specific Libkern C++ class during kext loading.");
break;
case kOSMetaClassInstNoSuper:
// libkern_metaclass_err(9) -603979767
printf("%s", "Internal error: No superclass can be found when constructing an instance of a Libkern C++ class.");
break;
case kOSMetaClassDuplicateClass:
// libkern_metaclass_err(10) -603979766
printf("%s", "A duplicate Libkern C++ classname was encountered during kext loading.");
break;
case kOSMetaClassNoKext:
// libkern_metaclass_err(11) -603979765
printf("%s", "Internal error: The kext for a Libkern C++ class can't be found during kext loading.");
break;
default:
printf("%s", "Unknown: error not defined in <libkern/OSReturn.h>)");
break;
}
}
XXX failed to load - (libkern/kext) not privileged; check the system/kernel logs for errors or try kextutil(8).
The error message you get when you try a kextload without root privileges.
-603947004 - this code appears in OSReturn when you try to load the kext via code without root privileges. The above code for translation works well for defined cases but for undefined error codes invoking the command via terminal helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With