我遵循Creating a Generic Kernel Extension with Xcode教程。Mac內核編程通用內核擴展prinf()不起作用
MyKext.c:
#include <sys/systm.h>
#include <mach/mach_types.h>
kern_return_t MyKext_start (kmod_info_t * ki, void * d)
{
printf("MyKext has started.\n");
return KERN_SUCCESS;
}
kern_return_t MyKext_stop (kmod_info_t * ki, void * d)
{
printf("MyKext has stopped.\n");
return KERN_SUCCESS;
}
我還禁用了csrutil,這讓我加載我自己的內核擴展。
# csrutil disable
當我打開我自己的內核擴展到內核
$ sudo kextload -v /tmp/MyKext.kext
的printf()的結果寫不進/var/log/system.log。
我還設置啓動參數
$ sudo nvram boot-args="original_contents debug=0x4"
誰能幫助我嗎?
首先,您需要使用內核函數。所以'printf()'應該是'printk()' – user3629249
有寫入系統日誌的特定函數。它們是:''openlog()','syslog()','closelog()' – user3629249
@ user3629249:什麼讓你有這個想法? 'printf()'應該可以正常工作。 –