Skip to content
FreeBSD kernel module in Rust
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
crates
src
.gitignore
Cargo.toml
Makefile
README.md
Xargo.toml
build.sh
hello.c
x86_64-kernel-freebsd.json

README.md

Echo - a FreeBSD kernel module written Rust (WIP)

Requirements

  • FreeBSD machine
  • Rust nightly
  • Xargo

I recommend using rustup for installing and handling different versions of Rust.

Installation

Rust

See https://www.rustup.rs/

Xargo

$ cargo install xargo

Setting Rust nightly

Do in crate root:

$ rustup override set nightly

Content

Root Folder

This folder is the Cargo root for the module itself.

Crates

Here are all the dependency crates that are not available on crates.io.

core is built and handled completely by Xargo.

libstd_unicode

Copied from Rust source code, unmodified.

libcollections

Copied from Rust source code, unmodified.

liballoc

Copied from Rust source code, unmodified.

liballoc_system

Copied from Rust source code.

Added kern_malloc.rs which is the FFI bindings to kernel's malloc functions.

Modified lib.rs to use said functions.

freebsd_kernel_std

A minimal implementation of std for the echo module. FFI bindings are generated on build. Safe bindings exists for things necessary for this code to run.

Build

Check build.sh script if you like to make any changes then run

$ ./build.sh

Load Module

If build was successful there should be a hello.ko file in the root folder. Load with

$ sudo kldload ./hello.ko

Usage

$ cat /dev/rustmodule  
Default Message :)  
$ echo Hello > /dev/rustmodule   
Read 6 bytes. Setting new message to "Hello\n"  
$ cat /dev/rustmodule  
Hello  
$ sudo kldunload hello  

Warning

If there are any bugs or faulty code the kernel will most likely hang.

I recommend testing the module in a virtual machine.

It keeps your system safe and it makes it easier to develop and test.

You can’t perform that action at this time.