components/storage_permissions/
tbf_header.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2024.
4
5//! Component for creating a storage permissions policy that grants applications
6//! storage permissions based on TBF headers.
7
8use core::mem::MaybeUninit;
9use kernel::component::Component;
10use kernel::platform::chip::Chip;
11use kernel::process::ProcessStandardDebug;
12
13#[macro_export]
14macro_rules! storage_permissions_tbf_header_component_static {
15    ($C:ty, $D:ty $(,)?) => {{
16        kernel::static_buf!(
17            capsules_system::storage_permissions::tbf_header::TbfHeaderStoragePermissions<
18                $C,
19                $D,
20                components::storage_permissions::tbf_header::AppStoreCapability
21            >
22        )
23    };};
24}
25
26pub struct AppStoreCapability;
27unsafe impl kernel::capabilities::ApplicationStorageCapability for AppStoreCapability {}
28
29pub type StoragePermissionsTbfHeaderComponentType<C, D> =
30    capsules_system::storage_permissions::tbf_header::TbfHeaderStoragePermissions<
31        C,
32        D,
33        AppStoreCapability,
34    >;
35
36pub struct StoragePermissionsTbfHeaderComponent<C: Chip, D: ProcessStandardDebug> {
37    _chip: core::marker::PhantomData<C>,
38    _debug: core::marker::PhantomData<D>,
39}
40
41impl<C: Chip, D: ProcessStandardDebug> StoragePermissionsTbfHeaderComponent<C, D> {
42    pub fn new() -> Self {
43        Self {
44            _chip: core::marker::PhantomData,
45            _debug: core::marker::PhantomData,
46        }
47    }
48}
49
50impl<C: Chip + 'static, D: ProcessStandardDebug + 'static> Component
51    for StoragePermissionsTbfHeaderComponent<C, D>
52{
53    type StaticInput = &'static mut MaybeUninit<
54        capsules_system::storage_permissions::tbf_header::TbfHeaderStoragePermissions<
55            C,
56            D,
57            AppStoreCapability,
58        >,
59    >;
60    type Output =
61        &'static capsules_system::storage_permissions::tbf_header::TbfHeaderStoragePermissions<
62            C,
63            D,
64            AppStoreCapability,
65        >;
66
67    fn finalize(self, s: Self::StaticInput) -> Self::Output {
68        s.write(
69            capsules_system::storage_permissions::tbf_header::TbfHeaderStoragePermissions::new(
70                AppStoreCapability,
71            ),
72        )
73    }
74}