summaryrefslogtreecommitdiff
path: root/simpleperf/environment.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'simpleperf/environment.cpp')
-rw-r--r--simpleperf/environment.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp
index ed161c23..0ad2d6bd 100644
--- a/simpleperf/environment.cpp
+++ b/simpleperf/environment.cpp
@@ -475,3 +475,31 @@ ArchType GetMachineArch() {
}
return GetBuildArch();
}
+
+void PrepareVdsoFile() {
+ // vdso is an elf file in memory loaded in each process's user space by the kernel. To read
+ // symbols from it and unwind through it, we need to dump it into a file in storage.
+ // It doesn't affect much when failed to prepare vdso file, so there is no need to return values.
+ std::vector<ThreadMmap> thread_mmaps;
+ if (!GetThreadMmapsInProcess(getpid(), &thread_mmaps)) {
+ return;
+ }
+ const ThreadMmap* vdso_map = nullptr;
+ for (const auto& map : thread_mmaps) {
+ if (map.name == "[vdso]") {
+ vdso_map = &map;
+ break;
+ }
+ }
+ if (vdso_map == nullptr) {
+ return;
+ }
+ std::string s(vdso_map->len, '\0');
+ memcpy(&s[0], reinterpret_cast<void*>(static_cast<uintptr_t>(vdso_map->start_addr)),
+ vdso_map->len);
+ std::unique_ptr<TemporaryFile> tmpfile(new TemporaryFile);
+ if (!android::base::WriteStringToFile(s, tmpfile->path)) {
+ return;
+ }
+ Dso::SetVdsoFile(std::move(tmpfile), sizeof(size_t) == sizeof(uint64_t));
+}