問題描述
Android可加載內核模塊錯誤:賦值使指針從沒有強制轉換的整數 (Android Loadable Kernel Module Error: assignment makes integer from pointer without a cast)
I got an Android LKM for my HTC Sensation XL as below, it will print a debug message before sys_open called. My OS is Ubuntu 11.10 64bit. Android Kernel is runnymede‑crc‑2.6.35 downloaded from http://www.htcdev.com/devcenter/downloads .
/* * mydebug.c * System Call sys_open dubugging */
#include <linux/kernel.h>
#include <linux/module.h>
#include <asm/unistd.h>
asmlinkage ssize_t (*orig_open)(const char *pathname, int flags);
asmlinkage ssize_t hooked_open(const char *pathname, int flags)
{
printk(KERN_INFO "SYS_OPEN: %s\n", pathname);
return orig_open(pathname, flags);
}
static int __init root_start(void)
{
unsigned long sys_addr = 0xc003b104; /* System.map */
unsigned long *sys_call_table= (unsigned long *)sys_addr;
orig_open = sys_call_table[__NR_open];
sys_call_table[__NR_open] = hooked_open;
return 0;
}
static void __exit root_stop(void)
{
unsigned long sys_addr = 0xc003b104;
unsigned long *sys_call_table= (unsigned long *)sys_addr;
sys_call_table[__NR_open] = &orig_open;
}
module_init(root_start);
module_exit(root_stop);
But it shows errors during compiling,
make ‑C /home/scott/runnymede‑crc‑2.6.35/ M=$(PWD) ARCH=arm CROSS_COMPILE=~/android‑ndk‑r7b/toolchains/arm‑linux‑androideabi‑4.4.3/prebuilt/linux‑x86/bin/arm‑linux‑androideabi‑ modules
make[1]: Entering directory '/home/scott/runnymede‑crc‑2.6.35'
CC [M] /home/scott/workspace/debugkit/mydebug.o
cc1: warnings being treated as errors
/home/scott/workspace/debugkit/mydebug.c: In function 'root_start':
/home/scott/workspace/debugkit/mydebug.c:23: error: assignment makes pointer from integer without a cast
/home/scott/workspace/debugkit/mydebug.c:24: error: assignment makes integer from pointer without a cast
/home/scott/workspace/debugkit/mydebug.c: In function 'root_stop':
/home/scott/workspace/debugkit/mydebug.c:34: error: assignment makes integer from pointer without a cast
make[2]: [/home/scott/workspace/debugkit/mydebug.o] Error 1
make[1]: [_module_/home/scott/workspace/debugkit] Error 2
make[1]: Leaving directory '/home/scott/runnymede‑crc‑2.6.35'
make: [default] Error 2
Anyone can help me?
‑‑‑‑‑
參考解法
方法 1:
You defined sys_call_table
as a pointer to an unsigned long, then do sys_call_table[1234]
. The resulting type is an unsigned long. You try to assign a pointer to this.
That's exactly what the compiler is telling you. Either redefine the type of sys_call_table
or cast the assignment.
Note that replacing syscalls is deeply frowned upon, especially from kernel modules. The fact that you have to do silly things like use a hard coded address from system.map should be taken as a hint that you shouldn't be doing it in the first place.
(by user1268467、Kristof Provost)