LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   exporting the kernels linked list (https://www.linuxquestions.org/questions/linux-kernel-70/exporting-the-kernels-linked-list-4175506477/)

ramzi.kahil 05-30-2014 02:45 AM

exporting the kernels linked list
 
I want to make a proof of concept and for easier development I would like to export the linked list methods which are in "include/linux/list.h". But I get the error below if I remove the "static" from the functions declaration. Also the exported functions cannot be static. (I have for now tried to just export the "add_list" method.) So:

Why can the add_list method be non-static?
What can I do?

The error while compiling the kernel with a non-static "list_add" method:

Code:

init/do_mounts_initrd.o: In function `list_add':
/usr/src/linux-3.14.2/include/linux/list.h:63: multiple definitions of `list_add'
init/do_mounts.o:/usr/src/linux-3.14.2/include/linux/list.h:63: first defined here
make[1]: *** [init/mounts.o] Error 1
make: *** [init] Error 2


** My main goal is to export the symbols and then use kprobes to hook these functions via kernel modules, and develop my proof of concept without recompiling the kernel every time from scratch. Of curse after I am happy with what I did, I will recommend putting the code into the kernel and removing the export.

dijetlo 06-01-2014 02:12 AM

Quote:

/usr/src/linux-3.14.2/include/linux/list.h:63: multiple definitions of `list_add'
init/do_mounts.o:/usr/src/linux-3.14.2/include/linux/list.h:63: first defined here
init/do_mounts.o:/usr/src/linux-3.14.2/include/linux/list.h:63: first defined here
Well, I'm just a moron, but that seems to indicate your call to "list_add" didn't work because you have multiple definitions of the same class, which is fine if you're overloading a constructor, but apparently you went beyond what's wise.
If you want it to take a pointer, create a child class that takes pointers but give it another name.

ramzi.kahil 06-01-2014 02:52 AM

I think I may have not explained good enough what I did, because I didn't add any thing. The only thing I did was going to the file "include/linux/list.h" and remove the word "static" which appears in the definition of the function "add_list" and then re-compiled the kernel. The error above appeared.

dijetlo 06-01-2014 03:40 AM

That's because if it isn't static, it's being redefined everywhere it appears in your code (not to mention in the header files)
It would seem a better option to create a child class for it, leave the original code alone, and work with that otherwise your looking at re-writing a significant portion of the linux kernel code.

ramzi.kahil 06-02-2014 02:28 AM

OK, that helps a lot. But what do you mean by creating a child class? I don't know how this is done in C language.

dijetlo 06-02-2014 04:39 AM

Quote:

But what do you mean by creating a child class?
Create a non-static variable that references the same structures as list add, though I'm not suggesting that will work. There is probably a reason it was designated a static variable to begin with, the most common being you can't manipulate it.
I'd start there.


All times are GMT -5. The time now is 07:29 AM.