%Linux Hello World %Thadeu Cascardo # Module Tools * lsmod * insmod * rmmod * modprobe * modinfo * depmod # Module Files * /lib/modules/ * /proc/modules * /sys/module/ # Module parameters * modinfo output * modprobe configuration files * /sys/module/*/parameters/ # Headers * include linux/module.h * include linux/init.h # Init and Exit Functions We use *module\\_init* and *module\\_exit* to declare our init and exit functions. The *\\_\\_init* and *\\_\\_exit* marks allow the kernel to remove them when they are not needed, reducing memory consumption. # printk *printk* is very similar to printf. The messages are usually preceded by a string in the form \, where *n* is a priority. There are macros, like *KERN\\_ALERT* and *KERN\\_DEBUG* to use for that. # License and taint *MODULE\\_LICENSE* is highly recommended. A free software license should be used, otherwise the kernel is tainted. This indicates to developers that something has gone wrong, and some bug reports are ignored some times. # Building out-of-tree Building an out-of-tree linux module is very simple. Let's take a look at a simple command line and a simple Makefile. # Module description definitios * MODULE\\_AUTHOR * MODULE\\_LICENSE * MODULE\\_DESCRIPTION * MODULE\\_INFO * MODULE\\_ALIAS * MODULE\\_VERSION # Module parameters Besides *MODULE\\_PARM\\_DESC* to inform user about the parameter, we must use *module\\_param*. module\\_param(name, type, perm); # Memory allocation * include linux/slab.h * kmalloc * kfree