翻ldd3书看得云里雾里的,幸好有源码,可以找到源码,编译一下,自己动手学习ldd3到底讲了些什么知识。找到一份源码后,运行起来再说,不管是白猫还是黑猫,要抓老鼠,你得先得给我跑起来,哈哈!
上一篇给出了ldd3下载地址,下载examples.tar.gz解压有以下子目录
include Makefile pci scullc scullv simple tty lddbus misc-modules sbull sculld short skull usb LICENSE misc-progs scull scullp shortprint snull
Makefile simple.c simple_load simple_unload
Makefile,simple_load,simple_unload书中的讲解比较详细,不懂的杜娘或者google,其实有些我也不懂。
bory@chong:~/ldd3/test/simple$ make make -C /lib/modules/2.6.32-37-generic/build M=/home/fang/ldd3/test/simple LDDINCDIR=/home/fang/ldd3/test/simple/../include modules make[1]: 正在进入目录 `/usr/src/linux-headers-2.6.32-37-generic' scripts/Makefile.build:49: *** CFLAGS was changed in "/home/fang/ldd3/test/simple/Makefile". Fix it to use EXTRA_CFLAGS。 停止。 make[1]: *** [_module_/home/fang/ldd3/test/simple] 错误 2 make[1]:正在离开目录 `/usr/src/linux-headers-2.6.32-37-generic' make: *** [default] 错误 2
因源码是针对linux内核2.6.10以下版本的,bory和您用的版本都高于2.6.10版本。所以在编译源码时会出现很多版本相关的错误。上面的错误的
解决方案:
将Makefile文件中的“CFLAGS”替换成“EXTRA_CFLAGS”
保存继续编译。
bory@chong:~/ldd3/test/simple$ make make -C /lib/modules/2.6.32-37-generic/build M=/home/fang/ldd3/test/simple LDDINCDIR=/home/fang/ldd3/test/simple/../include modules make[1]: 正在进入目录 `/usr/src/linux-headers-2.6.32-37-generic' CC [M] /home/fang/ldd3/test/simple/simple.o /home/fang/ldd3/test/simple/simple.c:18:26: error: linux/config.h: 没有那个文件或目录 /home/fang/ldd3/test/simple/simple.c: In function ‘simple_vma_nopage’: /home/fang/ldd3/test/simple/simple.c:115: error: ‘NOPAGE_SIGBUS’ undeclared (first use in this function) /home/fang/ldd3/test/simple/simple.c:115: error: (Each undeclared identifier is reported only once /home/fang/ldd3/test/simple/simple.c:115: error: for each function it appears in.) /home/fang/ldd3/test/simple/simple.c: At top level: /home/fang/ldd3/test/simple/simple.c:128: error: unknown field ‘nopage’ specified in initializer /home/fang/ldd3/test/simple/simple.c:128: warning: initialization from incompatible pointer type make[2]: *** [/home/fang/ldd3/test/simple/simple.o] 错误 1 make[1]: *** [_module_/home/fang/ldd3/test/simple] 错误 2 make[1]:正在离开目录 `/usr/src/linux-headers-2.6.32-37-generic' make: *** [default] 错误 2
linux/config.h这个文件不存在。这是因为config.h这个文件在新版本已经被移除。
解决方案:
将simple.c的头文件config.h注销掉
//#include <linux/config.h>
继续编译
bory@chong:~/ldd3/test/simple$ make make -C /lib/modules/2.6.32-37-generic/build M=/home/fang/ldd3/test/simple LDDINCDIR=/home/fang/ldd3/test/simple/../include modules make[1]: 正在进入目录 `/usr/src/linux-headers-2.6.32-37-generic' CC [M] /home/fang/ldd3/test/simple/simple.o /home/fang/ldd3/test/simple/simple.c: In function ‘simple_vma_nopage’: /home/fang/ldd3/test/simple/simple.c:115: error: ‘NOPAGE_SIGBUS’ undeclared (first use in this function) /home/fang/ldd3/test/simple/simple.c:115: error: (Each undeclared identifier is reported only once /home/fang/ldd3/test/simple/simple.c:115: error: for each function it appears in.) /home/fang/ldd3/test/simple/simple.c: At top level: /home/fang/ldd3/test/simple/simple.c:128: error: unknown field ‘nopage’ specified in initializer /home/fang/ldd3/test/simple/simple.c:128: warning: initialization from incompatible pointer type make[2]: *** [/home/fang/ldd3/test/simple/simple.o] 错误 1 make[1]: *** [_module_/home/fang/ldd3/test/simple] 错误 2 make[1]:正在离开目录 `/usr/src/linux-headers-2.6.32-37-generic' make: *** [default] 错误 2
又是错误。看来内核版本不匹配,带来的麻烦真不少阿。未定义NOPAGE_SIGBUS和nopage。因新版本vm_operations_struct去掉了nopage成员。我们这里也去掉她。
解决方案:
编辑simple.c,找到return NOPAGE_SIGBUS; 这一行,作如下改动。(因为这个方法我们不会用到,返回NULL没关系的)
//return NOPAGE_SIGBUS; return NULL;再找到.nopage = simple_vma_nopage,这一行,作如下改动
//.nopage = simple_vma_nopage,因为新内核版本在vm_operations_struct去掉了nopage成员
joydev 11104 0
。。。
如有错误之处,请您指出,谢谢您的不吝赐教!