Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux kernel &引用;模块中的未知符号“;插入内核模块时出错_Linux Kernel_Kernel Module - Fatal编程技术网

Linux kernel &引用;模块中的未知符号“;插入内核模块时出错

Linux kernel &引用;模块中的未知符号“;插入内核模块时出错,linux-kernel,kernel-module,Linux Kernel,Kernel Module,出于教育目的,我创建了以下容易出错的内核模块 #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/proc_fs.h> #include <linux/string.h> #include <asm/uaccess.h> void *(my_funptr)(void); int bug1_w

出于教育目的,我创建了以下容易出错的内核模块

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/string.h>
#include <asm/uaccess.h>

void *(my_funptr)(void);

int bug1_write(struct file *file,
               const char *buf,
               unsigned long len) {
        my_funptr();
        return len;
}

int init_module(void) {
        static struct proc_dir_entry *proc;
        proc = create_proc_entry("bug1", 0666, 0);
        proc->write_proc = bug1_write;
        return 0;
}
他给了我:-

$ make
make -C /lib/modules/3.0.0-13-generic-pae/build M=/home/fusion/kernel_exp modules
make[1]: Entering directory `/usr/src/linux-headers-3.0.0-13-generic-pae'
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "my_funptr" [/home/fusion/kernel_exp/bug1.ko] undefined!
make[1]: Leaving directory `/usr/src/linux-headers-3.0.0-13-generic-pae'
正在尝试安装内核模块:-

$ sudo insmod bug1.ko
[sudo] password for fusion:
insmod: error inserting 'bug1.ko': -1 Unknown symbol in module
考虑到代码故意存在bug,我真的希望能够编译和插入内核模块——有没有编译器标志可以用来实现这一点?你能给我指一些我可以参考的文件吗?谢谢。

这是一个C问题

void*(my_funptr)(void);
这声明了一个名为
my_funptr
的函数,该函数返回一个指针

要声明指向函数的指针,请使用:

void(*my_funptr)(void);

您是否搜索了此问题的修复方法?我相信你会得到一个。
$ sudo insmod bug1.ko
[sudo] password for fusion:
insmod: error inserting 'bug1.ko': -1 Unknown symbol in module