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;
70#[cfg(CONFIG_DMA_SHARED_BUFFER)]
71pub mod dma_buf;
72pub mod driver;
73#[cfg(CONFIG_DRM = "y")]
74pub mod drm;
75pub mod error;
76pub mod faux;
77#[cfg(CONFIG_RUST_FW_LOADER_ABSTRACTIONS)]
78pub mod firmware;
79pub mod fmt;
80pub mod fs;
81#[cfg(CONFIG_RUST_FWCTL_ABSTRACTIONS)]
82pub mod fwctl;
83#[cfg(CONFIG_GPU_BUDDY = "y")]
84pub mod gpu;
85#[cfg(CONFIG_I2C = "y")]
86pub mod i2c;
87pub mod id_pool;
88#[doc(hidden)]
89pub mod impl_flags;
90pub mod init;
91pub mod interop;
92pub mod interrupt;
93pub mod io;
94pub mod ioctl;
95pub mod iommu;
96pub mod iov;
97pub mod irq;
98pub mod jump_label;
99#[cfg(CONFIG_KUNIT)]
100pub mod kunit;
101pub mod list;
102pub mod maple_tree;
103pub mod mem;
104pub mod miscdevice;
105pub mod mm;
106pub mod module;
107pub mod module_param;
108#[cfg(CONFIG_NET)]
109pub mod net;
110pub mod num;
111pub mod of;
112#[cfg(CONFIG_PM_OPP)]
113pub mod opp;
114pub mod page;
115#[cfg(CONFIG_PCI)]
116pub mod pci;
117pub mod pid_namespace;
118pub mod platform;
119pub mod prelude;
120pub mod print;
121pub mod processor;
122pub mod ptr;
123#[cfg(CONFIG_RUST_PWM_ABSTRACTIONS)]
124pub mod pwm;
125pub mod ratelimit;
126pub mod rbtree;
127pub mod regulator;
128pub mod revocable;
129pub mod safety;
130pub mod scatterlist;
131pub mod security;
132pub mod seq_file;
133#[cfg(CONFIG_RUST_SERIAL_DEV_BUS_ABSTRACTIONS)]
134pub mod serdev;
135pub mod sizes;
136#[cfg(CONFIG_SOC_BUS)]
137pub mod soc;
138#[doc(hidden)]
139pub mod std_vendor;
140pub mod str;
141pub mod sync;
142pub mod task;
143pub mod time;
144pub mod tracepoint;
145pub mod transmute;
146pub mod types;
147pub mod uaccess;
148#[cfg(CONFIG_USB = "y")]
149pub mod usb;
150pub mod workqueue;
151pub mod xarray;
152
153#[doc(hidden)]
154pub use bindings;
155pub use macros;
156pub use module::{
157 InPlaceModule,
158 Module,
159 ModuleMetadata,
160 ThisModule, };
162pub use uapi;
163
164const __LOG_PREFIX: &[u8] = b"rust_kernel\0";
166
167#[allow(dead_code)]
170struct LocalModule;
171
172impl ModuleMetadata for LocalModule {
173 const NAME: &'static str::CStr = c"rust_kernel";
174
175 const THIS_MODULE: ThisModule = {
176 unsafe { ThisModule::from_ptr(core::ptr::null_mut()) }
178 };
179}
180
181#[cfg(not(testlib))]
182#[panic_handler]
183fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
184 pr_emerg!("{}\n", info);
185 unsafe { bindings::BUG() };
187}
188
189#[macro_export]
220macro_rules! container_of {
221 ($field_ptr:expr, $Container:ty, $($fields:tt)*) => {{
222 let offset: usize = ::core::mem::offset_of!($Container, $($fields)*);
223 let field_ptr = $field_ptr;
224 let container_ptr = field_ptr.byte_sub(offset).cast::<$Container>();
225 $crate::assert_same_type(field_ptr, (&raw const (*container_ptr).$($fields)*).cast_mut());
226 container_ptr
227 }}
228}
229
230#[doc(hidden)]
232pub fn assert_same_type<T>(_: T, _: T) {}
233
234#[doc(hidden)]
236#[macro_export]
237macro_rules! concat_literals {
238 ($( $asm:literal )* ) => {
239 ::core::concat!($($asm),*)
240 };
241}
242
243#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
249#[macro_export]
250macro_rules! asm {
251 ($($asm:expr),* ; $($rest:tt)*) => {
252 ::core::arch::asm!( $($asm)*, options(att_syntax), $($rest)* )
253 };
254}
255
256#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
262#[macro_export]
263macro_rules! asm {
264 ($($asm:expr),* ; $($rest:tt)*) => {
265 ::core::arch::asm!( $($asm)*, $($rest)* )
266 };
267}
268
269#[inline]
300pub fn file_from_location<'a>(loc: &'a core::panic::Location<'a>) -> &'a core::ffi::CStr {
301 #[cfg(CONFIG_RUSTC_HAS_FILE_AS_C_STR)]
302 {
303 loc.file_as_c_str()
304 }
305
306 #[cfg(all(CONFIG_RUSTC_HAS_FILE_WITH_NUL, not(CONFIG_RUSTC_HAS_FILE_AS_C_STR)))]
307 {
308 loc.file_with_nul()
309 }
310
311 #[cfg(not(CONFIG_RUSTC_HAS_FILE_WITH_NUL))]
312 {
313 let _ = loc;
314 c"<Location::file_as_c_str() not supported>"
315 }
316}