Basic template for an out-of-tree Linux kernel module written in Rust.

Overview

Rust out-of-tree module

This is a basic template for an out-of-tree Linux kernel module written in Rust.

Please note that:

  • The Rust support is experimental.

  • The kernel that the module is built against needs to be Rust-enabled (CONFIG_RUST=y).

  • The kernel tree (KDIR) requires the Rust metadata to be available. These are generated during the kernel build, but may not be available for installed/distributed kernels (the scripts that install/distribute kernel headers etc. for the different package systems and Linux distributions are not updated to take into account Rust support yet).

  • All Rust symbols are EXPORT_SYMBOL_GPL.

Example:

$ make KDIR=.../linux-with-rust-support LLVM=1
make -C .../linux-with-rust-support M=$PWD
make[1]: Entering directory '.../linux-with-rust-support'
  RUSTC [M] .../rust-out-of-tree-module/rust_out_of_tree.o
  MODPOST .../rust-out-of-tree-module/Module.symvers
  CC [M]  .../rust-out-of-tree-module/rust_out_of_tree.mod.o
  LD [M]  .../rust-out-of-tree-module/rust_out_of_tree.ko
make[1]: Leaving directory '.../linux-with-rust-support'

For details about the Rust support, see https://github.com/Rust-for-Linux/linux.

For details about out-of-tree modules, see https://www.kernel.org/doc/html/latest/kbuild/modules.html.

You might also like...
A syntax highlighter for Node powered by Tree Sitter. Written in Rust.

tree-sitter-highlight A syntax highlighter for Node.js powered by Tree Sitter. Written in Rust. Usage The following will output HTML: const treeSitter

A Rust-based Garry's Mod module for fetching environment variables.

gm_environ Using Environment Variables in Garry's Mod. Installation Download a copy of the module from the releases (or compile from source) Move the

Resolve JavaScript/TypeScript module with Rust

ES Resolve JavaScript/TypeScript module resolution in Rust Installation cargo add es_resolve Get Started use std::path::{Path, PathBuf}; use es_resolv

A very basic show-case of rust on the esp32 in 2022

Readme This example code does the following: Set up a WiFi connection on the ESP32-C3 Spawn a thread using std::thread in which we listen for incoming

Testing out if Rust can be used for a normal Data Engineering Pipeline.

RustForDataPipelines Testing out if Rust can be used for a normal Data Engineering Pipeline. Check out the full blog post here. https://www.confession

Rudi - an out-of-the-box dependency injection framework for Rust.

Rudi Rudi - an out-of-the-box dependency injection framework for Rust. use rudi::{Context, Singleton, Transient}; // Register `fn(cx) - A { A }` as

Rust Server Components. JSX-like syntax and async out of the box.

RSCx - Rust Server Components RSCx is a server-side HTML rendering engine library with a neat developer experience and great performance. Features: al

Threadless Module Stomping In Rust with some features
Threadless Module Stomping In Rust with some features

NovaLdr is a Threadless Module Stomping written in Rust, designed as a learning project while exploring the world of malware development. It uses advanced techniques like indirect syscalls and string encryption to achieve its functionalities. This project is not intended to be a complete or polished product but rather a journey into the technical aspects of malware, showcasing various techniques and features.

A CLI utility installed as
A CLI utility installed as "ansi" to quickly get ANSI escape sequences. Supports the most basic ones, like colors and styles as bold or italic.

'ansi' - a CLI utility to quickly get ANSI escape codes This Rust project called ansi-escape-sequences-cli provides an executable called ansi which ca

