Presentation is loading. Please wait.

Presentation is loading. Please wait.

Kernel Modules Giving your Linux more pop since 1995.

Similar presentations


Presentation on theme: "Kernel Modules Giving your Linux more pop since 1995."— Presentation transcript:

1 Kernel Modules Giving your Linux more pop since 1995

2 History Introduced in Linux version 1.2 (1995) At the time, drivers were already designed to be somewhat modular, so not a lot of work was needed to revamp one driver for use as a LKM. There are a lot of drivers, though... By 2000, most drivers and “module-able” things are converted.

3 What are Modules A Module is a object file that contains code to extend the functionality of the base kernel. Modules are used to add support for new hardware and file systems. Also used to add new system calls and executable interpreters.

4 Why are they Important? If modules did not exist then adding new features to the kernel would be nearly impossible. Remember the systemCall() project???

5 Pros and Cons Pros: –Time savings –Portability –Memory savings –Security (PAM) Cons –No safeguards –Security (rootkits)

6 Modules vs. Applications Modules are really a part of the kernel and so run in kernel space. Apps just do their tasks and end. Modules sit in the kernel space waiting to be run. Apps can be linked to outside libraries; modules can only "see" in the kernel and other loaded modules.

7 Module Loading Kernel Symbol Table: references kernel functions that modules can use. When loaded, unresolved symbols in module are linked to system table EXPORT_SYMBOL() allows specified symbol to be used by kernel and other modules. Use cat /proc/kallsyms to get a list of all exported kernel symbols.

8 Image from: http://www.xml.com/ldd/chapter/book/ch02.html

9 Module HOW-TO Some useful commands –insmodinsert module into kernel –rmmodremove kernel module –lsmodshow currently loaded modules The above work, but are dumb. Instead, use modprobe [-r] which is aware of module dependencies and config settings. Use depmod to find module dependencies. File location: /lib/modules/version/modules.dep

10 Building the Module The steps taken depend on whether you want your module in the kernel tree or not Living in the tree –The LKD book explains this well with the Fish Master example (pg 281) –Quickly: put module in drivers/ directory, edit/create Makefile so module is built, make Kconfig file if you have config options for module.

11 Example Files config SOME_OPTION tristate “Enable some option” default n help A file like this must be with your module. Go to Kconfig above this and add: source “this/directory/Kconfig” Kconfig: Makefile: #in module directory obj-$(CONFIG_SOME_OPTION) += myModule.o myModule-objs := leroy.o jenkins.o #edit makefile above module directory obj-m += directory/

12 Makefile goes with module source. The difference is in the compilation: –make -C /kernel/source/location SUBDIRS=$PWD modules –/kernel/source/location is the location of your kernel source tree –Be sure that your kernel source is configured and built And now for an example... Building Outside Tree #similar to before #Note the := rather than += on next line obj-m := hellomod.o hellomod-objs := goodbye.o hi.o

13 References The Linux Kernel Module Programming Guide http://www.faqs.org/docs/kernel/ Wikipedia: Linux Kernel http://en.wikipedia.org/wiki/Linux_kernel Wikipedia: Linux Modules http://en.wikipedia.org/wiki/Module_(Linux) Linux Device Drivers: Building and Running Modules http://www.xml.com/ldd/chapter/book/ch02.html Linux Loadable Kernel Module HOWTO http://www.tldp.org/HOWTO/Module-HOWTO/ Linux PAM page http://www.kernel.org/pub/linux/libs/pam/whatispam.html Linux Kernel Development. Ch. 16: Modules. pp.279-289 Linux Kernel Cross-Reference http://lxr.linux.no/


Download ppt "Kernel Modules Giving your Linux more pop since 1995."

Similar presentations


Ads by Google