我遵循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()'应该可以正常工作。 –