Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,429 changes: 1,429 additions & 0 deletions rust/kernel/init.rs

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions rust/kernel/init/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Module containing common kernel initializer functions.

use crate::{
init::{self, PinInit},
types::Opaque,
};

macro_rules! create_func {
($name:ident $(, $arg_name:ident: $arg_typ:ident)*) => {
/// Create an initializer using the given initializer function from C.
///
/// # Safety
///
/// The given function **must** under all circumstances initialize the memory location to a
/// valid `T`. If it fails to do so it results in UB.
///
/// If any parameters are given, those need to be valid for the function. Valid means that
/// calling the function with those parameters complies with the above requirement **and**
/// every other requirement on the function itself.
pub unsafe fn $name<T $(, $arg_typ)*>(
init_func: unsafe extern "C" fn(*mut T $(, $arg_name: $arg_typ)*),
$($arg_name: $arg_typ,)*
) -> impl PinInit<Opaque<T>> {
// SAFETY: The safety contract of this function ensures that `init_func` fully
// initializes `slot`.
unsafe {
init::pin_init_from_closure(move |slot| {
init_func(Opaque::raw_get(slot) $(, $arg_name)*);
Ok(())
})
}
}
}
}

create_func!(ffi_init);
create_func!(ffi_init1, arg1: A1);
create_func!(ffi_init2, arg1: A1, arg2: A2);
create_func!(ffi_init3, arg1: A1, arg2: A2, arg3: A3);
create_func!(ffi_init4, arg1: A1, arg2: A2, arg3: A3, arg4: A4);
Loading