There was a big book with plain red leather covers; its tall pages were now almost filled. At the beginning there were many leaves covered with Bilbo's thin wandering hand; but most of it was written in Frodo's firm flowing script. It was divided into chapters but Chapter 80 was unfinished, and after that were some blank leaves.
"Why, you have nearly finished it, Mr. Frodo!" Sam exclaimed. "Well, you have kept at it, I must say."
"I have quite finished, Sam," said Frodo. "The last pages are for you."
—The Return of the King, Book VI, Chapter 9
Explanation of studio
In this studio, you will:
Please complete the required exercises below, as well as any optional enrichment exercises that you wish to complete.
As you work through these exercises, please record your answers, and when finished email your results to email@example.com with the phrase Loadable Kernel Modules in the subject line.
Make sure that the name of each person who worked on these exercises is listed in the first answer, and make sure you number each of your responses so it is easy to match your responses with each exercise.
obj-m := hello.o". Finally, build the module with the command "
make -C /linux/source/directory/ SUBDIRS=$PWD modules", but replace the path with the root location of your Linux source tree.
What do you expect to happen when you load the kernel module?
dmesg) that allows you to view the system log also allows you to manipulate it. You can clear the log with the command "
sudo dmesg --clear".
The basic utility for loading modules into the kernel is called
insmod. The make process from before will have generated a
.ko file, which is the loadable module. Load your module now
with a command such as: "
sudo insmod hello.ko"
insmod utility has been superceeded
by another program called
modprobe, which in general should
modprobe is safer to use because it
performs dependency resolution between modules. We use
rmmod here simply to
demonstrate the low-level tools that actually perform
module loading and unloading.
lsmodcommand to see a listing of all currently loaded kernel modules. Verify that your module appears in the list. Second, verify that the printk statement in your init function has shown up in the system log. For the answer to this exercise, copy the output of
lsmodand the last few lines of the system log here.
rmmod. When using this tool you can specify the module name (as shown in
lsmod) or you can specify a
Remove your module now, and verify its removal as before. As the answer to
this exercise, copy the output of
lsmod and the last few lines
of the system log.
One kernel variable we've talked about previous is the
counter. Recall that this variable keeps track of how many timer interrupts
have (theoretically) occured since system boot. Modify your kernel module
to print the value of this variable, it's an unsigned long. This value
is not directly accessible by userspace programs, but it is visible in
Copy and paste a system log message that prints the
/include/uapi/asm-gerneic/errno-base.h. Modify your init function to return positive and negative values, respectively. What happens when you load the module? Check the system logs, what do you find there?
In addition to the answers above, please submit:
EXPORT_SYMBOLmacro. You can see a list of all kernel symbols by looking at the file /proc/kallsyms, e.g.
cat /proc/kallsyms. You might notice that this is very similar to the symbol table of a traditional application. (Which you can print with the program
nm, if you've never done it before. Try it on any binary!) In fact, their syntax is identical, so you can use
man nmto find some more information about how to decode the contents of
Symbols that have been exported can be found in this list with the prefixes
__ksymtab_. These prefixes denote
a special kernel symbol that stores the name of the exported symbol and a
struct that stores information about the symbol, respectively. See the
EXPORT_SYMBOL to see how these are generated.