1 /* 2 * Copyright (C) 2016 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 _LIBUNWINDSTACK_MAP_INFO_H 18 #define _LIBUNWINDSTACK_MAP_INFO_H 19 20 #include <stdint.h> 21 22 #include <atomic> 23 #include <memory> 24 #include <mutex> 25 #include <string> 26 27 #include <unwindstack/Elf.h> 28 29 namespace unwindstack { 30 31 // Forward declarations. 32 class Memory; 33 34 struct MapInfo { 35 MapInfo() = default; 36 MapInfo(uint64_t start, uint64_t end) : start(start), end(end) {} 37 MapInfo(uint64_t start, uint64_t end, uint64_t offset, uint64_t flags, const std::string& name) 38 : start(start), 39 end(end), 40 offset(offset), 41 flags(flags), 42 name(name), 43 load_bias(static_cast<uint64_t>(-1)) {} 44 ~MapInfo() = default; 45 46 uint64_t start = 0; 47 uint64_t end = 0; 48 uint64_t offset = 0; 49 uint16_t flags = 0; 50 std::string name; 51 std::shared_ptr<Elf> elf; 52 // This value is only non-zero if the offset is non-zero but there is 53 // no elf signature found at that offset. This indicates that the 54 // entire file is represented by the Memory object returned by CreateMemory, 55 // instead of a portion of the file. 56 uint64_t elf_offset = 0; 57 58 std::atomic_uint64_t load_bias; 59 60 // This function guarantees it will never return nullptr. 61 Elf* GetElf(const std::shared_ptr<Memory>& process_memory, bool init_gnu_debugdata = false); 62 63 uint64_t GetLoadBias(const std::shared_ptr<Memory>& process_memory); 64 65 private: 66 MapInfo(const MapInfo&) = delete; 67 void operator=(const MapInfo&) = delete; 68 69 Memory* GetFileMemory(); 70 71 Memory* CreateMemory(const std::shared_ptr<Memory>& process_memory); 72 73 // Protect the creation of the elf object. 74 std::mutex mutex_; 75 }; 76 77 } // namespace unwindstack 78 79 #endif // _LIBUNWINDSTACK_MAP_INFO_H 80