👨🔧 This kernel module merges many interesting concepts regarding Linux and Android kernel modules development in only two /proc entries.Needless to say, it does not include any standard C library.
It`s a SMP-Safe implementation of a Linux kernel module - random digits generator (even or odd).
Particularly interesting in terms of coding since:
- It manages a kernel doubly-linked list with ghost node (read more about them at my repo)
- It employs kernel interruptions to fill a kernel circular buffer (configurable intervals)
- It uses semaphores and special kernel mutexes called spin-locks which are required for a code with CPU interruptions.
- It uses private work-queues to schedule CPU work (in this case, empty the linked list)
You can also configure and check the module parameters with the auxiliar entry /proc/modconfig
Compile, load the module, access via cat and echo to /proc/modtimer2. The first process to open and write from the file will receive even numbers randomly generated, while the second one will be feed with odd digits.
$ make # make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
$ sudo insmod modtimer.ko
$ echo max_random 4 > /proc/modconfig or $ cat modconfig
...
$ cat /proc/modtimer
...
You can check it worked with $sudo lsmod | head and reading $sudo dmesg
The module was developed for Debian, but the can be easily used in Android. You just need to use the Makefile for re-compiling. Please notice that the Makefile employs a compiled Android-x86 kernel oreo version
This project is licensed under the GNU-GPL License - see the LICENSE.md file for details