summaryrefslogtreecommitdiffstats
path: root/libunwindstack/MapInfo.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2017-09-01 11:17:16 -0700
committerChristopher Ferris <cferris@google.com>2017-09-05 14:30:22 -0700
commit5f118519fd323a0c71b54de9279e8a9ea6a56271 (patch)
tree3ce288c58ab8d5a6aa1d3c307def1f0f1019ae7a /libunwindstack/MapInfo.cpp
parent9638729a9d9e3cbbbe1bb2784e774fef0f2e6a54 (diff)
downloadsystem_core-5f118519fd323a0c71b54de9279e8a9ea6a56271.tar.gz
system_core-5f118519fd323a0c71b54de9279e8a9ea6a56271.tar.bz2
system_core-5f118519fd323a0c71b54de9279e8a9ea6a56271.zip
Add a method to share the process memory object.
New function to create the process memory object. This allows for a future where different remote process memory objects could be created depending on the way remote memory can be created. Even different local memory objects that access memory without doing any checks. It also allows MemoryRange objects to share one single process memory object and could help if the process memory object caches data. Small changes to MapInfo::CreateMemory to when some errors are detected. - Always check if the map is a device map, instead of only if the name is not empty. - Check if a memory map is readable before creating the memory from process memory. Bug: 23762183 Test: Ran unit tests, unwound on device using the new code. Change-Id: I12a93c2dc19639689a528ec41c67bfac74d431b3
Diffstat (limited to 'libunwindstack/MapInfo.cpp')
-rw-r--r--libunwindstack/MapInfo.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/libunwindstack/MapInfo.cpp b/libunwindstack/MapInfo.cpp
index 32722154a..96f2cb42b 100644
--- a/libunwindstack/MapInfo.cpp
+++ b/libunwindstack/MapInfo.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <sys/mman.h>
#include <sys/types.h>
#include <unistd.h>
@@ -76,40 +77,39 @@ Memory* MapInfo::GetFileMemory() {
return memory.release();
}
-Memory* MapInfo::CreateMemory(pid_t pid) {
+Memory* MapInfo::CreateMemory(const std::shared_ptr<Memory>& process_memory) {
if (end <= start) {
return nullptr;
}
elf_offset = 0;
+ // Fail on device maps.
+ if (flags & MAPS_FLAGS_DEVICE_MAP) {
+ return nullptr;
+ }
+
// First try and use the file associated with the info.
if (!name.empty()) {
- // Fail on device maps.
- if (flags & MAPS_FLAGS_DEVICE_MAP) {
- return nullptr;
- }
Memory* memory = GetFileMemory();
if (memory != nullptr) {
return memory;
}
}
- Memory* memory;
- if (pid == getpid()) {
- memory = new MemoryLocal();
- } else {
- memory = new MemoryRemote(pid);
+ // If the map isn't readable, don't bother trying to read from process memory.
+ if (!(flags & PROT_READ)) {
+ return nullptr;
}
- return new MemoryRange(memory, start, end);
+ return new MemoryRange(process_memory, start, end);
}
-Elf* MapInfo::GetElf(pid_t pid, bool init_gnu_debugdata) {
+Elf* MapInfo::GetElf(const std::shared_ptr<Memory>& process_memory, bool init_gnu_debugdata) {
if (elf) {
return elf;
}
- elf = new Elf(CreateMemory(pid));
+ elf = new Elf(CreateMemory(process_memory));
if (elf->Init() && init_gnu_debugdata) {
elf->InitGnuDebugdata();
}