Linux kernel 未加载中的内核模块(但insmod返回0)

Linux kernel 未加载中的内核模块(但insmod返回0),linux-kernel,mips,router,mips32,Linux Kernel,Mips,Router,Mips32,我必须向现有设备(mips arch)添加一些功能-我尝试了几个SDK,目前我取得了一些进展,但是: insmod返回0(成功),lsmod显示它们,但aither printk或create\u proc\u条目不起作用。。。。但是我已经查看了section.gnu.linkonce.this_模块:除了模块名-没有有用的信息-该部分用0x0填充 我发现在设备大小为.gnu.linkonce.section的本机.ko文件中,该模块小于8字节,但根据该节用于将信息临时加载到结构模块的事实,我的

我必须向现有设备(mips arch)添加一些功能-我尝试了几个SDK,目前我取得了一些进展,但是: insmod返回0(成功),lsmod显示它们,但aither printk或create\u proc\u条目不起作用。。。。但是我已经查看了section.gnu.linkonce.this_模块:除了模块名-没有有用的信息-该部分用0x0填充

我发现在设备大小为.gnu.linkonce.section的本机.ko文件中,该模块小于8字节,但根据该节用于将信息临时加载到结构模块的事实,我的建议中没有任何问题

有几个文件:khelloworld.ko-我的helloworld模块-尝试创建procfs条目khelloworld.ko-尝试在rootfs(/tmp/test.file)本机模块中创建文件:xt_mark.ko md5.ko cbc.ko

我没有内核配置-但我需要编译该模块。。。我只知道这个版本

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>  /* Necessary because we use the proc fs */
#include <linux/init.h>     /* Needed for the macros */

#define procfs_name "khelloworld"


MODULE_LICENSE("GPL");
MODULE_INFO(vermagic, "2.6.32.68 mod_unload MIPS32_R2 32BIT ");
MODULE_AUTHOR     ("XAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");


struct proc_dir_entry *Our_Proc_File;

static int
procfile_read(char *buffer,
      char **buffer_location,
      off_t offset, int buffer_length, int *eof, void *data);

    static int __init khelloworld_init( void ) {
    printk(KERN_INFO "try to create /proc \n"); 
    Our_Proc_File = create_proc_entry(procfs_name, 0644, NULL);

    if (Our_Proc_File == NULL) {
        remove_proc_entry(procfs_name, NULL);
        printk(KERN_ALERT "Error: Could not initialize /proc/%s\n",
           procfs_name);
        return -ENOMEM;
    }

    Our_Proc_File->read_proc = procfile_read;
    Our_Proc_File->owner     = THIS_MODULE;
    Our_Proc_File->mode      = S_IFREG | S_IRUGO;
    Our_Proc_File->uid       = 0;
    Our_Proc_File->gid       = 0;
    Our_Proc_File->size      = 37;

    printk(KERN_INFO "/proc/%s created\n", procfs_name);    
    return 3;   /* everything is ok */
}

static void __exit khelloworld_exit( void ) {
    remove_proc_entry(procfs_name, NULL);
    printk(KERN_INFO "/proc/%s removed\n", procfs_name);
}


module_init(khelloworld_init);
module_exit(khelloworld_exit);

int
procfile_read(char *buffer,
      char **buffer_location,
      off_t offset, int buffer_length, int *eof, void *data)
{
    int ret;

    printk(KERN_INFO "procfile_read (/proc/%s) called\n", procfs_name);

    /* 
     * We give all of our information in one go, so if the
     * user asks us if we have more information the
     * answer should always be no.
     *
     * This is important because the standard read
     * function from the library would continue to issue
     * the read system call until the kernel replies
     * that it has no more information, or until its
     * buffer is filled.
     */
    if (offset > 0) {
        /* we have finished to read, return 0 */
        ret  = 0;
    } else {
        /* fill the buffer, return the buffer size */
        ret = sprintf(buffer, "HelloWorld!\n");
    }

    return ret;
}
#包括
#包括
#包括/*必要,因为我们使用proc fs*/
#包含宏所需的/**/
#定义procfs_名称“khelloworld”
模块许可证(“GPL”);
模块信息(vermagic,“2.6.32.68模块卸载MIPS32\U R2 32位”);
模块作者(“XAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”);
struct proc\u dir\u entry*我们的\u proc\u文件;
静态整数
procfile_读取(字符*缓冲区,
字符**缓冲区位置,
off_t offset,int buffer_length,int*eof,void*data);
静态整数初始化khelloworld初始化(void){
printk(KERN_INFO“尝试创建/proc\n”);
我们的\u Proc\u文件=创建\u Proc\u条目(procfs\u name,0644,NULL);
if(我们的_Proc_文件==NULL){
删除\u proc\u条目(procfs\u名称,空);
printk(内核警报“错误:无法初始化/proc/%s\n”,
procfs_name);
return-ENOMEM;
}
我们的程序文件->读取程序=程序文件读取;
我们的\u Proc\u File->owner=此\u模块;
我们的程序文件->模式=S|IFREG | S|IRUGO;
我们的程序文件->uid=0;
我们的程序文件->gid=0;
我们的程序文件->大小=37;
printk(KERN\u INFO)/proc/%s已创建\n“,procfs\u名称);
返回3;/*一切正常*/
}
静态void uu出口khelloworld u出口(void){
删除\u proc\u条目(procfs\u名称,空);
printk(内核信息“/proc/%s已删除\n”,procfs\u名称);
}
模块初始化(khelloworld初始化);
模块出口(khelloworld出口);
int
procfile_读取(字符*缓冲区,
字符**缓冲区位置,
off_t offset,int buffer_length,int*eof,void*data)
{
int ret;
printk(KERN\u INFO“procfile\u read(/proc/%s)调用\n”,procfs\u name);
/* 
*我们一次性提供所有信息,因此如果
*用户询问我们是否有更多信息
*答案应该总是否定的。
*
*这一点很重要,因为标准
*图书馆的职能将继续发布
*读取系统调用,直到内核响应为止
*它没有更多的信息,或者直到
*缓冲区已满。
*/
如果(偏移量>0){
/*我们已完成读取,返回0*/
ret=0;
}否则{
/*填充缓冲区,返回缓冲区大小*/
ret=sprintf(缓冲区,“HelloWorld!\n”);
}
返回ret;
}

readelf-a
显示init函数的重新定位条目与本机模块不同:

xt_mark.ko

Relocation section '.rel.gnu.linkonce.this_module' at offset 0x958 contains 2 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
000000bc  00001502 R_MIPS_32         00000000   init_module
00000130  00001402 R_MIPS_32         00000000   cleanup_module


khelloworld.ko

Relocation section '.rel.gnu.linkonce.this_module' at offset 0xafc contains 2 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
000000ac  00002502 R_MIPS_32         00000000   init_module
0000010c  00002402 R_MIPS_32         00000000   cleanup_module
请注意,对于本机模块,
init_模块
指针位于
module
结构的偏移量0xbc中,而在您的模块中它位于偏移量0xac中。因此,加载程序找不到您的init函数,也不会调用它

如前所述,这可能是构建环境和本机构建环境之间的内核配置差异造成的。很可能是
CONFIG\u UNUSED\u SYMBOLS
造成的(请参阅
模块
定义)


或者,您可以(自行承担风险!)对生成的模块应用二进制补丁,将0xac更改为0xbc。

欢迎使用堆栈溢出!在这里,我们希望问题代码和其他信息(如构建日志)包含在问题帖子中,而不是链接。通过解决你的问题来解决这个问题。