capsules_system/process_checker/
tbf.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//! AppID mechanisms based on TBF headers.
6
7use kernel::process::{Process, ProcessBinary, ShortId};
8use kernel::process_checker::{AppUniqueness, Compress};
9
10/// Assign AppIDs based on fields in the app's TBF header.
11///
12/// This uses the ShortId TBF header to assign short IDs to applications. If the
13/// header is not present the application will be assigned a
14/// `ShortID::LocallyUnique` ID.
15///
16/// This assigner uses ShortIds as the AppID, so the built-in check for ShortId
17/// uniqueness is sufficient.
18pub struct AppIdAssignerTbfHeader {}
19
20impl AppUniqueness for AppIdAssignerTbfHeader {
21    fn different_identifier(&self, _process_a: &ProcessBinary, _process_b: &ProcessBinary) -> bool {
22        true
23    }
24
25    fn different_identifier_process(
26        &self,
27        _process_binary: &ProcessBinary,
28        _process: &dyn Process,
29    ) -> bool {
30        true
31    }
32
33    fn different_identifier_processes(
34        &self,
35        _process_a: &dyn Process,
36        _process_b: &dyn Process,
37    ) -> bool {
38        true
39    }
40}
41
42impl Compress for AppIdAssignerTbfHeader {
43    fn to_short_id(&self, process: &ProcessBinary) -> ShortId {
44        process.header.get_fixed_short_id().into()
45    }
46}