A Linux kernel module implementing a character device driver that provides a circular buffer for logging messages in kernel space. This module allows user-space applications to write log entries and read them back through a simple interface, making it useful for debugging, monitoring, and logging purposes.
- Implements a character device driver (
/dev/klogger
) - Circular buffer implementation for efficient memory usage
- Thread-safe operations using read-write locks
- Supports concurrent access from multiple processes
- Fixed-size message buffer (256 bytes per message)
- Total buffer size of 262,144 bytes (256KB)
- Automatic overwrite of oldest messages when buffer is full
- Simple read/write interface compatible with standard Unix tools
- Linux kernel headers
- GCC compiler
- Make build system
- Clone the repository:
git clone https://github.com/yourusername/kernel-logger-module.git
cd kernel-logger-module
- Build the module:
make
- Load the module:
make load
This will create the device file /dev/klogger
with read-write permissions (666).
You can write messages to the logger using standard Unix tools:
echo "Hello from userspace!" > /dev/klogger
To read all messages from the logger:
cat /dev/klogger
The Makefile provides several useful commands:
make
ormake build
: Build the kernel modulemake load
: Load the module and set permissionsmake unload
: Unload the modulemake reload
: Unload and reload the modulemake status
: Show module statusmake logs
: Show recent kernel logs for the modulemake test
: Run the test suitemake clean
: Clean build artifacts
The project includes a comprehensive test suite that verifies:
- Basic read/write operations
- Multiple message handling
- Buffer overflow behavior
- Concurrent access handling
- Device file permissions
- Module loading/unloading
Run the tests with:
make test
- Message size: 256 bytes
- Buffer size: 262,144 bytes (256KB)
- Maximum entries: 1024 messages
- Device name: klogger
- Major number: Dynamically allocated
- Access permissions: 666 (rw-rw-rw-)
The module implements:
- Circular buffer management
- Thread-safe operations using read-write locks
- Reference counting for open handles
- Proper cleanup on module unload
- Error handling and boundary checks
This project is licensed under the GPL License - see the LICENSE file for details.
Lionel Silva
0.1
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request