Tag: 模块

编译内核模块,头文件问题,makefile问题

好吧,我正在尝试编译一个简单的内核模块,当我指向包含包含的任何下面的内容时,它会抱怨各种各样的东西。 linux-headers-2.6.31-21 linux-headers-2.6.31-22 linux-headers-2.6.31-21-generic linux-headers-2.6.31-22-generic linux-headers-2.6.31-21-generic-pae linux-headers-2.6.31-22-generic-pae 我正在尝试按照以下网站上的说明操作: http : //www.faqs.org/docs/kernel/x145.html 我更新了make文件,如下所示: TARGET := hello_world WARN := -W -Wall -Wstrict-prototypes -Wmissing-prototypes INCLUDE := -isystem /usr/src/linux-headers-2.6.31-22-generic/include CFLAGS := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE} CC := gcc ${TARGET}.o: ${TARGET}.c .PHONY: clean clean: rm -rf ${TARGET}.o 例如,当我输入make时,我得到以下错误以及更多,调查文件夹,我看到处理器和缓存文件是asm-generic,如果它不指向,我应该如何编译它文件的正确位置? /usr/src/linux-headers-2.6.31-22-generic/include/linux/prefetch.h:14:27: error: asm/processor.h: No such file or directory /usr/src/linux-headers-2.6.31-22-generic/include/linux/prefetch.h:15:23: error: asm/cache.h: […]

C – Linux – 内核模块 – TCP标头

我正在尝试创建linux内核模块,它将检查传入的数据包。 目前,我正在提取数据包的TCP头并读取源和目标端口 – >但是我得到的值不正确。 我有钩function: unsigned int hook_func(unsigned int hooknum, struct sk_buff *skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *)) { struct iphdr *ipp = (struct iphdr *)skb_network_header(skb); struct tcphdr *hdr; /* Using this to filter data from another machine */ unsigned long ok_ip = 2396891328; /* Some problem, empty […]

加载的库函数如何在主应用程序中调用符号?

加载共享库时,通过函数dlopen()打开,有没有办法在主程序中调用函数?

未定义的符号:在C中嵌入Python时的PyExc_ImportError

我正在开发一个调用python脚本的C共享库。 当我运行应用程序时,我收到此错误: Traceback (most recent call last): File “/home/ubuntu/galaxy-es/lib/galaxy/earthsystem/gridftp_security/gridftp_acl_plugin.py”, line 2, in import galaxy.eggs File “/home/ubuntu/galaxy-es/lib/galaxy/eggs/__init__.py”, line 5, in import os, sys, shutil, glob, urllib, urllib2, ConfigParser, HTMLParser, zipimport, zipfile File “/usr/lib/python2.7/zipfile.py”, line 6, in import io File “/usr/lib/python2.7/io.py”, line 60, in import _io ImportError: /usr/lib/python2.7/lib-dynload/_io.so: undefined symbol: PyExc_ImportError 如果我尝试从控制台导入模块io工作正常: Python 2.7.1+ (r271:86832, Apr 11 […]

如果cmd = 2,则不调用ioctl

我正在开发一个使用unlocked_ioctl的内核模块。 我用内核版本2.6.24-23-generic测试了它,它运行得很好。 现在我尝试使用内核版本3.3.1-1-ARCH并发生一些奇怪的事情:当请求值(cmd)为2时,不会执行ioctl函数。它返回0,但函数未执行。 为了检查它是否未执行,我执行了以下操作: static long midriver_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { printk(“Called with cmd = %d\n”, cmd); 我写了一个测试程序,从0到4096调用此设备的ioctl,我可以在dmesg中看到所有这些值的消息“用cmd = n调用”,除了“2”,唯一没有显示的值。 关于我做错了什么的线索? 先感谢您,

内核模块上的addr2line

我正在尝试调试内核模块。 我怀疑有一些内存泄漏。 为了检查它,我准备了内核和模块的内存泄漏调试的构建。 我得到了一些警告: [11839.429168] slab error in verify_redzone_free(): cache `size-64′: memory outside object was overwritten [11839.438659] [] (unwind_backtrace+0x0/0x164) from [] (kfree+0x278/0x4d8) [11839.447357] [] (kfree+0x278/0x4d8) from [] (some_function+0x18/0x1c [my_module]) [11839.457214] [] (some_function+0x18/0x1c [my_module]) from [] (some_function+0x174/0x718 [my_module]) [11839.470184] [] (some_function+0x174/0x718 [my_module]) from [] (some_function+0x12c/0x16c [my_module]) [11839.483917] [] (some_function+0x12c/0x16c [my_module]) from [] (some_function+0x8/0x10 [my_module]) [11839.496368] [] […]

如何从另一个模块调用导出的内核模块函数?

我正在编写一个API作为内核模块,为设备驱动程序提供各种function。 我在mycode.c中写了三个函数。 然后我构建并加载了模块,然后将mycode.h复制到 / include / linux中 。 在设备驱动程序中,我有一个#include 并调用这三个函数。 但是当我构建驱动程序模块时,我收到三个链接器警告,说明这些函数是未定义的 。 笔记: 函数在mycode.h中声明为extern 使用mycode.c中的EXPORT_SYMBOL(func_name)导出函数 运行命令nm mycode.ko显示符号表中可用的所有三个函数(它们旁边的大写字母T,表示符号在文本(代码)部分中找到) 加载模块后,命令grep func_name / proc / kallsyms将所有三个函数显示为已加载 很明显,函数正确导出,内核知道它们的位置和位置。 那么为什么司机不能看到他们的定义呢? 知道我错过了什么吗? 编辑:我在这里找到了一些相关信息: http : //www.kernel.org/doc/Documentation/kbuild/modules.txt 有时,外部模块使用来自另一个外部模块的导出符号。 kbuild需要完全了解所有符号,以避免吐出有关未定义符号的警告。 这种情况存在三种解决方案。 注意:建议使用顶级kbuild文件的方法,但在某些情况下可能不切实际。 使用顶级kbuild文件如果你有两个模块,foo.ko和bar.ko,其中foo.ko需要来自bar.ko的符号,你可以使用一个通用的顶层kbuild文件,所以这两个模块都是用同一个编译的建立。 请考虑以下目录布局: ./foo/ <= contains foo.ko ./bar/ <= contains bar.ko The top-level kbuild file would then look like: #./Kbuild (or ./Makefile): […]