Download presentation
Presentation is loading. Please wait.
1
CS 6560 Operating System Design
Lecture 14 Kernel Modules
2
References Textbook, chapter 16
3
Kernel Modules Are you tired of waiting for your kernel to compile?
Kernel modules provide a way to quickly modify a running kernel. They can be separately compiled and be dynamically added and be removed. When added they become part of the kernel with access to the rest of the kernel.
4
Kernel Module Structure
Kernel modules consist of An initialization routine that is called when the module is loaded An exit routine that is called when the module is removed. Functions and variables that can be exported for use by other parts of the kernel, including other modules. Meta data that can be accessed by tools and the kernel.
5
Starting Example Here is an example of kernel module that has the basic structure. //* */ /* File: CS6560_LKM.c Example of a loadable kernel module that initializes, exports functions, and exits. */ /* Standard headers for LKMs */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/moduleparam.h> #include "CS6560_LKM.h" int init_CS6560_module(void); void exit_CS6560_module(void); /* Initialize the LKM */ int init_CS6560_module() { printk(KERN_ALERT "CS6560_LKM_one: init_CS6560_module\n"); return 0; } /* Exit the LKM */ void exit_CS6560_module() printk("CS6560_LKM_one: exit_CS6560_module\n"); /* Example exported function */ int CS6560_LKM_function1(int arg1) printk("CS6560_LKM_one: CS6560_LKM_function1\n"); EXPORT_SYMBOL(CS6560_LKM_function1); module_init(init_CS6560_module); module_exit(exit_CS6560_module); MODULE_LICENSE("GPL"); MODULE_AUTHOR("CS6560 at CSUEB"); /* */
6
Points printw and Kernel loglevels - see man pages for syslogd and klogctl. Also see kernel code for printw.c. Naming and registration of module init and exit functions. Exporting symbols Meta data macros
7
Development Modes Standalone Integrated
Work in separate directory (see pages ) (next slide) Integrated Put module code in source code tree (see textbook, pages ) Pick appropriate directory and place module code there Add line (obj-m += …) to Makefile in that directory (see info make for how to set variables, and the kbuild documentation on configuration.)
8
Standalone Makefile # Makefile for kernel module development #
# CS6560 Fall 2007 ########################## obj-m := CS6560_LKM_one.o obj-m += CS6560_LKM_two.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
9
Loading and Unloading Modules
Commands insmod - inserts module rmmod - removes module lsmod - lists modules depmod - control dependencies modinfo - display module meta data
10
Examples in Class Modules_two
Compile (in directory that contains source code for new module) # fakeroot make Look at modinfo CS6560_LKM_one.ko modinfo CS6560_LKM_two.ko Bring up dmesg Use: dmesg | tail or use: cat /proc/kmsg Load CS6560_LKM_one lsmod CS6560_LKM_one.ko /proc/modules /sys/module
11
Try the second one Load and unload CS6560_LKM_two.ko
Look at what happens each time to Messages /proc/modules /sys/module
12
Now with parameters Initialization on command line
Changing variables with /sys/ using cat
13
Applications of Modules
Proc files Device drivers Interrupt Handlers File systems System calls Monitoring and replacing core functionality such as scheduling
14
Proc Files Example From
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.