确定驱动程序模块所在的位置(内存地址)

时间:2013-12-19 02:41:57

标签: c linux kernel driver memory-address

当动态加载linux内核驱动程序时,我们如何编写C函数来报告驱动程序模块所在的位置(内存地址)?

这更适用于Windows,但是,如果我们适应类似的Linux驱动程序那会有用吗?

    long sizeOfExe = 0;   
    FILE *fp;

    fp = fopen("./Mini.ko", "rb"); // reading itself

    fseek(fp, 0L, SEEK_END);
    sizeOfExe = ftell(fp);

    printf("The size of this driver module is: %ld bytes\n", sizeOfExe);   
    int* addressStartOfFile = &fp;
    printf("Location of this driver module starts at: 0x%x\n", addressStartOfFile);        
    printf("Location of this driver module ends at: 0x%x\n", (addressStartOfFile+sizeOfExe));

/*
The size of this driver module is: 18727 bytes
Location of this driver module starts at: 0x28ff30
Location of this driver module ends at: 0x2a23cc
*/

1 个答案:

答案 0 :(得分:0)

  

当动态加载linux内核驱动程序时,我们如何编写C语言   函数报告驱动程序所在的位置(内存地址)   模块正在居住?

我们写它来阅读(通过popen()等)shell命令的输出或转换成C命令

grep '\[modulename]' /proc/k*syms | sort