Comments
  • Fix build for Linux 6.1

    Fix build for Linux 6.1

    I tried building the kernel module for the Linux 6.1 kernel and these were the changes that were needed. I'm not sure if it makes sense to merge this, since it is probably due to changes in https://github.com/Rust-for-Linux/linux which were not yet up-streamed, but if anyone tries something similar this diff might be helpful.

    opened by rnestler 1
  • Adding support to generate rust-project.json

    Adding support to generate rust-project.json

    Using the linux/scripts/generate_rust_analyzer.py script as inspiration to add a make rust-analyzer target for an out-of-tree module.

    Process:

    • Make the $KDIR rust-project by issuing make rust-analyzer
    • Extend the crates config with the out-of-tree module
    • Write to rust-project.json in the module directory

    Here's an example of the added module crate config:

    $ more rust-project.json| tail -n 20
            {
                "cfg": [],
                "deps": [
                    {
                        "crate": 6,
                        "name": "kernel"
                    }
                ],
                "display_name": "rust_out_of_tree",
                "edition": "2021",
                "env": {
                    "RUST_MODFILE": "This is only for rust-analyzer"
                },
                "is_proc_macro": false,
                "is_workspace_member": false,
                "root_module": "rust_out_of_tree.rs"
            }
        ],
        "sysroot_src": "/home/mat/.rustup/toolchains/1.62.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library"
    }
    

    And the updated kernel crate config (pointing at my KDIR of ../rust_for_linux):

    more rust-project.json| jq 'del(.crates[].cfg) | .crates[]| select(.display_name=="kernel") '
    {
      "deps": [
        {
          "crate": 0,
          "name": "core"
        },
        {
          "crate": 2,
          "name": "alloc"
        },
        {
          "crate": 3,
          "name": "macros"
        },
        {
          "crate": 4,
          "name": "build_error"
        },
        {
          "crate": 5,
          "name": "bindings"
        }
      ],
      "display_name": "kernel",
      "edition": "2021",
      "env": {
        "RUST_MODFILE": "This is only for rust-analyzer"
      },
      "is_proc_macro": false,
      "is_workspace_member": true,
      "root_module": "../rust_for_linux/rust/kernel/lib.rs",
      "source": {
        "exclude_dirs": [],
        "include_dirs": [
          "rust/kernel",
          "rust"
        ]
      }
    }
    

    ===

    One janky thing I'm not currently a fan of is getting the root_module and rust source file name. This script currently only supports one file/module. I'd prefer to get it from the Kbuild file by reading obj-m but I'm not sure how to do that, any suggestions here are welcome.

    opened by thepacketgeek 5
Owner
Rust for Linux
Organization for adding support for the Rust language to the Linux kernel.
Rust for Linux
For something between the likes of a toy bootloader or tiny kernel and Arch Linux.

For something between the likes of a toy bootloader or tiny kernel and Arch Linux.

Aarush Gupta 3 Oct 9, 2022
Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. A tokei/scc/cloc alternative.

tcount (pronounced "tee-count") Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. Quick Start Simply run tcount

Adam P. Regasz-Rethy 48 Dec 7, 2022
Traversal of tree-sitter Trees and any arbitrary tree with a TreeCursor-like interface

tree-sitter-traversal Traversal of tree-sitter Trees and any arbitrary tree with a TreeCursor-like interface. Using cursors, iteration over the tree c

Sebastian Mendez 12 Jan 8, 2023
As-tree - Print a list of paths as a tree of paths 🌳

as-tree Print a list of paths as a tree of paths. For example, given: dir1/foo.txt dir1/bar.txt dir2/qux.txt it will print: . ├── dir1 │ ├── foo.tx

Jake Zimmerman 396 Dec 10, 2022
Simple template to use csr and ssr leptos with tauri for ios/android/windows/macos/linux and web dev

Tailwind-Leptos-Tauri Template Simple template to use csr and ssr leptos with tauri for ios/android/windows/macos/linux and web dev Just clone the rep

Victor Batarse 11 Mar 10, 2024
TMM is a Linux native game modding tool. it allows to install and depoly mods for Linux native and wine games.

Tux Mod Manager TMM is a Linux native mod manager made with the Tauri toolkit. It can install, load, remove and deploy mods for both Linux native and

Mathiew May 119 Dec 27, 2022
Baby's first Rust CLI project. Basic implementation of grep. Written in about 100 SLOC.

minigrep Coding project from Chapter 12 of the The Rust Programming Language book. Usage Compile and run as so minigrep QUERY FILENAME QUERY being the

Anis 2 Oct 2, 2021
A utility written in Rust for dumping binary information out of Mach-O files inspired by objdump

Mach-O Dump (macho-dump) An objdump like tool for exploring and manipulating Mach-O files. Note: This project is in an early stage and most of the fea

Irides 2 Oct 17, 2022
A basic text editor, written in Rust (hence the name).

rut A basic text editor, written in Rust (hence the name). Why, though? I just wanted a basic TUI text editor (like Nano) that could: Be used with all

Lowell Thoerner 4 Feb 3, 2023
a Rust library implementing safe, lightweight context switches, without relying on kernel services

libfringe libfringe is a library implementing safe, lightweight context switches, without relying on kernel services. It can be used in hosted environ

edef 473 Dec 28, 2022