Skip to main content

kernel/
auxiliary.rs

1// SPDX-License-Identifier: GPL-2.0
2
3//! Abstractions for the auxiliary bus.
4//!
5//! C header: [`include/linux/auxiliary_bus.h`](srctree/include/linux/auxiliary_bus.h)
6
7use crate::{
8    bindings,
9    container_of,
10    device,
11    device_id::{
12        RawDeviceId,
13        RawDeviceIdIndex, //
14    },
15
16    driver,
17    error::{
18        from_result,
19        to_result, //
20    },
21    prelude::*,
22    types::{
23        CovariantForLt,
24        ForLt,
25        ForeignOwnable,
26        Opaque, //
27    },
28    ThisModule, //
29};
30use core::{
31    any::TypeId,
32    marker::PhantomData,
33    mem::offset_of,
34    pin::Pin,
35    ptr::{
36        addr_of_mut,
37        NonNull, //
38    },
39};
40
41/// An adapter for the registration of auxiliary drivers.
42pub struct Adapter<T: Driver>(T);
43
44// SAFETY:
45// - `bindings::auxiliary_driver` is a C type declared as `repr(C)`.
46// - `T::Data` is the type of the driver's device private data.
47// - `struct auxiliary_driver` embeds a `struct device_driver`.
48// - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`.
49unsafe impl<T: Driver> driver::DriverLayout for Adapter<T> {
50    type DriverType = bindings::auxiliary_driver;
51    type DriverData<'bound> = T::Data<'bound>;
52    const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver);
53}
54
55// SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if
56// a preceding call to `register` has been successful.
57unsafe impl<T: Driver> driver::RegistrationOps for Adapter<T> {
58    unsafe fn register(
59        adrv: &Opaque<Self::DriverType>,
60        name: &'static CStr,
61        module: &'static ThisModule,
62    ) -> Result {
63        // SAFETY: It's safe to set the fields of `struct auxiliary_driver` on initialization.
64        unsafe {
65            (*adrv.get()).name = name.as_char_ptr();
66            (*adrv.get()).probe = Some(Self::probe_callback);
67            (*adrv.get()).remove = Some(Self::remove_callback);
68            (*adrv.get()).id_table = T::ID_TABLE.as_ptr();
69        }
70
71        // SAFETY: `adrv` is guaranteed to be a valid `DriverType`.
72        to_result(unsafe {
73            bindings::__auxiliary_driver_register(adrv.get(), module.0, name.as_char_ptr())
74        })
75    }
76
77    unsafe fn unregister(adrv: &Opaque<Self::DriverType>) {
78        // SAFETY: `adrv` is guaranteed to be a valid `DriverType`.
79        unsafe { bindings::auxiliary_driver_unregister(adrv.get()) }
80    }
81}
82
83impl<T: Driver> Adapter<T> {
84    extern "C" fn probe_callback(
85        adev: *mut bindings::auxiliary_device,
86        id: *const bindings::auxiliary_device_id,
87    ) -> c_int {
88        // SAFETY: The auxiliary bus only ever calls the probe callback with a valid pointer to a
89        // `struct auxiliary_device`.
90        //
91        // INVARIANT: `adev` is valid for the duration of `probe_callback()`.
92        let adev = unsafe { &*adev.cast::<Device<device::CoreInternal<'_>>>() };
93
94        // SAFETY: `DeviceId` is a `#[repr(transparent)`] wrapper of `struct auxiliary_device_id`
95        // and does not add additional invariants, so it's safe to transmute.
96        let id = unsafe { &*id.cast::<DeviceId>() };
97        let info = T::ID_TABLE.info(id.index());
98
99        from_result(|| {
100            let data = T::probe(adev, info);
101
102            adev.as_ref().set_drvdata(data)?;
103            Ok(0)
104        })
105    }
106
107    extern "C" fn remove_callback(adev: *mut bindings::auxiliary_device) {
108        // SAFETY: The auxiliary bus only ever calls the probe callback with a valid pointer to a
109        // `struct auxiliary_device`.
110        //
111        // INVARIANT: `adev` is valid for the duration of `remove_callback()`.
112        let adev = unsafe { &*adev.cast::<Device<device::CoreInternal<'_>>>() };
113
114        // SAFETY: `remove_callback` is only ever called after a successful call to
115        // `probe_callback`, hence it's guaranteed that `Device::set_drvdata()` has been called
116        // and stored a `Pin<KBox<T::Data<'_>>>`.
117        let data = unsafe { adev.as_ref().drvdata_borrow::<T::Data<'_>>() };
118
119        T::unbind(adev, data);
120    }
121}
122
123/// Declares a kernel module that exposes a single auxiliary driver.
124#[macro_export]
125macro_rules! module_auxiliary_driver {
126    ($($f:tt)*) => {
127        $crate::module_driver!(<T>, $crate::auxiliary::Adapter<T>, { $($f)* });
128    };
129}
130
131/// Abstraction for `bindings::auxiliary_device_id`.
132#[repr(transparent)]
133#[derive(Clone, Copy)]
134pub struct DeviceId(bindings::auxiliary_device_id);
135
136impl DeviceId {
137    /// Create a new [`DeviceId`] from name.
138    pub const fn new(modname: &'static CStr, name: &'static CStr) -> Self {
139        let name = name.to_bytes_with_nul();
140        let modname = modname.to_bytes_with_nul();
141
142        let mut id: bindings::auxiliary_device_id = pin_init::zeroed();
143        let mut i = 0;
144        while i < modname.len() {
145            id.name[i] = modname[i];
146            i += 1;
147        }
148
149        // Reuse the space of the NULL terminator.
150        id.name[i - 1] = b'.';
151
152        let mut j = 0;
153        while j < name.len() {
154            id.name[i] = name[j];
155            i += 1;
156            j += 1;
157        }
158
159        Self(id)
160    }
161}
162
163// SAFETY: `DeviceId` is a `#[repr(transparent)]` wrapper of `auxiliary_device_id` and does not add
164// additional invariants, so it's safe to transmute to `RawType`.
165unsafe impl RawDeviceId for DeviceId {
166    type RawType = bindings::auxiliary_device_id;
167}
168
169// SAFETY: `DRIVER_DATA_OFFSET` is the offset to the `driver_data` field.
170unsafe impl RawDeviceIdIndex for DeviceId {
171    const DRIVER_DATA_OFFSET: usize =
172        core::mem::offset_of!(bindings::auxiliary_device_id, driver_data);
173
174    fn index(&self) -> usize {
175        self.0.driver_data
176    }
177}
178
179/// IdTable type for auxiliary drivers.
180pub type IdTable<T> = &'static dyn kernel::device_id::IdTable<DeviceId, T>;
181
182/// Create a auxiliary `IdTable` with its alias for modpost.
183#[macro_export]
184macro_rules! auxiliary_device_table {
185    ($table_name:ident, $module_table_name:ident, $id_info_type: ty, $table_data: expr) => {
186        const $table_name: $crate::device_id::IdArray<
187            $crate::auxiliary::DeviceId,
188            $id_info_type,
189            { $table_data.len() },
190        > = $crate::device_id::IdArray::new($table_data);
191
192        $crate::module_device_table!("auxiliary", $module_table_name, $table_name);
193    };
194}
195
196/// The auxiliary driver trait.
197///
198/// Drivers must implement this trait in order to get an auxiliary driver registered.
199pub trait Driver {
200    /// The type holding information about each device id supported by the driver.
201    ///
202    /// TODO: Use associated_type_defaults once stabilized:
203    ///
204    /// type IdInfo: 'static = ();
205    type IdInfo: 'static;
206
207    /// The type of the driver's bus device private data.
208    type Data<'bound>: Send + 'bound;
209
210    /// The table of device ids supported by the driver.
211    const ID_TABLE: IdTable<Self::IdInfo>;
212
213    /// Auxiliary driver probe.
214    ///
215    /// Called when an auxiliary device is matches a corresponding driver.
216    fn probe<'bound>(
217        dev: &'bound Device<device::Core<'_>>,
218        id_info: &'bound Self::IdInfo,
219    ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound;
220
221    /// Auxiliary driver unbind.
222    ///
223    /// Called when a [`Device`] is unbound from its bound [`Driver`]. Implementing this callback
224    /// is optional.
225    ///
226    /// This callback serves as a place for drivers to perform teardown operations that require a
227    /// `&Device<Core>` or `&Device<Bound>` reference. For instance, drivers may try to perform I/O
228    /// operations to gracefully tear down the device.
229    ///
230    /// Otherwise, release operations for driver resources should be performed in `Drop`.
231    fn unbind<'bound>(dev: &'bound Device<device::Core<'_>>, this: Pin<&Self::Data<'bound>>) {
232        let _ = (dev, this);
233    }
234}
235
236/// The auxiliary device representation.
237///
238/// This structure represents the Rust abstraction for a C `struct auxiliary_device`. The
239/// implementation abstracts the usage of an already existing C `struct auxiliary_device` within
240/// Rust code that we get passed from the C side.
241///
242/// # Invariants
243///
244/// A [`Device`] instance represents a valid `struct auxiliary_device` created by the C portion of
245/// the kernel.
246#[repr(transparent)]
247pub struct Device<Ctx: device::DeviceContext = device::Normal>(
248    Opaque<bindings::auxiliary_device>,
249    PhantomData<Ctx>,
250);
251
252impl<Ctx: device::DeviceContext> Device<Ctx> {
253    fn as_raw(&self) -> *mut bindings::auxiliary_device {
254        self.0.get()
255    }
256
257    /// Returns the auxiliary device' id.
258    pub fn id(&self) -> u32 {
259        // SAFETY: By the type invariant `self.as_raw()` is a valid pointer to a
260        // `struct auxiliary_device`.
261        unsafe { (*self.as_raw()).id }
262    }
263}
264
265impl Device<device::Bound> {
266    /// Returns a bound reference to the parent [`device::Device`].
267    pub fn parent(&self) -> &device::Device<device::Bound> {
268        let parent = (**self).parent();
269
270        // SAFETY: A bound auxiliary device always has a bound parent device.
271        unsafe { parent.as_bound() }
272    }
273
274    /// Returns the stored registration data as a pinned reference.
275    ///
276    /// Performs null and [`TypeId`] checks, then borrows the stored [`KBox`].
277    ///
278    /// # Safety
279    ///
280    /// Callers must ensure that the lifetime shortening from the original `'static` storage to
281    /// `'_` is sound, e.g. via an HRTB closure or [`CovariantForLt`] guarantee.
282    unsafe fn registration_data_pinned<F: ForLt + 'static>(&self) -> Result<Pin<&F::Of<'_>>> {
283        // SAFETY: By the type invariant, `self.as_raw()` is a valid `struct auxiliary_device`.
284        let ptr = unsafe { (*self.as_raw()).registration_data_rust };
285        if ptr.is_null() {
286            dev_warn!(
287                self.as_ref(),
288                "No registration data set; parent is not a Rust driver.\n"
289            );
290            return Err(ENOENT);
291        }
292
293        // SAFETY: `ptr` is non-null and was set via `into_foreign()` in `Registration::new()`;
294        // `RegistrationData` is `#[repr(C)]` with `type_id` at offset 0, so reading a `TypeId`
295        // at the start of the allocation is valid regardless of `F`.
296        let type_id = unsafe { ptr.cast::<TypeId>().read() };
297        if type_id != TypeId::of::<F>() {
298            return Err(EINVAL);
299        }
300
301        // SAFETY: The `TypeId` check above confirms that the stored type matches `F`'s
302        // encoding; lifetimes are erased at runtime, so borrowing as `F::Of<'_>` is
303        // layout-compatible with the stored `F::Of<'static>`. `ptr` remains valid until
304        // `Registration::drop()` calls `from_foreign()`.
305        let wrapper = unsafe { Pin::<KBox<RegistrationData<F::Of<'_>>>>::borrow(ptr) };
306
307        // SAFETY: `data` is a structurally pinned field of `RegistrationData`.
308        Ok(unsafe { wrapper.map_unchecked(|w| &w.data) })
309    }
310
311    /// Access the registration data set by the registering (parent) driver through a closure.
312    ///
313    /// `F` is the [`ForLt`](trait@ForLt) encoding of the data type. The closure receives a pinned
314    /// reference to the registration data.
315    ///
316    /// For covariant types that implement [`trait@CovariantForLt`], prefer
317    /// [`registration_data`](Self::registration_data) which returns a direct reference.
318    ///
319    /// Returns [`EINVAL`] if `F` does not match the type used by the parent driver when calling
320    /// [`Registration::new()`].
321    ///
322    /// Returns [`ENOENT`] if no registration data has been set, e.g. when the device was
323    /// registered by a C driver.
324    #[inline]
325    pub fn registration_data_with<F: ForLt + 'static, R>(
326        &self,
327        f: impl for<'a> FnOnce(Pin<&'a F::Of<'a>>) -> R,
328    ) -> Result<R> {
329        // SAFETY: The HRTB closure prevents the caller from smuggling in references with a
330        // concrete short lifetime, making the round-trip from `'static` sound regardless of
331        // variance.
332        let pinned = unsafe { self.registration_data_pinned::<F>()? };
333
334        Ok(f(pinned))
335    }
336
337    /// Returns a pinned reference to the registration data set by the registering (parent) driver.
338    ///
339    /// This method is only available when `F` implements [`trait@CovariantForLt`], which guarantees
340    /// that the lifetime shortening is sound.
341    ///
342    /// For non-covariant types, use the closure-based [`Self::registration_data_with`].
343    ///
344    /// Returns [`EINVAL`] if `F` does not match the type used by the parent driver when calling
345    /// [`Registration::new()`].
346    ///
347    /// Returns [`ENOENT`] if no registration data has been set, e.g. when the device was
348    /// registered by a C driver.
349    #[inline]
350    pub fn registration_data<F: CovariantForLt + 'static>(&self) -> Result<Pin<&F::Of<'_>>> {
351        // SAFETY: `CovariantForLt` guarantees covariance, which makes the lifetime shortening
352        // from `'static` to `'_` performed by `registration_data_pinned` sound.
353        unsafe { self.registration_data_pinned::<F>() }
354    }
355}
356
357impl Device {
358    /// Returns a reference to the parent [`device::Device`].
359    pub fn parent(&self) -> &device::Device {
360        // SAFETY: A `struct auxiliary_device` always has a parent.
361        unsafe { self.as_ref().parent().unwrap_unchecked() }
362    }
363
364    extern "C" fn release(dev: *mut bindings::device) {
365        // SAFETY: By the type invariant `self.0.as_raw` is a pointer to the `struct device`
366        // embedded in `struct auxiliary_device`.
367        let adev = unsafe { container_of!(dev, bindings::auxiliary_device, dev) };
368
369        // SAFETY: `adev` points to the memory that has been allocated in `Registration::new`, via
370        // `KBox::new(Opaque::<bindings::auxiliary_device>::zeroed(), GFP_KERNEL)`.
371        let _ = unsafe { KBox::<Opaque<bindings::auxiliary_device>>::from_raw(adev.cast()) };
372    }
373}
374
375// SAFETY: `auxiliary::Device` is a transparent wrapper of `struct auxiliary_device`.
376// The offset is guaranteed to point to a valid device field inside `auxiliary::Device`.
377unsafe impl<Ctx: device::DeviceContext> device::AsBusDevice<Ctx> for Device<Ctx> {
378    const OFFSET: usize = offset_of!(bindings::auxiliary_device, dev);
379}
380
381// SAFETY: `Device` is a transparent wrapper of a type that doesn't depend on `Device`'s generic
382// argument.
383kernel::impl_device_context_deref!(unsafe { Device });
384kernel::impl_device_context_into_aref!(Device);
385
386// SAFETY: Instances of `Device` are always reference-counted.
387unsafe impl crate::sync::aref::AlwaysRefCounted for Device {
388    fn inc_ref(&self) {
389        // SAFETY: The existence of a shared reference guarantees that the refcount is non-zero.
390        unsafe { bindings::get_device(self.as_ref().as_raw()) };
391    }
392
393    unsafe fn dec_ref(obj: NonNull<Self>) {
394        // CAST: `Self` a transparent wrapper of `bindings::auxiliary_device`.
395        let adev: *mut bindings::auxiliary_device = obj.cast().as_ptr();
396
397        // SAFETY: By the type invariant of `Self`, `adev` is a pointer to a valid
398        // `struct auxiliary_device`.
399        let dev = unsafe { addr_of_mut!((*adev).dev) };
400
401        // SAFETY: The safety requirements guarantee that the refcount is non-zero.
402        unsafe { bindings::put_device(dev) }
403    }
404}
405
406impl<Ctx: device::DeviceContext> AsRef<device::Device<Ctx>> for Device<Ctx> {
407    fn as_ref(&self) -> &device::Device<Ctx> {
408        // SAFETY: By the type invariant of `Self`, `self.as_raw()` is a pointer to a valid
409        // `struct auxiliary_device`.
410        let dev = unsafe { addr_of_mut!((*self.as_raw()).dev) };
411
412        // SAFETY: `dev` points to a valid `struct device`.
413        unsafe { device::Device::from_raw(dev) }
414    }
415}
416
417// SAFETY: A `Device` is always reference-counted and can be released from any thread.
418unsafe impl Send for Device {}
419
420// SAFETY: `Device` can be shared among threads because all methods of `Device`
421// (i.e. `Device<Normal>) are thread safe.
422unsafe impl Sync for Device {}
423
424// SAFETY: Same as `Device<Normal>` -- the underlying `struct auxiliary_device` is the same;
425// `Bound` is a zero-sized type-state marker that does not affect thread safety.
426unsafe impl Sync for Device<device::Bound> {}
427
428/// Wrapper that stores a [`TypeId`] alongside the registration data for runtime type checking.
429#[repr(C)]
430#[pin_data]
431struct RegistrationData<T> {
432    type_id: TypeId,
433    #[pin]
434    data: T,
435}
436
437/// The registration of an auxiliary device.
438///
439/// This type represents the registration of a [`struct auxiliary_device`]. When its parent device
440/// is unbound, the corresponding auxiliary device will be unregistered from the system.
441///
442/// The type parameter `F` is a [`ForLt`](trait@ForLt) encoding of the registration
443/// data type. For non-lifetime-parameterized types, use [`ForLt!(T)`](macro@ForLt).
444///
445/// The data can be accessed by the auxiliary driver through [`Device::registration_data()`] and
446/// [`Device::registration_data_with()`].
447///
448/// # Invariants
449///
450/// `self.adev` always holds a valid pointer to an initialized and registered
451/// [`struct auxiliary_device`] whose `registration_data_rust` field points to a
452/// valid `Pin<KBox<RegistrationData<F::Of<'static>>>>`.
453pub struct Registration<'a, F: ForLt + 'static> {
454    adev: NonNull<bindings::auxiliary_device>,
455    _phantom: PhantomData<F::Of<'a>>,
456}
457
458impl<'a, F: ForLt> Registration<'a, F>
459where
460    for<'b> F::Of<'b>: Send + Sync,
461{
462    /// Create and register a new auxiliary device with the given registration data.
463    ///
464    /// The `data` is owned by the registration and can be accessed through the auxiliary device
465    /// via [`Device::registration_data()`].
466    ///
467    /// # Safety
468    ///
469    /// The caller must not `mem::forget()` the returned [`Registration`] or otherwise prevent its
470    /// [`Drop`] implementation from running, since the registration data may contain borrowed
471    /// references that become invalid after `'a` ends.
472    ///
473    /// If the registration data is `'static`, use the safe [`Registration::new()`] instead.
474    pub unsafe fn new_with_lt<E>(
475        parent: &'a device::Device<device::Bound>,
476        name: &CStr,
477        id: u32,
478        modname: &CStr,
479        data: impl PinInit<F::Of<'a>, E>,
480    ) -> Result<Self>
481    where
482        Error: From<E>,
483    {
484        let data = KBox::pin_init::<Error>(
485            try_pin_init!(RegistrationData {
486                type_id: TypeId::of::<F>(),
487                data <- data,
488            }),
489            GFP_KERNEL,
490        )?;
491
492        // SAFETY: `'a` is invariant (via `Registration`'s `PhantomData`). Lifetimes do not
493        // affect layout, so RegistrationData<F::Of<'a>> and RegistrationData<F::Of<'static>>
494        // have identical representation.
495        let data: Pin<KBox<RegistrationData<F::Of<'static>>>> =
496            unsafe { core::mem::transmute(data) };
497
498        let boxed: KBox<Opaque<bindings::auxiliary_device>> = KBox::zeroed(GFP_KERNEL)?;
499        let adev = boxed.get();
500
501        // SAFETY: It's safe to set the fields of `struct auxiliary_device` on initialization.
502        unsafe {
503            (*adev).dev.parent = parent.as_raw();
504            (*adev).dev.release = Some(Device::release);
505            (*adev).name = name.as_char_ptr();
506            (*adev).id = id;
507            (*adev).registration_data_rust = data.into_foreign();
508        }
509
510        // SAFETY: `adev` is guaranteed to be a valid pointer to a `struct auxiliary_device`,
511        // which has not been initialized yet.
512        unsafe { bindings::auxiliary_device_init(adev) };
513
514        // Now that `adev` is initialized, leak the `Box`; the corresponding memory will be
515        // freed by `Device::release` when the last reference to the `struct auxiliary_device`
516        // is dropped.
517        let _ = KBox::into_raw(boxed);
518
519        // SAFETY:
520        // - `adev` is guaranteed to be a valid pointer to a `struct auxiliary_device`, which
521        //   has been initialized,
522        // - `modname.as_char_ptr()` is a NULL terminated string.
523        let ret = unsafe { bindings::__auxiliary_device_add(adev, modname.as_char_ptr()) };
524        if ret != 0 {
525            // SAFETY: `registration_data` was set above via `into_foreign()`.
526            drop(unsafe {
527                Pin::<KBox<RegistrationData<F::Of<'static>>>>::from_foreign(
528                    (*adev).registration_data_rust,
529                )
530            });
531
532            // SAFETY: `adev` is guaranteed to be a valid pointer to a
533            // `struct auxiliary_device`, which has been initialized.
534            unsafe { bindings::auxiliary_device_uninit(adev) };
535
536            return Err(Error::from_errno(ret));
537        }
538
539        // INVARIANT: The device will remain registered until `auxiliary_device_delete()` is
540        // called, which happens in `Self::drop()`.
541        Ok(Self {
542            // SAFETY: `adev` is guaranteed to be non-null, since the `KBox` was allocated
543            // successfully.
544            adev: unsafe { NonNull::new_unchecked(adev) },
545            _phantom: PhantomData,
546        })
547    }
548
549    /// Create and register a new auxiliary device with `'static` registration data.
550    ///
551    /// Safe variant of [`Registration::new_with_lt()`] for registration data that does not contain
552    /// borrowed references.
553    pub fn new<E>(
554        parent: &'a device::Device<device::Bound>,
555        name: &CStr,
556        id: u32,
557        modname: &CStr,
558        data: impl PinInit<F::Of<'a>, E>,
559    ) -> Result<Self>
560    where
561        F::Of<'a>: 'static,
562        Error: From<E>,
563    {
564        // SAFETY: `F::Of<'a>: 'static` guarantees the data contains no borrowed references,
565        // so forgetting the `Registration` cannot cause use-after-free.
566        unsafe { Self::new_with_lt(parent, name, id, modname, data) }
567    }
568}
569
570impl<F: ForLt> Drop for Registration<'_, F> {
571    fn drop(&mut self) {
572        // SAFETY: By the type invariant of `Self`, `self.adev.as_ptr()` is a valid registered
573        // `struct auxiliary_device`.
574        unsafe { bindings::auxiliary_device_delete(self.adev.as_ptr()) };
575
576        // SAFETY: `registration_data` was set in `new()` via `into_foreign()`.
577        drop(unsafe {
578            Pin::<KBox<RegistrationData<F::Of<'static>>>>::from_foreign(
579                (*self.adev.as_ptr()).registration_data_rust,
580            )
581        });
582
583        // This drops the reference we acquired through `auxiliary_device_init()`.
584        //
585        // SAFETY: By the type invariant of `Self`, `self.adev.as_ptr()` is a valid registered
586        // `struct auxiliary_device`.
587        unsafe { bindings::auxiliary_device_uninit(self.adev.as_ptr()) };
588    }
589}
590
591// SAFETY: A `Registration` of a `struct auxiliary_device` can be released from any thread.
592unsafe impl<F: ForLt> Send for Registration<'_, F> where for<'a> F::Of<'a>: Send {}
593
594// SAFETY: `Registration` does not expose any methods or fields that need synchronization.
595unsafe impl<F: ForLt> Sync for Registration<'_, F> where for<'a> F::Of<'a>: Send {}