【问题标题】:How to compile <linnux/kernel.h> in Linux gcc compiler?如何在 Linux gcc 编译器中编译 <linnux/kernel.h>?
【发布时间】:2013-10-22 16:58:25
【问题描述】:

我有一个简单的问题。我要编译以下c文件:

#include <linux/kernel.h>
#include <linux/module.h>
#include <sys/syscall.h>

extern void *sys_call_table[];


asmlinkage int (*original_sys_open)(int);

asmlinkage int our_fake_open_function(int error_code)
{

        /*print message on console every time we
 *          *are called*/
        printk("HEY! sys_open called with error_code=%d\n",error_code);

        /*call the original sys_exit*/
        return original_sys_open(error_code);
}

/*this function is called when the module is
*  *loaded (initialization)*/
int init_module()
{
        /*store reference to the original sys_exit*/
        original_sys_open=sys_call_table[__NR_open];

        /*manipulate sys_call_table to call our
 *          *fake exit function instead
 *                   *of sys_exit*/
        sys_call_table[__NR_open]=our_fake_open_function;
}


/*this function is called when the module is
 *  *unloaded*/
void cleanup_module()
{

        /*make __NR_exit point to the original
 *          *sys_exit when our module
 *                   *is unloaded*/
        sys_call_table[__NR_open]=original_sys_open;

}

问题是 gcc -I/usr/src/kernels/2.6.32-279.el6.x86_64/include myfile.c 生成一个不可解决的包含依赖项,可以在 . 请告诉我如何解决我今天遇到的这个 gcc 编译器问题。非常感谢您的洞察力。

【问题讨论】:

  • 这段代码行不通,因为系统调用表既不导出也不可写,open参数错误。

标签: linux gcc linux-kernel


【解决方案1】:

如何构建外部模块记录在the documentation

$ make -C <path_to_kernel_src> M=$PWD

【讨论】:

    猜你喜欢
    • 2014-11-14
    • 1970-01-01
    • 2023-03-10
    • 2019-06-09
    • 1970-01-01
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多