/linux-kernel-modules-development

Notes and experiments on linux kernel module development

Primary LanguageCGNU General Public License v2.0GPL-2.0

Messing with the Linux kernel

At the moment I'm just following the Linux Device Drivers book to get a hint on how the kernel works. I will follow the path it proposes, so the experiments will correlate with the exposition order of the topics in the book.

But, as this book is from 2009, and it works with the version 2.6 of the kernel, I will be using some other resources to update the examples.

This repo will document my journey on learning some cool kernel stuff. Keep in mind I'm just hacking my way through this... things will be messy and suboptimal, I'm just making some experiments.

This series of experiments does not start from building a custom kernel image, booting with a custom init, mounting everything and so on. If you are interested in that please refer to the following links:

Experiments

index title contents
0 Hello World from the kernel setting up a vm, sharing files between gest and host, compiling and inserting a new module
1 Mounting and checking some info allocating minor and major numbers, checking our char device is listed
2 Using parameters with insmod updating module to accept parameters when mounting
3 The load script creating a simple init script to set the files for our devices
4 Registering File Operations setting the callbacks that will enable to interact with the module from userland
5 Simplest Open Callback setting private_data to file pointer and checking access mode
6 Simplest Read Callback making our device to stream a long string :)
7 Reading from private_data using the private_data field as the source of the string we are going to print
8 Writing to private_data writing to a fixed size buffer stored in private_data
9 Dynamically allocating memory from the device allocating, reading and resizing from our file operations
10 Implementing an interesting memory management strategy Implementing a memory management strategy similar to the one used in chapter 3 of the Linux Device Drivers Book
11 Concurrency control - Introducing the mutex Implementing a simple mutex to avoid race conditions when multiple processes try to read/write into the device
12 Introducing IOCTL Introducing a simple implementation of ioctl to demostrate how it works
13 Concurrency control - Sleep & wait queues Introducing a little experiment on how wait queues work
14 Asynchronous notifications An example on how to set asynchronous notification queues, signal from the module, and set up handlers in userland
15 A simple Polling callback An example on registering polling callback so we can use poll, select and epoll with our device

Various Resources

The Monkey

The Monkey