From 42bb3938df78686b6d1ceae003ce8c149f8dc9d8 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 18 Apr 2025 14:42:05 -0400 Subject: Add a setting to disable creating a backing memory region for SVD regions This is apart of https://github.com/Vector35/binaryninja-api/issues/6678 --- plugins/svd/src/mapper.rs | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'plugins/svd/src/mapper.rs') diff --git a/plugins/svd/src/mapper.rs b/plugins/svd/src/mapper.rs index c0ca5e99..0a476481 100644 --- a/plugins/svd/src/mapper.rs +++ b/plugins/svd/src/mapper.rs @@ -163,24 +163,29 @@ impl DeviceMapper { let memory_info = self.peripheral_block_memory_info(peripheral, address_block, block_name.clone()); - // Add the block segment, section and backing memory. - let data_memory = DataBuffer::new(&vec![0; address_block.size as usize]).unwrap(); - let added_memory = view.memory_map().add_data_memory_region( - &block_name, - block_addr, - &data_memory, - Some(memory_info.segment_flags), - ); - view.add_segment(memory_info.segment); - view.add_section(memory_info.section); - - if !added_memory { - log::error!( - "Failed to add memory for peripheral block! {} @ 0x{:x}", - block_name, - block_addr + // Add the block segment, section and backing memory (optional). + if self.settings.add_backing_regions { + // Because adding a memory region will add a possibly large memory buffer in the BNDB, this + // is optional. if a user disables this, they cannot write to the segment until they add a backing memory region. + let data_memory = DataBuffer::new(&vec![0; address_block.size as usize]).unwrap(); + let added_memory = view.memory_map().add_data_memory_region( + &block_name, + block_addr, + &data_memory, + Some(memory_info.segment_flags), ); + + if !added_memory { + log::error!( + "Failed to add memory for peripheral block! {} @ 0x{:x}", + block_name, + block_addr + ); + } } + + view.add_segment(memory_info.segment); + view.add_section(memory_info.section); // Handle usage specific stuff like adding registers. match address_block.usage { -- cgit v1.3.1