I'm trying to compile my kernel module that uses "ksys_close" running on Linux-5.3. The issue comes when I want to compile the module on a different machine running Linux-4.15, where the "ksys_close" doesn't exist. So I have to use the old convention "sys_close" when the kernel is older than version 4.15.
More info: https://lore.kernel.org/patchwork/patch/937297/
How can I avoid changing my code every time?
I'm a noob on kernel module programming :)
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;
Error using "ksys_close" running Linux-4.15:
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