1 // SPDX-License-Identifier: GPL-2.0
3 //! Crate for all kernel procedural macros.
9 use proc_macro::TokenStream;
11 /// Declares a kernel module.
13 /// The `type` argument should be a type which implements the [`Module`]
14 /// trait. Also accepts various forms of kernel metadata.
16 /// C header: [`include/linux/moduleparam.h`](../../../include/linux/moduleparam.h)
18 /// [`Module`]: ../kernel/trait.Module.html
23 /// use kernel::prelude::*;
27 /// name: b"my_kernel_module",
28 /// author: b"Rust for Linux Contributors",
29 /// description: b"My very own kernel module!",
34 /// permissions: 0o000,
35 /// description: b"Example of i32",
37 /// writeable_i32: i32 {
39 /// permissions: 0o644,
40 /// description: b"Example of i32",
47 /// impl kernel::Module for MyModule {
48 /// fn init() -> Result<Self> {
49 /// // If the parameter is writeable, then the kparam lock must be
50 /// // taken to read the parameter:
52 /// let lock = THIS_MODULE.kernel_param_lock();
53 /// pr_info!("i32 param is: {}\n", writeable_i32.read(&lock));
55 /// // If the parameter is read only, it can be read without locking
56 /// // the kernel parameters:
57 /// pr_info!("i32 param is: {}\n", my_i32.read());
63 /// # Supported argument types
64 /// - `type`: type which implements the [`Module`] trait (required).
65 /// - `name`: byte array of the name of the kernel module (required).
66 /// - `author`: byte array of the author of the kernel module.
67 /// - `description`: byte array of the description of the kernel module.
68 /// - `license`: byte array of the license of the kernel module (required).
69 /// - `alias`: byte array of alias name of the kernel module.
71 pub fn module(ts: TokenStream) -> TokenStream {
75 /// Concatenate two identifiers.
77 /// This is useful in macros that need to declare or reference items with names
78 /// starting with a fixed prefix and ending in a user specified name. The resulting
79 /// identifier has the span of the second argument.
84 /// use kernel::macro::concat_idents;
86 /// macro_rules! pub_no_prefix {
87 /// ($prefix:ident, $($newname:ident),+) => {
88 /// $(pub(crate) const $newname: u32 = kernel::macros::concat_idents!($prefix, $newname);)+
93 /// binder_driver_return_protocol_,
99 /// BR_TRANSACTION_COMPLETE,
107 /// BR_CLEAR_DEATH_NOTIFICATION_DONE,
111 /// assert_eq!(BR_OK, binder_driver_return_protocol_BR_OK);
114 pub fn concat_idents(ts: TokenStream) -> TokenStream {
115 concat_idents::concat_idents(ts)