将OSReturn值转换为人类可读定义

时间:2012-11-25 06:50:21

标签: objective-c macos iokit kernel-extension

我正在使用IOKit/kext/KextManager.h中的一些函数以编程方式加载内核扩展,我遇到了新的错误值。例如:

OSReturn osr = KextManagerLoadKextWithIdentifier(...);
// => -603947004

如何将此值转换为libkern/OSReturn.h中的人类可读定义之一?

2 个答案:

答案 0 :(得分:1)

Per @ pmjordan的comment,我刚刚使用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;
  }
}

答案 1 :(得分:1)

XXX加载失败-(libkern / kext)没有特权;检查系统/内核日志中是否有错误或尝试kextutil(8)。

尝试没有root特权的kextload时收到的错误消息。

-603947004-当您尝试通过没有root特权的代码加载kext时,此代码将出现在OSReturn中。上面的翻译代码在定义好的情况下效果很好,但是对于通过终端帮助调用命令的未定义错误代码。