aya: set .rodata maps as BPF_F_RDONLY.

pull/117/head
Thia Wyrod 3 years ago
parent df393690d3
commit 4dcf46e357
No known key found for this signature in database
GPG Key ID: 55D3AB7E5658CA0C

@ -510,20 +510,31 @@ impl From<KernelVersion> for u32 {
} }
} }
fn data_section_def(section: &Section, map_flags: u32) -> bpf_map_def {
bpf_map_def {
map_type: BPF_MAP_TYPE_ARRAY as u32,
key_size: mem::size_of::<u32>() as u32,
// We need to use section.size here since
// .bss will always have data.len() == 0
value_size: section.size as u32,
max_entries: 1,
map_flags,
..Default::default()
}
}
fn parse_map(section: &Section, name: &str) -> Result<Map, ParseError> { fn parse_map(section: &Section, name: &str) -> Result<Map, ParseError> {
let (def, data) = if name == ".bss" || name.starts_with(".data") || name.starts_with(".rodata") // TODO: Create an equivalent of aya-bpf-bindings for aya and define this
{ // there. This value is the same across armv7, amd64, and aarch64.
let def = bpf_map_def { const BPF_F_RDONLY: u32 = 8;
map_type: BPF_MAP_TYPE_ARRAY as u32,
key_size: mem::size_of::<u32>() as u32, let (def, data) = if name == ".bss" || name.starts_with(".data") {
// We need to use section.size here since (data_section_def(section, 0), section.data.to_vec())
// .bss will always have data.len() == 0 } else if name.starts_with(".rodata") {
value_size: section.size as u32, (
max_entries: 1, data_section_def(section, BPF_F_RDONLY),
map_flags: 0, /* FIXME: set rodata readonly */ section.data.to_vec(),
..Default::default() )
};
(def, section.data.to_vec())
} else { } else {
(parse_map_def(name, section.data)?, Vec::new()) (parse_map_def(name, section.data)?, Vec::new())
}; };

Loading…
Cancel
Save