8000 GitHub - Thoxy67/zigko: A proof-of-concept Linux kernel module written in Zig
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Thoxy67/zigko

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZigKo - Zig Linux Kernel Module

A proof-of-concept Linux kernel module written in Zig, demonstrating how to write kernel modules using Zig instead of C.

Overview

This project shows that it's possible to write Linux kernel modules in Zig by:

  • Using Zig's C interop capabilities to interface with kernel functions
  • Leveraging Zig's build system to handle kernel module compilation
  • Automatically detecting kernel configuration and compiler

Features

  • Hello World kernel module - Simple module that prints messages on load/unload
  • Automatic kernel detection - Detects kernel version and compiler (GCC/Clang)
  • Cross-compiler support - Works with both GCC and Clang-built kernels
  • Convenient build commands - Easy-to-use Zig build steps

Prerequisites

  • Linux system with kernel headers installed
  • Zig compiler (latest stable version recommended)
  • sudo access for module installation
  • Build tools (make, gcc or clang)

Installing kernel headers

# Ubuntu/Debian
sudo apt install linux-headers-$(uname -r)

# Fedora/RHEL
sudo dnf install kernel-devel

# Arch Linux
sudo pacman -S linux-headers

Quick Start

  1. Clone and build:

    git clone <repo-url>
    cd zigko
    zig build
  2. Install the module:

    zig build install-mod
  3. Check if it's loaded:

    zig build status
  4. View kernel messages:

    zig build logs
  5. Unload the module:

    zig build uninstall-mod

Build Commands

Command Description
zig build Compile the kernel module
zig build install-mod Load the module into the kernel
zig build uninstall-mod Remove the module from the kernel
zig build status Check if module is currently loaded
zig build logs Show recent kernel log messages
zig build clean Clean all build artifacts

Project Structure

zigko/
├── src/
│   └── main.zig          # Main kernel module source
├── build.zig             # Zig build configuration
└── README.md             # This file

How It Works

  1. Zig Compilation: The Zig code is compiled to an object file with kernel-compatible settings
  2. Kernel Build: A Makefile is generated and used to build the final .ko module
  3. Module Loading: Standard Linux module loading mechanisms are used

The build system automatically:

  • Detects your kernel version and compiler
  • Sets up proper include paths
  • Configures compiler flags for kernel compatibility
  • Handles the two-stage build process (Zig → Make → .ko)

Example Output

When the module is loaded, you should see:

[zigko] Hello World from Zig kernel module!

When unloaded:

[zigko] Goodbye from Zig kernel module!

Limitations

This is a proof-of-concept with several limitations:

  • Only basic kernel functions are exposed
  • No comprehensive kernel API bindings
  • Limited error handling
  • Minimal kernel module features implemented

Development Notes

  • The module uses _printk for kernel logging
  • Module metadata is embedded using inline assembly
  • Kernel configuration is auto-detected from /proc/version
  • Both GCC and Clang kernels are supported

Contributing

This is an experimental project. Feel free to:

  • Report issues
  • Suggest improvements
  • Add more kernel API bindings
  • Improve error handling

⚠️ Warning: This is experimental software. Only use on development systems. Kernel modules can crash your system if not properly written.

About

A proof-of-concept Linux kernel module written in Zig

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0