2017-12-21 21 views
2

Ich muss einige Funktionalität zu einem vorhandenen Gerät (Mips Arch) hinzufügen - Ich habe versucht, mehrere SDKs und in diesem Moment habe ich ein wenig Fortschritte, aber: Insmod zurück 0 (Erfolg) und lsmod zeigt sie, aber aither printk noch create_proc_entry funktioniert nicht .... ABER ich habe Abschnitt .gnu.linkonce.this_module angesehen: außer Modulname - es gibt keine nützlichen Informationen - Abschnitt ist mit 0x0 gefülltKernelmodul in nicht geladen (aber Insmod gibt 0 zurück)

Ich habe festgestellt, dass in nativen .ko-Dateien in Gerätegröße von Abschnitt .gnu.linkonce.this_module ist kleiner in 8 Bytes - aber nach der Tatsache, dass Abschnitt für das temporäre Laden von Informationen zu Strukturmodul verwendet wird - gibt es nicht wichtig in meiner Meinung ...

https://ufile.io/eco1s Es gibt mehrere Dateien: khelloworld.ko - mein Helloworld-Modul - versuche, einen procfs-Eintrag zu erstellen khelloworld.ko - versuche, eine Datei in den nativen Modulen rootfs (/tmp/test.file) zu erstellen: xt_mark.ko md5.ko cbc. ko

ich habe Kernelkonfiguration nicht - aber ich brauche das Modul zu kompilieren ... ich weiß nur die Version

#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; 
} 
+1

Willkommen bei Stack Overflow! Hier wollen wir Code in Frage und andere Informationen (wie Build-Logs) ** in die Frage selbst eingefügt werden **, nicht verknüpft. Beheben Sie dieses Problem, indem Sie Ihre Frage bearbeiten. – Tsyvarev

Antwort

3

readelf -a zeigt, dass die Verlagerung Eintrag für Ihre init-Funktion anders als in der natives Modulgehäuse:

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 

Beachten Sie, dass der Zeiger init_module für die nativen Module im Offset 0xbc der Struktur module steht, während er in Ihrem Modul im Offset 0xac ist. Daher findet der Loader Ihre Init-Funktion nicht und ruft sie nicht auf.

Wie erklärt here, ist dies wahrscheinlich das Ergebnis einer Kernel-Konfiguration Unterschied zwischen Ihrer Build-Umgebung und der nativen Build-Umgebung. Es ist sehr wahrscheinlich, dass CONFIG_UNUSED_SYMBOLS der Schuldige ist (siehe die module Definition here).

Alternativ können Sie (auf eigene Verantwortung!) Einen Binär-Patch auf das resultierende Modul anwenden, um die 0xac in 0xbc zu ändern.

Verwandte Themen