1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_CREATE_MAPPING_PARAMS_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_CREATE_MAPPING_PARAMS_H_ 19 20 #include <cstddef> 21 #include <cstdint> 22 #include <optional> 23 #include <string> 24 #include <tuple> 25 26 #include "perfetto/ext/base/hash.h" 27 #include "src/trace_processor/importers/common/address_range.h" 28 #include "src/trace_processor/util/build_id.h" 29 30 namespace perfetto { 31 namespace trace_processor { 32 33 struct CreateMappingParams { 34 AddressRange memory_range; 35 // This is the offset into the file that has been mapped at 36 // memory_range.start() 37 uint64_t exact_offset = 0; 38 // This is the offset into the file where the ELF header starts. We assume 39 // all file mappings are ELF files an thus this offset is 0. 40 uint64_t start_offset = 0; 41 // This can only be read out of the actual ELF file. 42 uint64_t load_bias = 0; 43 std::string name; 44 std::optional<BuildId> build_id; 45 ToTupleCreateMappingParams46 auto ToTuple() const { 47 return std::tie(memory_range, exact_offset, start_offset, load_bias, name, 48 build_id); 49 } 50 51 bool operator==(const CreateMappingParams& o) const { 52 return ToTuple() == o.ToTuple(); 53 } 54 55 struct Hasher { operatorCreateMappingParams::Hasher56 size_t operator()(const CreateMappingParams& p) const { 57 base::Hasher h; 58 h.UpdateAll(p.memory_range.start(), p.memory_range.end(), p.exact_offset, 59 p.start_offset, p.load_bias, p.name); 60 if (p.build_id) { 61 h.Update(*p.build_id); 62 } 63 return static_cast<size_t>(h.digest()); 64 } 65 }; 66 }; 67 68 } // namespace trace_processor 69 } // namespace perfetto 70 71 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_CREATE_MAPPING_PARAMS_H_ 72