1 //! Noop implementations of MPK primitives for environments that do not support
2 //! the feature.
3 
4 #[cfg(feature = "pooling-allocator")]
5 use crate::prelude::*;
6 
7 #[cfg(feature = "pooling-allocator")]
is_supported() -> bool8 pub fn is_supported() -> bool {
9     false
10 }
11 
12 #[cfg(feature = "pooling-allocator")]
keys(_: usize) -> &'static [ProtectionKey]13 pub fn keys(_: usize) -> &'static [ProtectionKey] {
14     &[]
15 }
16 
17 #[cfg(any(feature = "async", feature = "pooling-allocator"))]
allow(_: ProtectionMask)18 pub fn allow(_: ProtectionMask) {}
19 
20 #[cfg(feature = "async")]
current_mask() -> ProtectionMask21 pub fn current_mask() -> ProtectionMask {
22     ProtectionMask
23 }
24 
25 #[derive(Clone, Copy, Debug)]
26 pub enum ProtectionKey {}
27 
28 impl ProtectionKey {
29     #[cfg(feature = "pooling-allocator")]
protect(&self, _: &mut [u8]) -> Result<()>30     pub fn protect(&self, _: &mut [u8]) -> Result<()> {
31         match *self {}
32     }
33     #[cfg(feature = "pooling-allocator")]
as_stripe(&self) -> usize34     pub fn as_stripe(&self) -> usize {
35         match *self {}
36     }
37 }
38 
39 #[derive(Clone, Copy, Debug)]
40 #[cfg(any(feature = "async", feature = "pooling-allocator"))]
41 pub struct ProtectionMask;
42 
43 #[cfg(any(feature = "async", feature = "pooling-allocator"))]
44 impl ProtectionMask {
45     #[cfg(any(feature = "async", feature = "pooling-allocator"))]
all() -> Self46     pub fn all() -> Self {
47         Self
48     }
49     #[cfg(feature = "pooling-allocator")]
zero() -> Self50     pub fn zero() -> Self {
51         Self
52     }
53     #[cfg(feature = "pooling-allocator")]
or(self, _: ProtectionKey) -> Self54     pub fn or(self, _: ProtectionKey) -> Self {
55         Self
56     }
57 }
58