wasmer_compiler/
section.rs1use crate::lib::std::vec::Vec;
9use crate::Relocation;
10use wasmer_types::entity::entity_impl;
11
12#[derive(rkyv::Serialize, rkyv::Deserialize, rkyv::Archive)]
14#[archive_attr(derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug))]
15#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
16pub struct SectionIndex(u32);
17
18entity_impl!(SectionIndex);
19
20entity_impl!(ArchivedSectionIndex);
21
22#[derive(rkyv::Serialize, rkyv::Deserialize, rkyv::Archive, Debug, Copy, Clone, PartialEq, Eq)]
26pub enum CustomSectionProtection {
27 Read,
29
30 ReadExecute,
32}
33
34#[derive(rkyv::Serialize, rkyv::Deserialize, rkyv::Archive, Debug, Clone, PartialEq, Eq)]
39pub struct CustomSection {
40 pub protection: CustomSectionProtection,
42
43 pub bytes: SectionBody,
50
51 pub relocations: Vec<Relocation>,
53}
54
55#[derive(Clone, Copy)]
59pub struct CustomSectionRef<'a> {
60 pub protection: CustomSectionProtection,
62
63 pub bytes: &'a [u8],
65}
66
67impl<'a> From<&'a CustomSection> for CustomSectionRef<'a> {
68 fn from(section: &'a CustomSection) -> Self {
69 CustomSectionRef {
70 protection: section.protection.clone(),
71 bytes: section.bytes.as_slice(),
72 }
73 }
74}
75
76impl<'a> From<&'a ArchivedCustomSection> for CustomSectionRef<'a> {
77 fn from(section: &'a ArchivedCustomSection) -> Self {
78 CustomSectionRef {
79 protection: Result::<_, std::convert::Infallible>::unwrap(
80 rkyv::Deserialize::deserialize(§ion.protection, &mut rkyv::Infallible),
81 ),
82 bytes: §ion.bytes.0[..],
83 }
84 }
85}
86
87#[derive(
89 rkyv::Serialize, rkyv::Deserialize, rkyv::Archive, Debug, Clone, PartialEq, Eq, Default,
90)]
91pub struct SectionBody(Vec<u8>);
92
93impl SectionBody {
94 pub fn new_with_vec(contents: Vec<u8>) -> Self {
96 Self(contents)
97 }
98
99 pub fn as_ptr(&self) -> *const u8 {
101 self.0.as_ptr()
102 }
103
104 pub fn len(&self) -> usize {
106 self.0.len()
107 }
108
109 pub fn as_slice(&self) -> &[u8] {
111 self.0.as_slice()
112 }
113
114 pub fn is_empty(&self) -> bool {
116 self.0.is_empty()
117 }
118}