我正在尝试编译使用在Linux-5.3上运行的“ ksys_close”的内核模块。当我想在运行Linux-4.15的另一台机器上编译模块时,就会出现问题,其中“ ksys_close”不存在。因此,当内核早于版本4.15时,我必须使用旧的约定“ sys_close”。
更多信息:https://lore.kernel.org/patchwork/patch/937297/
如何避免每次都更改代码?
我是内核模块编程方面的菜鸟:)
Makefile:
obj-m += interceptor.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
linux-4.15
if (sct[__NR_close] == (unsigned long *) sys_close)
return sct;
linux-5.3
if (sct[__NR_close] == (unsigned long *) ksys_close)
return sct;
使用运行Linux-4.15的“ ksys_close”时出错:
make -C /lib/modules/4.15.0-58-generic/build M=/root/module modules
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-58-generic'
CC [M] /root/module/interceptor.o
/root/module/interceptor.c: In function ‘aquire_sys_call_table’:
/root/module/interceptor.c:30:44: error: ‘ksys_close’ undeclared (first use in this function); did you mean ‘sys_close’?
if (sct[__NR_close] == (unsigned long *) ksys_close)
^~~~~~~~~~
sys_close
/root/module/interceptor.c:30:44: note: each undeclared identifier is reported only once for each function it appears in
scripts/Makefile.build:337: recipe for target '/root/module/interceptor.o' failed
make[2]: *** [/root/module/interceptor.o] Error 1
Makefile:1562: recipe for target '_module_/root/module' failed
make[1]: *** [_module_/root/module] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-58-generic'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2