Giter VIP home page Giter VIP logo

rust-lkm-template's Introduction

Rust Loadable Kernel Module Template

Setup

Note that you need to have a rust enabled kernel to use this template. Follow the instructions on the link or see one of the references.

The default paths for scripts in this template are:

  • KERNEL: ../linux
  • BUSYBOX: ../busybox

So, you should have a KERNEL dir with a rust enabled kernel already built and a BUSYBOX dir with a ALREADY built and configured busybox.

For automating the setup of the environment, run the setup script:

./scripts/setup

Refer to the script for more info.

Building

I wrote a simple wrapper script for the make command for compiling this LKM. It is located in the scripts directory. You can use it like this:

./scripts/build
./scripts/build -t clean
./scripts/build -t rust-analyzer
./scripts/build -k /path/to/rust/enabled/kernel -b /path/to/busybox
# ... and so on

Please refer to the kernel docs for more info on basic Kbuild usage.

There's also rust specific targets. For example, you can build the rust-analyzer project configuration with:

./scripts/build -t rust-analyzer

Note that we have a bug in the current mainline kernel that prevents rust-analyzer from working properly with LKMs. You can find a patch for it here.

Running

First, build the LKM. Then, you can use the run script to run it in a qemu VM:

# Default locations: KERNEL=../linux, BUSYBOX=../busybox
./scripts/run
# Custom locations
./scripts/run -k /path/to/rust/enabled/kernel -b /path/to/busybox

This script will simply copy all the .ko files to the initramfs and run the VM.

Hot-reloading

You can use the hot-reload script to hot-reload the LKM in the running VM:

./scripts/hot-reload

It uses the cargo-watch crate to watch for changes in the source code and then running ./scripts/build to build the LKM and ./scripts/run to run it in the VM. Please refer to the script for more info.

References

rust-lkm-template's People

Contributors

tomcat-42 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.