djp
djp

Reputation: 646

How do runtime loadable kernel modules know the addresses of core kernel functions?

I would be interested in answers for both Linux and NT (or any other for that matter)

Edit:

Thanks Laurion for the answer.

More information here:

Upvotes: 1

Views: 257

Answers (2)

Peter Teoh
Peter Teoh

Reputation: 6753

Having written a loader for both windows kernel (and windows userspace) before: it works the same way. essentially all binaries have something called IAT (eg, http://msdn.microsoft.com/en-us/magazine/cc301808.aspx this is the eternal classic paper). When the loader allocated memory for the DLL it will copy the DLL there, and read the IAT of the DLL for all the symbols that it needs (by name), and then lookup the names in the export section of the Windows core DLL (eg, kernel32.dll), and fill it up with the address read. all the needed files will have to be read and address fillup, before the DLL can continue execution.

Linux works the same way too.....be it userspace or kernel. ELF structure call it relocation table.

http://www.bravegnu.org/gnu-eprog/linker.html

Hope that help :-) (the details are similar for x86 arch).

Upvotes: 0

Laurion Burchall
Laurion Burchall

Reputation: 2853

The runtime loader normally fixes up references to imported functions when the module is loaded. It looks at the table of imported functions and puts in the proper address. The module uses the imported functions through an indirection table.

Upvotes: 3

Related Questions