mmarinus/
perms.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Permissions for a mapping
3
4#![allow(missing_docs)]
5
6macro_rules! perm {
7        ($($name:ident[$($trait:ident),* $(,)?] => $value:expr),+ $(,)?) => {
8            $(
9                #[derive(Debug)]
10                pub struct $name;
11
12                impl super::map::Known for $name {
13                    const VALUE: libc::c_int = $value;
14                }
15
16                $(
17                    impl super::map::$trait for $name {}
18                )*
19            )+
20        };
21    }
22
23perm! {
24    None[] => libc::PROT_NONE,
25    Read[Readable] => libc::PROT_READ,
26    Write[Writeable] => libc::PROT_WRITE,
27    Execute[Executable] => libc::PROT_EXEC,
28    ReadWrite[Readable, Writeable] => libc::PROT_READ | libc::PROT_WRITE,
29    ReadExecute[Readable, Executable] => libc::PROT_READ | libc::PROT_EXEC,
30    WriteExecute[Writeable, Executable] => libc::PROT_WRITE | libc::PROT_EXEC,
31    ReadWriteExecute[Readable, Writeable, Executable] => libc::PROT_READ | libc::PROT_WRITE | libc::PROT_EXEC,
32}
33
34pub struct Unknown(pub libc::c_int);
35
36impl super::map::Type for Unknown {
37    #[inline]
38    fn perms(self) -> libc::c_int {
39        self.0
40    }
41}