Page 1 of 1

Modules and kernel symbols

Posted: Thu Oct 09, 2008 6:33 pm
by piranha
Over the last few days, I have been borrowing (I mean, basing my code heavily off of) Linux 1.0's module code, and module system. I have now reached the stage where I must understand kernel symbols, as (I guess) putting those functions and variables in the system call table would be a security problem.
However, I cannot understand out the module uses them. The file ksyms.S contains a list of symbols, is compiled, put through a script, and I get something like:

Code: Select all

	.data
	.globl	symbol_table_size, symbol_table

symbol_table_size:
	.long 16

symbol_table:
	.long add_syscall
	.long strings+0
	.long current_task
	.long strings+12

strings:
	.ascii "add_syscall\0"
	.ascii "current_task\0"
Which is fine, as it does compile and link into my kernel (and even works with some of my module code which references it).
But how does a module use those symbols?

-JL

Re: Modules and kernel symbols

Posted: Fri Oct 10, 2008 12:57 am
by pcmattman
When you load a module you need to fix undefined external references (modules are generally just ELF object files that aren't linked yet). To do this you need to know the name (string representation) and location of specific functions.

So if there was an external reference to, say, "memcpy", you'd search for "memcpy" and insert the address of the memcpy function into the location specified. It's obviously more complicated than that, so the ELF specification will help a lot.

I have assumed you're using ELF, if not then I can't really help much - I've only worked extensively with the ELF format.

Re: Modules and kernel symbols

Posted: Fri Oct 10, 2008 8:03 am
by piranha
I will eventually support ELF, but right now I'm just using a flat binary, as I haven't setup my kernel for ELF.

So I replace strings, OK. I'll try that out. Maybe I'll look at insmod's code or something.

-JL