FreeBSD 13.1 Rust Kernel Programming Interface

This repository contains only bindings to the kernel!

It is unsafe, just a bindings!

It it still not tested (because structure alignment tests are now performed, see Kernel Programming Interface Test)

For the 'safe' and rust compatiable realization see Kernel Module Interface

Kernel Module Interface depends on this crate.


Porting guide

Please refer to The Rustonomicon

Private Function

```Rust /// defined in :line number

[repr(C)]

pub struct turnstile { _data: [u8; 0], _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, } ```

Extern functions and variables

```Rust extern "C" { #[nomangle] pub fn vmemcreate(name: *const cchar, base: vmemaddrt, size: vmemsizet, quantum: vmemsizet, qcachemax: vmemsizet, flags: cint) -> *mut vmemt;

#[no_mangle]
#[link_name = "wdog_software_attach"]
pub static mut wdog_software_attach: Option<unsafe extern "C" fn()>;

} ```

Pointer to function

A function fointer like C void (*func)() is: Rust Option<unsafe extern "C" fn()>

Functions

A special attributes - C __returns_twice, Rust #[ffi_returns_twice] - C __no_return, Rust ! - C __weak_symbol, Rust #[linkage = "extern_weak"]

Other


Styles

Some guidelins on formatting and porting.

Do not use rustfmt!.

Line breaks and formatting.

Normally the length of the line should be no more than 120 chars. But it is ok up to 160.

Function fromatting: ```Rust // #[ATTRIBUTES] \n // #[ATTRIBUTES] \n // [FUNCTION MODIFIERS] \n // [FUNCTION] [FUNCTIONNAME] [GENERICS][ARGUMENTS] [RETURNDATA]\n // [{] // [...] // [}] // // where [ARGUMENTS] may be formatted as following: // ([ARG], [ARG], [ARG]) // -- OR -- // ( // [ARG], // [ARG] // ) // -- OR -- // ([ARG], [ARG], [ARG], // [ARG], [ARG])

[inline]

pub unsafe fn function_name(arg1: u64, arg2: u64, arg3: B, arg4: C, arg5: D) -> u64 where B: SomeTrait, C: SomeTrait, D: SomeTrait {}

[inline]

pub unsafe fn function_name( arg1: u64, arg2: u64, arg3: B, arg4: C, arg5: D ) -> u64 where B: SomeTrait, C: SomeTrait, D: SomeTrait {}

[inline]

pub unsafe fn function_name(arg1: u64, arg2: u64, arg3: B, arg4: C, arg5: D) -> u64 where // optiinal \n B: SomeTrait, C: SomeTrait, D: SomeTrait {} ```

Const/type fromatting: ```Rust // [VISIBILITY] [CONST] [NAME][:] [DATATYPE] [=] [DATA] // [VISIBILITY] [TYPE] [TYPE_NAME] = [TYPE]

pub const RWVAL: u8 = 9; const DVAL: &[u8] = b"dvalue\0"; const BVAL: &[&[u8]] = & // \n if list if large, otherwise same line [ D_VAL, "blabla\0", ];

pub type uint32t = u32; pub type callbackfn = // \n if long difinition Option< unsafe extern "C" fn(my_var: u64) -> u64

;

pub type callbackfn = unsafe extern "C" fn(myvar: u64) -> u64; pub type callback_fn = Option u64>; ```

Assignment: ```Rust //... let var: u64 = some_struct.read().unwrap();

let var2: Option>> = somes.getinstance().get_sourcer().read().unwrap();

let var3: Arc> = iosource.instance() .grab() .setsource() .set_name() .start(); //... ```

Structs: ```Rust //[DERIVES/MODIFIERS] //[VISIBILITY][struct][name] \n //[{] \n //\t [field][:] [data][,] //[}]\n

[repr(C)]

[derive(Copy, Clone, Debug)]

pub struct StructName { field: u64, field1: Option>>, } ```

Match/If: ```Rust if var1 == 8 {

} else {

}

if var1 == 8 || varwithlongname > 6 || varwithanothrname > 100 || var5 != 8 {

} else if var2 < 6 {

} else {

}

match myvar { 3 => return 5, 6 => { something }, 9 => return 1, _ => }

match myvar.get_instance().foo() .bar().foobar() { StateA0V1H3 { field1: ..., field2: ..., field3: ... } => {

},
StateA4N6(a,b,c,d,e) =>
{

},
StateA5K3B6R3blabla =>
{

}

} ```

Security

I am trying my best to control what is pushed to this repository. No one else is allowed to commit to this repo! Mostly this crate contains structures. But sometimes '.h' files contains some static functions. A code in such functions must match with what in the originam '.h' file! Otherwise, any changes must be highlighted and a reason for changes must be in the comment sections. Also, the author of the changes must be mentioned!

Requests

Request to implement something or to fix something and ASAP are rejected.

Only if sponsored.