2017-12-27 323 views
0

我計劃約在Mac屯內核擴展,我用的是API proto_register_plumber喜歡如下:mac kernel-extension的錯誤代碼含義是什麼?

err = proto_register_plumber(PF_INET, IFNET_FAMILY_TUN, method_attach, method_detach); 
if (err) { 
    printf("error code is : %d\n", err); 
} 

在一個MAC(10.13),它返回17,它意味着什麼?我該如何解決它?

我閱讀了關於https://developer.apple.com/documentation/kernel/1532491-proto_register_plumber?language=objc的API文檔,但我沒有發現任何有關錯誤代碼的含義。

回答

1

17幾乎肯定是errno,特別是因爲這是來自KPI的BSD部分。如果您在errno.h看你會發現,它對應於EEXIST

#define EEXIST  17  /* File exists */ 

在你的API調用的情況下,這可能意味着已經是你想註冊登記的事情的東西。我不熟悉的proto_register_plumber()功能,但非常快看its source code顯示功能,這似乎證實了我的懷疑開始靠近下列檢查:

lck_mtx_lock(proto_family_mutex); 

TAILQ_FOREACH(proto_family, &proto_family_head, proto_fam_next) { 
    if (proto_family->proto_family == protocol_family && 
     proto_family->if_family == interface_family) { 
     lck_mtx_unlock(proto_family_mutex); 
     return (EEXIST); 
    } 
} 

難道說:

  • 你以前註冊過處理程序,卸載了你的kext,它沒有註銷它,然後你重新加載了你的kext,試圖重新註冊它?在這種情況下,重新啓動(並修復kext stop功能!)應該修復它。
  • 另一個加載的kext已經註冊了它自己的處理程序?如果是這樣,請嘗試卸載可能的候選人。
  • xnu內核已經爲此協議族提供了默認處理程序?也許你需要以不同的方式去做你想要做的事情。
+0

坦克,這是因爲另一個kext註冊其處理程序! – waitianlou