From 056846723a6e2912555c6a2ef5c95874871c9b01 Mon Sep 17 00:00:00 2001 From: Serge Lamikhov-Center Date: Tue, 21 Sep 2021 00:31:47 +0300 Subject: [PATCH] Change order and meaning of address_translation structure --- elfio/elfio_utils.hpp | 12 ++++++------ examples/proc_mem/proc_mem.cpp | 4 ++-- tests/ELFIOTest2.cpp | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/elfio/elfio_utils.hpp b/elfio/elfio_utils.hpp index 2ae91f9..5e9c55b 100644 --- a/elfio/elfio_utils.hpp +++ b/elfio/elfio_utils.hpp @@ -163,11 +163,11 @@ class endianess_convertor //------------------------------------------------------------------------------ struct address_translation { - address_translation( uint64_t start, uint64_t size, uint64_t map_to ) - : start( start ), size( size ), map_to( map_to ){}; + address_translation( uint64_t start, uint64_t size, uint64_t mapped_to ) + : start( start ), size( size ), mapped_to( mapped_to ){}; std::streampos start; std::streampos size; - std::streampos map_to; + std::streampos mapped_to; }; //------------------------------------------------------------------------------ @@ -182,7 +182,7 @@ class address_translator std::sort( addr_translations.begin(), addr_translations.end(), []( address_translation& a, address_translation& b ) -> bool { - return a.map_to < b.map_to; + return a.start < b.start; } ); } @@ -194,8 +194,8 @@ class address_translator } for ( auto& t : addr_translations ) { - if ( ( t.map_to <= value ) && ( ( value - t.map_to ) < t.size ) ) { - return t.start - t.map_to + value; + if ( ( t.start <= value ) && ( ( value - t.start ) < t.size ) ) { + return value - t.start + t.mapped_to; } } diff --git a/examples/proc_mem/proc_mem.cpp b/examples/proc_mem/proc_mem.cpp index 21ed765..96963be 100644 --- a/examples/proc_mem/proc_mem.cpp +++ b/examples/proc_mem/proc_mem.cpp @@ -49,8 +49,8 @@ void get_translation_ranges( std::ifstream& proc_maps, if ( match.size() == 9 && match[8].str() == file_name ) { unsigned long start = std::stoul( match[1].str(), 0, 16 ); unsigned long end = std::stoul( match[2].str(), 0, 16 ); - unsigned long mapped = std::stoul( match[4].str(), 0, 16 ); - result.emplace_back( start, end - start, mapped ); + unsigned long actual = std::stoul( match[4].str(), 0, 16 ); + result.emplace_back( actual, end - start, start ); } } } diff --git a/tests/ELFIOTest2.cpp b/tests/ELFIOTest2.cpp index 9aad78d..7e7ecab 100644 --- a/tests/ELFIOTest2.cpp +++ b/tests/ELFIOTest2.cpp @@ -433,9 +433,9 @@ BOOST_AUTO_TEST_CASE( address_translation_test ) { std::vector ranges; - ranges.emplace_back( 500, 100, 0 ); - ranges.emplace_back( 1000, 1000, 500 ); - ranges.emplace_back( 3000, 1000, 2000 ); + ranges.emplace_back( 0, 100, 500 ); + ranges.emplace_back( 500, 1000, 1000 ); + ranges.emplace_back( 2000, 1000, 3000 ); address_translator tr; tr.set_address_translation( ranges );