#![no_std]
#![feature(generic_arg_infer)]
#![feature(arbitrary_self_types)]
#![feature(derive_coerce_pointee)]
#![feature(used_with_arg)]
#![cfg_attr(CONFIG_RUSTC_HAS_FILE_WITH_NUL, feature(file_with_nul))]
#[cfg(not(CONFIG_RUST))]
compile_error!("Missing kernel configuration for conditional compilation");
extern crate self as kernel;
pub use ffi;
pub mod acpi;
pub mod alloc;
#[cfg(CONFIG_AUXILIARY_BUS)]
pub mod auxiliary;
pub mod bitmap;
pub mod bits;
#[cfg(CONFIG_BLOCK)]
pub mod block;
pub mod bug;
pub mod build_assert;
pub mod clk;
#[cfg(CONFIG_CONFIGFS_FS)]
pub mod configfs;
pub mod cpu;
#[cfg(CONFIG_CPU_FREQ)]
pub mod cpufreq;
pub mod cpumask;
pub mod cred;
pub mod debugfs;
pub mod device;
pub mod device_id;
pub mod devres;
pub mod dma;
pub mod driver;
#[cfg(CONFIG_DRM = "y")]
pub mod drm;
pub mod error;
pub mod faux;
#[cfg(CONFIG_RUST_FW_LOADER_ABSTRACTIONS)]
pub mod firmware;
pub mod fmt;
pub mod fs;
#[cfg(CONFIG_GPU_BUDDY = "y")]
pub mod gpu;
#[cfg(CONFIG_I2C = "y")]
pub mod i2c;
pub mod id_pool;
#[doc(hidden)]
pub mod impl_flags;
pub mod init;
pub mod interop;
pub mod io;
pub mod ioctl;
pub mod iommu;
pub mod iov;
pub mod irq;
pub mod jump_label;
#[cfg(CONFIG_KUNIT)]
pub mod kunit;
pub mod list;
pub mod maple_tree;
pub mod miscdevice;
pub mod mm;
pub mod module_param;
#[cfg(CONFIG_NET)]
pub mod net;
pub mod num;
pub mod of;
#[cfg(CONFIG_PM_OPP)]
pub mod opp;
pub mod page;
#[cfg(CONFIG_PCI)]
pub mod pci;
pub mod pid_namespace;
pub mod platform;
pub mod prelude;
pub mod print;
pub mod processor;
pub mod ptr;
#[cfg(CONFIG_RUST_PWM_ABSTRACTIONS)]
pub mod pwm;
pub mod rbtree;
pub mod regulator;
pub mod revocable;
pub mod safety;
pub mod scatterlist;
pub mod security;
pub mod seq_file;
pub mod sizes;
#[cfg(CONFIG_SOC_BUS)]
pub mod soc;
#[doc(hidden)]
pub mod std_vendor;
pub mod str;
pub mod sync;
pub mod task;
pub mod time;
pub mod tracepoint;
pub mod transmute;
pub mod types;
pub mod uaccess;
#[cfg(CONFIG_USB = "y")]
pub mod usb;
pub mod workqueue;
pub mod xarray;
#[doc(hidden)]
pub use bindings;
pub use macros;
pub use uapi;
const __LOG_PREFIX: &[u8] = b"rust_kernel\0";
pub trait Module: Sized + Sync + Send {
fn init(module: &'static ThisModule) -> error::Result<Self>;
}
pub trait InPlaceModule: Sync + Send {
fn init(module: &'static ThisModule) -> impl pin_init::PinInit<Self, error::Error>;
}
impl<T: Module> InPlaceModule for T {
fn init(module: &'static ThisModule) -> impl pin_init::PinInit<Self, error::Error> {
let initer = move |slot: *mut Self| {
let m = <Self as Module>::init(module)?;
unsafe { slot.write(m) };
Ok(())
};
unsafe { pin_init::pin_init_from_closure(initer) }
}
}
pub trait ModuleMetadata {
const NAME: &'static crate::str::CStr;
}
pub struct ThisModule(*mut bindings::module);
unsafe impl Sync for ThisModule {}
impl ThisModule {
pub const unsafe fn from_ptr(ptr: *mut bindings::module) -> ThisModule {
ThisModule(ptr)
}
pub const fn as_ptr(&self) -> *mut bindings::module {
self.0
}
}
#[cfg(not(testlib))]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
pr_emerg!("{}\n", info);
unsafe { bindings::BUG() };
}
#[macro_export]
macro_rules! container_of {
($field_ptr:expr, $Container:ty, $($fields:tt)*) => {{
let offset: usize = ::core::mem::offset_of!($Container, $($fields)*);
let field_ptr = $field_ptr;
let container_ptr = field_ptr.byte_sub(offset).cast::<$Container>();
$crate::assert_same_type(field_ptr, (&raw const (*container_ptr).$($fields)*).cast_mut());
container_ptr
}}
}
#[doc(hidden)]
pub fn assert_same_type<T>(_: T, _: T) {}
#[doc(hidden)]
#[macro_export]
macro_rules! concat_literals {
($( $asm:literal )* ) => {
::core::concat!($($asm),*)
};
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[macro_export]
macro_rules! asm {
($($asm:expr),* ; $($rest:tt)*) => {
::core::arch::asm!( $($asm)*, options(att_syntax), $($rest)* )
};
}
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
#[macro_export]
macro_rules! asm {
($($asm:expr),* ; $($rest:tt)*) => {
::core::arch::asm!( $($asm)*, $($rest)* )
};
}
#[inline]
pub fn file_from_location<'a>(loc: &'a core::panic::Location<'a>) -> &'a core::ffi::CStr {
#[cfg(CONFIG_RUSTC_HAS_FILE_AS_C_STR)]
{
loc.file_as_c_str()
}
#[cfg(all(CONFIG_RUSTC_HAS_FILE_WITH_NUL, not(CONFIG_RUSTC_HAS_FILE_AS_C_STR)))]
{
loc.file_with_nul()
}
#[cfg(not(CONFIG_RUSTC_HAS_FILE_WITH_NUL))]
{
let _ = loc;
c"<Location::file_as_c_str() not supported>"
}
}