Android可加載內核模塊錯誤:賦值使指針從沒有強制轉換的整數 (Android Loadable Kernel Module Error: assignment makes integer from pointer without a cast)


問題描述

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 user1268467Kristof Provost)

參考文件

  1. Android Loadable Kernel Module Error: assignment makes integer from pointer without a cast (CC BY‑SA 3.0/4.0)

#linux-kernel #Android






相關問題

選擇 Linux I/O 調度程序 (Selecting a Linux I/O Scheduler)

Android可加載內核模塊錯誤:賦值使指針從沒有強制轉換的整數 (Android Loadable Kernel Module Error: assignment makes integer from pointer without a cast)

文件描述符中實際存儲了多少信息? (How much information is actually stored in a file descriptor?)

hrtimer mengulangi tugas di kernel Linux (hrtimer repeating task in the Linux kernel)

我可以在 C 代碼中使用 LKM 內核代碼中的“getpwuid”嗎? (Can I use "getpwuid" from kernel code in LKM in c code?)

將傳入數據包注入網絡接口 (Injecting an incoming packet to a network interface)

無法從 D3 睡眠狀態喚醒 pci 總線 (Unable to wake pci bus form D3 sleep satate)

在 Linux 中使用 DMA 的最簡單方法 (Easiest way to use DMA in Linux)

Linux I2C 通信問題 (Linux I2C communication issues)

理解 perf stat 輸出中的數字 (Make sense of numbers in perf stat output)

我如何在 amazon Linux AMI 上找到我的 Linux 發行版? (How i could find my Linux distribution on amazon Linux AMI?)

將參數傳遞給系統調用 (Passing arguments to system calls)







留言討論