elf_utilities/segment/
segment_flag.rs

1//! Type definitions for segment flags.
2
3use crate::*;
4
5#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy, Hash)]
6/// Segment flags
7pub enum Flag {
8    /// Segment is executable
9    X,
10    /// segment is writable
11    W,
12    /// segment is readable
13    R,
14}
15
16impl Into<Elf64Word> for Flag {
17    fn into(self) -> Elf64Word {
18        match self {
19            Flag::X => 1 << 0,
20            Flag::W => 1 << 1,
21            Flag::R => 1 << 2,
22        }
23    }
24}
25
26impl From<Elf64Word> for Flag {
27    fn from(v: Elf64Word) -> Self {
28        match v {
29            0b1 => Flag::X,
30            0b10 => Flag::W,
31            0b100 => Flag::R,
32            _ => unimplemented!(),
33        }
34    }
35}