projects/linux·blob assoc-array-fixes · refs

85 lines · 2.4 KiB

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::as_underscore)]
26#[allow(clippy::cast_lossless)]
27#[allow(clippy::ptr_as_ptr)]
28#[allow(clippy::ref_as_ptr)]
29#[allow(clippy::undocumented_unsafe_blocks)]
30#[cfg_attr(not(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES), allow(unknown_lints))]
31#[allow(unnecessary_transmutes)]
32#[cfg_attr(
33 CONFIG_RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS,
34 allow(suspicious_runtime_symbol_definitions)
35)]
36mod bindings_raw {
37 use pin_init::{MaybeZeroable, Zeroable};
38
39 // Manual definition for blocklisted types.
40 type __kernel_size_t = usize;
41 type __kernel_ssize_t = isize;
42 type __kernel_ptrdiff_t = isize;
43
44 // `bindgen` doesn't automatically do this, see
45 // <https://github.com/rust-lang/rust-bindgen/issues/3196>
46 //
47 // SAFETY: `__BindgenBitfieldUnit<Storage>` is a newtype around `Storage`.
48 unsafe impl<Storage> Zeroable for __BindgenBitfieldUnit<Storage> where Storage: Zeroable {}
49
50 // Use glob import here to expose all helpers.
51 // Symbols defined within the module will take precedence to the glob import.
52 pub use super::bindings_helper::*;
53 include!(concat!(
54 env!("OBJTREE"),
55 "/rust/bindings/bindings_generated.rs"
56 ));
57}
58
59// When both a directly exposed symbol and a helper exists for the same function,
60// the directly exposed symbol is preferred and the helper becomes dead code, so
61// ignore the warning here.
62#[allow(dead_code)]
63mod bindings_helper {
64 // Import the generated bindings for types.
65 use super::bindings_raw::*;
66 include!(concat!(
67 env!("OBJTREE"),
68 "/rust/bindings/bindings_helpers_generated.rs"
69 ));
70}
71
72pub use bindings_raw::*;
73
74pub const compat_ptr_ioctl: Option<
75 unsafe extern "C" fn(*mut file, ffi::c_uint, ffi::c_ulong) -> ffi::c_long,
76> = {
77 #[cfg(CONFIG_COMPAT)]
78 {
79 Some(bindings_raw::compat_ptr_ioctl)
80 }
81 #[cfg(not(CONFIG_COMPAT))]
82 {
83 None
84 }
85};