1#![no_std]
15#![feature(unsigned_is_multiple_of)]
21#![feature(generic_arg_infer)]
24#![feature(arbitrary_self_types)]
27#![feature(derive_coerce_pointee)]
28#![feature(used_with_arg)]
31#![cfg_attr(CONFIG_RUSTC_HAS_FILE_WITH_NUL, feature(file_with_nul))]
35
36#[cfg(not(CONFIG_RUST))]
39compile_error!("Missing kernel configuration for conditional compilation");
40
41extern crate self as kernel;
43
44pub use ffi;
45
46pub mod acpi;
47pub mod alloc;
48#[cfg(CONFIG_AUXILIARY_BUS)]
49pub mod auxiliary;
50pub mod bitfield;
51pub mod bitmap;
52pub mod bits;
53#[cfg(CONFIG_BLOCK)]
54pub mod block;
55pub mod bug;
56pub mod build_assert;
57pub mod clk;
58#[cfg(CONFIG_CONFIGFS_FS)]
59pub mod configfs;
60pub mod cpu;
61#[cfg(CONFIG_CPU_FREQ)]
62pub mod cpufreq;
63pub mod cpumask;
64pub mod cred;
65pub mod debugfs;
66pub mod device;
67pub mod device_id;
68pub mod devres;
69pub mod dma;
70pub mod driver;
71#[cfg(CONFIG_DRM = "y")]
72pub mod drm;
73pub mod error;
74pub mod faux;
75#[cfg(CONFIG_RUST_FW_LOADER_ABSTRACTIONS)]
76pub mod firmware;
77pub mod fmt;
78pub mod fs;
79#[cfg(CONFIG_RUST_FWCTL_ABSTRACTIONS)]
80pub mod fwctl;
81#[cfg(CONFIG_GPU_BUDDY = "y")]
82pub mod gpu;
83#[cfg(CONFIG_I2C = "y")]
84pub mod i2c;
85pub mod id_pool;
86#[doc(hidden)]
87pub mod impl_flags;
88pub mod init;
89pub mod interop;
90pub mod interrupt;
91pub mod io;
92pub mod ioctl;
93pub mod iommu;
94pub mod iov;
95pub mod irq;
96pub mod jump_label;
97#[cfg(CONFIG_KUNIT)]
98pub mod kunit;
99pub mod list;
100pub mod maple_tree;
101pub mod miscdevice;
102pub mod mm;
103pub mod module;
104pub mod module_param;
105#[cfg(CONFIG_NET)]
106pub mod net;
107pub mod num;
108pub mod of;
109#[cfg(CONFIG_PM_OPP)]
110pub mod opp;
111pub mod page;
112#[cfg(CONFIG_PCI)]
113pub mod pci;
114pub mod pid_namespace;
115pub mod platform;
116pub mod prelude;
117pub mod print;
118pub mod processor;
119pub mod ptr;
120#[cfg(CONFIG_RUST_PWM_ABSTRACTIONS)]
121pub mod pwm;
122pub mod rbtree;
123pub mod regulator;
124pub mod revocable;
125pub mod safety;
126pub mod scatterlist;
127pub mod security;
128pub mod seq_file;
129#[cfg(CONFIG_RUST_SERIAL_DEV_BUS_ABSTRACTIONS)]
130pub mod serdev;
131pub mod sizes;
132#[cfg(CONFIG_SOC_BUS)]
133pub mod soc;
134#[doc(hidden)]
135pub mod std_vendor;
136pub mod str;
137pub mod sync;
138pub mod task;
139pub mod time;
140pub mod tracepoint;
141pub mod transmute;
142pub mod types;
143pub mod uaccess;
144#[cfg(CONFIG_USB = "y")]
145pub mod usb;
146pub mod workqueue;
147pub mod xarray;
148
149#[doc(hidden)]
150pub use bindings;
151pub use macros;
152pub use module::{
153 InPlaceModule,
154 Module,
155 ModuleMetadata,
156 ThisModule, };
158pub use uapi;
159
160const __LOG_PREFIX: &[u8] = b"rust_kernel\0";
162
163#[allow(dead_code)]
166struct LocalModule;
167
168impl ModuleMetadata for LocalModule {
169 const NAME: &'static str::CStr = c"rust_kernel";
170
171 const THIS_MODULE: ThisModule = {
172 unsafe { ThisModule::from_ptr(core::ptr::null_mut()) }
174 };
175}
176
177#[cfg(not(testlib))]
178#[panic_handler]
179fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
180 pr_emerg!("{}\n", info);
181 unsafe { bindings::BUG() };
183}
184
185#[macro_export]
216macro_rules! container_of {
217 ($field_ptr:expr, $Container:ty, $($fields:tt)*) => {{
218 let offset: usize = ::core::mem::offset_of!($Container, $($fields)*);
219 let field_ptr = $field_ptr;
220 let container_ptr = field_ptr.byte_sub(offset).cast::<$Container>();
221 $crate::assert_same_type(field_ptr, (&raw const (*container_ptr).$($fields)*).cast_mut());
222 container_ptr
223 }}
224}
225
226#[doc(hidden)]
228pub fn assert_same_type<T>(_: T, _: T) {}
229
230#[doc(hidden)]
232#[macro_export]
233macro_rules! concat_literals {
234 ($( $asm:literal )* ) => {
235 ::core::concat!($($asm),*)
236 };
237}
238
239#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
245#[macro_export]
246macro_rules! asm {
247 ($($asm:expr),* ; $($rest:tt)*) => {
248 ::core::arch::asm!( $($asm)*, options(att_syntax), $($rest)* )
249 };
250}
251
252#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
258#[macro_export]
259macro_rules! asm {
260 ($($asm:expr),* ; $($rest:tt)*) => {
261 ::core::arch::asm!( $($asm)*, $($rest)* )
262 };
263}
264
265#[inline]
296pub fn file_from_location<'a>(loc: &'a core::panic::Location<'a>) -> &'a core::ffi::CStr {
297 #[cfg(CONFIG_RUSTC_HAS_FILE_AS_C_STR)]
298 {
299 loc.file_as_c_str()
300 }
301
302 #[cfg(all(CONFIG_RUSTC_HAS_FILE_WITH_NUL, not(CONFIG_RUSTC_HAS_FILE_AS_C_STR)))]
303 {
304 loc.file_with_nul()
305 }
306
307 #[cfg(not(CONFIG_RUSTC_HAS_FILE_WITH_NUL))]
308 {
309 let _ = loc;
310 c"<Location::file_as_c_str() not supported>"
311 }
312}