Modules and kernel symbols

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Modules and kernel symbols

Post 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
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Modules and kernel symbols

Post 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.
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: Modules and kernel symbols

Post 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
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
Post Reply