|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2 | 2 |
|
3 | | -//! Proc macro crate implementing the [`module!`] magic. |
4 | | -//! |
5 | | -//! C header: [`include/linux/moduleparam.h`](../../../include/linux/moduleparam.h) |
6 | | -
|
7 | | -#![deny(clippy::complexity)] |
8 | | -#![deny(clippy::correctness)] |
9 | | -#![deny(clippy::perf)] |
10 | | -#![deny(clippy::style)] |
11 | | - |
12 | 3 | use proc_macro::{token_stream, Delimiter, Group, TokenStream, TokenTree}; |
13 | 4 |
|
14 | 5 | fn try_ident(it: &mut token_stream::IntoIter) -> Option<String> { |
@@ -399,86 +390,6 @@ impl ModuleInfo { |
399 | 390 | } |
400 | 391 | } |
401 | 392 |
|
402 | | -/// Declares a kernel module. |
403 | | -/// |
404 | | -/// The `type` argument should be a type which implements the [`KernelModule`] |
405 | | -/// trait. Also accepts various forms of kernel metadata. |
406 | | -/// |
407 | | -/// [`KernelModule`]: ../kernel/trait.KernelModule.html |
408 | | -/// |
409 | | -/// # Examples |
410 | | -/// |
411 | | -/// ```rust,no_run |
412 | | -/// use kernel::prelude::*; |
413 | | -/// |
414 | | -/// module!{ |
415 | | -/// type: MyKernelModule, |
416 | | -/// name: b"my_kernel_module", |
417 | | -/// author: b"Rust for Linux Contributors", |
418 | | -/// description: b"My very own kernel module!", |
419 | | -/// license: b"GPL v2", |
420 | | -/// params: { |
421 | | -/// my_i32: i32 { |
422 | | -/// default: 42, |
423 | | -/// permissions: 0o000, |
424 | | -/// description: b"Example of i32", |
425 | | -/// }, |
426 | | -/// writeable_i32: i32 { |
427 | | -/// default: 42, |
428 | | -/// permissions: 0o644, |
429 | | -/// description: b"Example of i32", |
430 | | -/// }, |
431 | | -/// }, |
432 | | -/// } |
433 | | -/// |
434 | | -/// struct MyKernelModule; |
435 | | -/// |
436 | | -/// impl KernelModule for MyKernelModule { |
437 | | -/// fn init() -> Result<Self> { |
438 | | -/// // If the parameter is writeable, then the kparam lock must be |
439 | | -/// // taken to read the parameter: |
440 | | -/// { |
441 | | -/// let lock = THIS_MODULE.kernel_param_lock(); |
442 | | -/// pr_info!("i32 param is: {}\n", writeable_i32.read(&lock)); |
443 | | -/// } |
444 | | -/// // If the parameter is read only, it can be read without locking |
445 | | -/// // the kernel parameters: |
446 | | -/// pr_info!("i32 param is: {}\n", my_i32.read()); |
447 | | -/// Ok(MyKernelModule) |
448 | | -/// } |
449 | | -/// } |
450 | | -/// ``` |
451 | | -/// |
452 | | -/// # Supported argument types |
453 | | -/// - `type`: type which implements the [`KernelModule`] trait (required). |
454 | | -/// - `name`: byte array of the name of the kernel module (required). |
455 | | -/// - `author`: byte array of the author of the kernel module. |
456 | | -/// - `description`: byte array of the description of the kernel module. |
457 | | -/// - `license`: byte array of the license of the kernel module (required). |
458 | | -/// - `alias`: byte array of alias name of the kernel module. |
459 | | -/// - `alias_rtnl_link`: byte array of the `rtnl_link_alias` of the kernel module (mutually exclusive with `alias`). |
460 | | -/// - `params`: parameters for the kernel module, as described below. |
461 | | -/// |
462 | | -/// # Supported parameter types |
463 | | -/// |
464 | | -/// - `bool`: Corresponds to C `bool` param type. |
465 | | -/// - `i8`: No equivalent C param type. |
466 | | -/// - `u8`: Corresponds to C `char` param type. |
467 | | -/// - `i16`: Corresponds to C `short` param type. |
468 | | -/// - `u16`: Corresponds to C `ushort` param type. |
469 | | -/// - `i32`: Corresponds to C `int` param type. |
470 | | -/// - `u32`: Corresponds to C `uint` param type. |
471 | | -/// - `i64`: No equivalent C param type. |
472 | | -/// - `u64`: Corresponds to C `ullong` param type. |
473 | | -/// - `isize`: No equivalent C param type. |
474 | | -/// - `usize`: No equivalent C param type. |
475 | | -/// - `str`: Corresponds to C `charp` param type. Reading returns a byte slice. |
476 | | -/// - `ArrayParam<T,N>`: Corresponds to C parameters created using `module_param_array`. An array |
477 | | -/// of `T`'s of length at **most** `N`. |
478 | | -/// |
479 | | -/// `invbool` is unsupported: it was only ever used in a few modules. |
480 | | -/// Consider using a `bool` and inverting the logic instead. |
481 | | -#[proc_macro] |
482 | 393 | pub fn module(ts: TokenStream) -> TokenStream { |
483 | 394 | let mut it = ts.into_iter(); |
484 | 395 |
|
@@ -775,34 +686,6 @@ pub fn module(ts: TokenStream) -> TokenStream { |
775 | 686 | ).parse().expect("Error parsing formatted string into token stream.") |
776 | 687 | } |
777 | 688 |
|
778 | | -/// Declares a kernel module that exposes a single misc device. |
779 | | -/// |
780 | | -/// The `type` argument should be a type which implements the [`FileOpener`] trait. Also accepts |
781 | | -/// various forms of kernel metadata. |
782 | | -/// |
783 | | -/// [`FileOpener`]: ../kernel/file_operations/trait.FileOpener.html |
784 | | -/// |
785 | | -/// # Examples |
786 | | -/// |
787 | | -/// ```rust,no_run |
788 | | -/// use kernel::prelude::*; |
789 | | -/// |
790 | | -/// module_misc_device! { |
791 | | -/// type: MyFile, |
792 | | -/// name: b"my_miscdev_kernel_module", |
793 | | -/// author: b"Rust for Linux Contributors", |
794 | | -/// description: b"My very own misc device kernel module!", |
795 | | -/// license: b"GPL v2", |
796 | | -/// } |
797 | | -/// |
798 | | -/// #[derive(Default)] |
799 | | -/// struct MyFile; |
800 | | -/// |
801 | | -/// impl kernel::file_operations::FileOperations for MyFile { |
802 | | -/// kernel::declare_file_operations!(); |
803 | | -/// } |
804 | | -/// ``` |
805 | | -#[proc_macro] |
806 | 689 | pub fn module_misc_device(ts: TokenStream) -> TokenStream { |
807 | 690 | let mut it = ts.into_iter(); |
808 | 691 |
|
|
0 commit comments