components/storage_permissions/
individual.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2024.

//! Component for creating a storage permissions policy that grants applications
//! access to their own stored state.
//!
//! ```rust
//! let storage_permissions_policy =
//!     components::storage_permissions::individual::StoragePermissionsIndividualComponent::new()
//!         .finalize(
//!             components::storage_permissions_individual_component_static!(nrf52840dk_lib::Chip),
//!         );
//! ```

use core::mem::MaybeUninit;
use kernel::capabilities;
use kernel::component::Component;
use kernel::platform::chip::Chip;
use kernel::process::ProcessStandardDebug;

#[macro_export]
macro_rules! storage_permissions_individual_component_static {
    ($C:ty, $D:ty $(,)?) => {{
        kernel::static_buf!(
            capsules_system::storage_permissions::individual::IndividualStoragePermissions<
                $C,
                $D,
                components::storage_permissions::individual::AppStoreCapability
            >
        )
    };};
}

pub struct AppStoreCapability;
unsafe impl capabilities::ApplicationStorageCapability for AppStoreCapability {}

pub type StoragePermissionsIndividualComponentType<C, D> =
    capsules_system::storage_permissions::individual::IndividualStoragePermissions<
        C,
        D,
        AppStoreCapability,
    >;

pub struct StoragePermissionsIndividualComponent<C: Chip, D: ProcessStandardDebug> {
    _chip: core::marker::PhantomData<C>,
    _debug: core::marker::PhantomData<D>,
}

impl<C: Chip, D: ProcessStandardDebug> StoragePermissionsIndividualComponent<C, D> {
    pub fn new() -> Self {
        Self {
            _chip: core::marker::PhantomData,
            _debug: core::marker::PhantomData,
        }
    }
}

impl<C: Chip + 'static, D: ProcessStandardDebug + 'static> Component
    for StoragePermissionsIndividualComponent<C, D>
{
    type StaticInput = &'static mut MaybeUninit<
        capsules_system::storage_permissions::individual::IndividualStoragePermissions<
            C,
            D,
            AppStoreCapability,
        >,
    >;
    type Output =
        &'static capsules_system::storage_permissions::individual::IndividualStoragePermissions<
            C,
            D,
            AppStoreCapability,
        >;

    fn finalize(self, s: Self::StaticInput) -> Self::Output {
        s.write(
            capsules_system::storage_permissions::individual::IndividualStoragePermissions::new(
                AppStoreCapability,
            ),
        )
    }
}