Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2
3//! Bindings.
4//!
5//! Imports the generated bindings by `bindgen`.
6//!
7//! This crate may not be directly used. If you need a kernel C API that is
8//! not ported or wrapped in the `kernel` crate, then do so first instead of
9//! using this crate.
10
11#![no_std]
12#![allow(
13 clippy::all,
14 missing_docs,
15 non_camel_case_types,
16 non_upper_case_globals,
17 non_snake_case,
18 improper_ctypes,
19 unreachable_pub,
20 unsafe_op_in_unsafe_fn
21)]
22#![feature(cfi_encoding)]
23
24#[allow(dead_code)]
25#[allow(clippy::cast_lossless)]
26#[allow(clippy::ptr_as_ptr)]
27#[allow(clippy::ref_as_ptr)]
28#[allow(clippy::undocumented_unsafe_blocks)]
29#[cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_transmutes))]
30mod bindings_raw {
31 use pin_init::{MaybeZeroable, Zeroable};
32
33 // Manual definition for blocklisted types.
34 type __kernel_size_t = usize;
35 type __kernel_ssize_t = isize;
36 type __kernel_ptrdiff_t = isize;
37
38 // `bindgen` doesn't automatically do this, see
39 // <https://github.com/rust-lang/rust-bindgen/issues/3196>
40 //
41 // SAFETY: `__BindgenBitfieldUnit<Storage>` is a newtype around `Storage`.
42 unsafe impl<Storage> Zeroable for __BindgenBitfieldUnit<Storage> where Storage: Zeroable {}
43
44 // Use glob import here to expose all helpers.
45 // Symbols defined within the module will take precedence to the glob import.
46 pub use super::bindings_helper::*;
47 include!(concat!(
48 env!("OBJTREE"),
49 "/rust/bindings/bindings_generated.rs"
50 ));
51}
52
53// When both a directly exposed symbol and a helper exists for the same function,
54// the directly exposed symbol is preferred and the helper becomes dead code, so
55// ignore the warning here.
56#[allow(dead_code)]
57mod bindings_helper {
58 // Import the generated bindings for types.
59 use super::bindings_raw::*;
60 include!(concat!(
61 env!("OBJTREE"),
62 "/rust/bindings/bindings_helpers_generated.rs"
63 ));
64}
65
66pub use bindings_raw::*;
67
68pub const compat_ptr_ioctl: Option<
69 unsafe extern "C" fn(*mut file, ffi::c_uint, ffi::c_ulong) -> ffi::c_long,
70> = {
71 #[cfg(CONFIG_COMPAT)]
72 {
73 Some(bindings_raw::compat_ptr_ioctl)
74 }
75 #[cfg(not(CONFIG_COMPAT))]
76 {
77 None
78 }
79};