1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use super::relocation::Relocation;
use crate::entity::entity_impl;
use crate::lib::std::vec::Vec;
use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
#[derive(
RkyvSerialize,
RkyvDeserialize,
Archive,
Copy,
Clone,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
Debug,
Default,
)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[archive(as = "Self")]
pub struct SectionIndex(u32);
entity_impl!(SectionIndex);
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[derive(RkyvSerialize, RkyvDeserialize, Archive, Debug, Clone, PartialEq, Eq)]
#[archive(as = "Self")]
pub enum CustomSectionProtection {
Read,
ReadExecute,
}
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[derive(RkyvSerialize, RkyvDeserialize, Archive, Debug, Clone, PartialEq, Eq)]
pub struct CustomSection {
pub protection: CustomSectionProtection,
pub bytes: SectionBody,
pub relocations: Vec<Relocation>,
}
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
#[derive(RkyvSerialize, RkyvDeserialize, Archive, Debug, Clone, PartialEq, Eq, Default)]
pub struct SectionBody(#[cfg_attr(feature = "enable-serde", serde(with = "serde_bytes"))] Vec<u8>);
impl SectionBody {
pub fn new_with_vec(contents: Vec<u8>) -> Self {
Self(contents)
}
pub fn as_ptr(&self) -> *const u8 {
self.0.as_ptr()
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn as_slice(&self) -> &[u8] {
self.0.as_slice()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}