kernel/
process_policies.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 2022.
4
5//! Process-related policies in the Tock kernel.
6//!
7//! This file contains definitions of policies the Tock kernel can use when
8//! managing processes. For example, these policies control decisions such as
9//! whether a specific process should be restarted.
10
11use crate::platform::chip::Chip;
12use crate::process;
13use crate::process::Process;
14use crate::process_standard::ProcessStandard;
15use crate::process_standard::ProcessStandardDebug;
16use crate::storage_permissions::StoragePermissions;
17
18/// Generic trait for implementing a policy on what to do when a process faults.
19///
20/// Implementations can use the `Process` reference to decide which action to
21/// take. Implementations can also use `debug!()` to print messages if desired.
22pub trait ProcessFaultPolicy {
23    /// Decide which action the kernel should take in response to `process`
24    /// faulting.
25    fn action(&self, process: &dyn Process) -> process::FaultAction;
26}
27
28/// Generic trait for implementing a policy on how applications should be
29/// assigned storage permissions.
30pub trait ProcessStandardStoragePermissionsPolicy<C: Chip, D: ProcessStandardDebug> {
31    /// Return the storage permissions for the specified `process`.
32    fn get_permissions(&self, process: &ProcessStandard<C, D>) -> StoragePermissions;
33}
34
35// Any platforms that do not issue storage permissions can use `&()` as the
36// [`ProcessStandardStoragePermissionsPolicy`]. This will only provide null
37// permissions (that is, no permission to access persistent storage).
38impl<C: Chip, D: ProcessStandardDebug> ProcessStandardStoragePermissionsPolicy<C, D> for () {
39    fn get_permissions(&self, _process: &ProcessStandard<C, D>) -> StoragePermissions {
40        StoragePermissions::new_null()
41    }
42}