|
1 | 1 | // SPDX-License-Identifier: Apache-2.0 OR MIT
|
2 | 2 |
|
3 |
| -/// Used to specify the pinning information of the fields of a struct. |
4 |
| -/// |
5 |
| -/// This is somewhat similar in purpose as |
6 |
| -/// [pin-project-lite](https://crates.io/crates/pin-project-lite). |
7 |
| -/// Place this macro on a struct definition and then `#[pin]` in front of the attributes of each |
8 |
| -/// field you want to structurally pin. |
9 |
| -/// |
10 |
| -/// This macro enables the use of the [`pin_init!`] macro. When pin-initializing a `struct`, |
11 |
| -/// then `#[pin]` directs the type of initializer that is required. |
12 |
| -/// |
13 |
| -/// If your `struct` implements `Drop`, then you need to add `PinnedDrop` as arguments to this |
14 |
| -/// macro, and change your `Drop` implementation to `PinnedDrop` annotated with |
15 |
| -/// `#[`[`macro@pinned_drop`]`]`, since dropping pinned values requires extra care. |
16 |
| -/// |
17 |
| -/// # Examples |
18 |
| -/// |
19 |
| -/// ```ignore |
20 |
| -/// # #![feature(lint_reasons)] |
21 |
| -/// # use kernel::prelude::*; |
22 |
| -/// # use std::{sync::Mutex, process::Command}; |
23 |
| -/// # use kernel::macros::pin_data; |
24 |
| -/// #[pin_data] |
25 |
| -/// struct DriverData { |
26 |
| -/// #[pin] |
27 |
| -/// queue: Mutex<KVec<Command>>, |
28 |
| -/// buf: KBox<[u8; 1024 * 1024]>, |
29 |
| -/// } |
30 |
| -/// ``` |
31 |
| -/// |
32 |
| -/// ```ignore |
33 |
| -/// # #![feature(lint_reasons)] |
34 |
| -/// # use kernel::prelude::*; |
35 |
| -/// # use std::{sync::Mutex, process::Command}; |
36 |
| -/// # use core::pin::Pin; |
37 |
| -/// # pub struct Info; |
38 |
| -/// # mod bindings { |
39 |
| -/// # pub unsafe fn destroy_info(_ptr: *mut super::Info) {} |
40 |
| -/// # } |
41 |
| -/// use kernel::macros::{pin_data, pinned_drop}; |
42 |
| -/// |
43 |
| -/// #[pin_data(PinnedDrop)] |
44 |
| -/// struct DriverData { |
45 |
| -/// #[pin] |
46 |
| -/// queue: Mutex<KVec<Command>>, |
47 |
| -/// buf: KBox<[u8; 1024 * 1024]>, |
48 |
| -/// raw_info: *mut Info, |
49 |
| -/// } |
50 |
| -/// |
51 |
| -/// #[pinned_drop] |
52 |
| -/// impl PinnedDrop for DriverData { |
53 |
| -/// fn drop(self: Pin<&mut Self>) { |
54 |
| -/// unsafe { bindings::destroy_info(self.raw_info) }; |
55 |
| -/// } |
56 |
| -/// } |
57 |
| -/// # fn main() {} |
58 |
| -/// ``` |
59 |
| -/// |
60 |
| -/// [`pin_init!`]: ../kernel/macro.pin_init.html |
61 |
| -// ^ cannot use direct link, since `kernel` is not a dependency of `macros`. |
| 3 | +#[allow(missing_docs)] |
62 | 4 | #[proc_macro_attribute]
|
63 | 5 | pub fn pin_data(inner: TokenStream, item: TokenStream) -> TokenStream {
|
64 | 6 | pin_data::pin_data(inner, item)
|
65 | 7 | }
|
66 | 8 |
|
67 |
| -/// Used to implement `PinnedDrop` safely. |
68 |
| -/// |
69 |
| -/// Only works on structs that are annotated via `#[`[`macro@pin_data`]`]`. |
70 |
| -/// |
71 |
| -/// # Examples |
72 |
| -/// |
73 |
| -/// ```ignore |
74 |
| -/// # #![feature(lint_reasons)] |
75 |
| -/// # use kernel::prelude::*; |
76 |
| -/// # use macros::{pin_data, pinned_drop}; |
77 |
| -/// # use std::{sync::Mutex, process::Command}; |
78 |
| -/// # use core::pin::Pin; |
79 |
| -/// # mod bindings { |
80 |
| -/// # pub struct Info; |
81 |
| -/// # pub unsafe fn destroy_info(_ptr: *mut Info) {} |
82 |
| -/// # } |
83 |
| -/// #[pin_data(PinnedDrop)] |
84 |
| -/// struct DriverData { |
85 |
| -/// #[pin] |
86 |
| -/// queue: Mutex<KVec<Command>>, |
87 |
| -/// buf: KBox<[u8; 1024 * 1024]>, |
88 |
| -/// raw_info: *mut bindings::Info, |
89 |
| -/// } |
90 |
| -/// |
91 |
| -/// #[pinned_drop] |
92 |
| -/// impl PinnedDrop for DriverData { |
93 |
| -/// fn drop(self: Pin<&mut Self>) { |
94 |
| -/// unsafe { bindings::destroy_info(self.raw_info) }; |
95 |
| -/// } |
96 |
| -/// } |
97 |
| -/// ``` |
| 9 | +#[allow(missing_docs)] |
98 | 10 | #[proc_macro_attribute]
|
99 | 11 | pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
|
100 | 12 | pinned_drop::pinned_drop(args, input)
|
101 | 13 | }
|
102 | 14 |
|
103 |
| -/// Derives the [`Zeroable`] trait for the given struct. |
104 |
| -/// |
105 |
| -/// This can only be used for structs where every field implements the [`Zeroable`] trait. |
106 |
| -/// |
107 |
| -/// # Examples |
108 |
| -/// |
109 |
| -/// ```ignore |
110 |
| -/// use kernel::macros::Zeroable; |
111 |
| -/// |
112 |
| -/// #[derive(Zeroable)] |
113 |
| -/// pub struct DriverData { |
114 |
| -/// id: i64, |
115 |
| -/// buf_ptr: *mut u8, |
116 |
| -/// len: usize, |
117 |
| -/// } |
118 |
| -/// ``` |
| 15 | +#[allow(missing_docs)] |
119 | 16 | #[proc_macro_derive(Zeroable)]
|
120 | 17 | pub fn derive_zeroable(input: TokenStream) -> TokenStream {
|
121 | 18 | zeroable::derive(input)
|
|
0 commit comments