summaryrefslogtreecommitdiffstats
path: root/libbacktrace
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2016-11-10 23:19:30 +0000
committerChristopher Ferris <cferris@google.com>2016-11-10 23:19:30 +0000
commitfdb02f8b9c6920d6c5edecabda62e175fc03dcbf (patch)
tree5c576802d32c6741b085e38988f7ec3cef951bde /libbacktrace
parent279843e1397aff2aedb5e5ffe513893fa1f6767f (diff)
downloadsystem_core-fdb02f8b9c6920d6c5edecabda62e175fc03dcbf.tar.gz
system_core-fdb02f8b9c6920d6c5edecabda62e175fc03dcbf.tar.bz2
system_core-fdb02f8b9c6920d6c5edecabda62e175fc03dcbf.zip
Revert "Use process_vm_readv to read memory."
This reverts commit 279843e1397aff2aedb5e5ffe513893fa1f6767f. Bug: 32806783 Change-Id: I61df26d979a8139a571ff5a6442fb5499ca20547 Test: Verified that the stack and read data works with the revert.
Diffstat (limited to 'libbacktrace')
-rw-r--r--libbacktrace/BacktracePtrace.cpp45
1 files changed, 33 insertions, 12 deletions
diff --git a/libbacktrace/BacktracePtrace.cpp b/libbacktrace/BacktracePtrace.cpp
index 148c41810..fd8b7134f 100644
--- a/libbacktrace/BacktracePtrace.cpp
+++ b/libbacktrace/BacktracePtrace.cpp
@@ -17,7 +17,6 @@
#include <errno.h>
#include <stdint.h>
#include <string.h>
-#include <sys/uio.h>
#include <sys/param.h>
#include <sys/ptrace.h>
#include <sys/types.h>
@@ -73,20 +72,42 @@ size_t BacktracePtrace::Read(uintptr_t addr, uint8_t* buffer, size_t bytes) {
if (!BacktraceMap::IsValid(map) || !(map.flags & PROT_READ)) {
return 0;
}
- bytes = MIN(map.end - addr, bytes);
- struct iovec local_io;
- local_io.iov_base = buffer;
- local_io.iov_len = bytes;
+ bytes = MIN(map.end - addr, bytes);
+ size_t bytes_read = 0;
+ word_t data_word;
+ size_t align_bytes = addr & (sizeof(word_t) - 1);
+ if (align_bytes != 0) {
+ if (!PtraceRead(Tid(), addr & ~(sizeof(word_t) - 1), &data_word)) {
+ return 0;
+ }
+ size_t copy_bytes = MIN(sizeof(word_t) - align_bytes, bytes);
+ memcpy(buffer, reinterpret_cast<uint8_t*>(&data_word) + align_bytes, copy_bytes);
+ addr += copy_bytes;
+ buffer += copy_bytes;
+ bytes -= copy_bytes;
+ bytes_read += copy_bytes;
+ }
- struct iovec remote_io;
- remote_io.iov_base = reinterpret_cast<void*>(addr);
- remote_io.iov_len = bytes;
+ size_t num_words = bytes / sizeof(word_t);
+ for (size_t i = 0; i < num_words; i++) {
+ if (!PtraceRead(Tid(), addr, &data_word)) {
+ return bytes_read;
+ }
+ memcpy(buffer, &data_word, sizeof(word_t));
+ buffer += sizeof(word_t);
+ addr += sizeof(word_t);
+ bytes_read += sizeof(word_t);
+ }
- ssize_t bytes_read = process_vm_readv(Tid(), &local_io, 1, &remote_io, 1, 0);
- if (bytes_read == -1) {
- return 0;
+ size_t left_over = bytes & (sizeof(word_t) - 1);
+ if (left_over) {
+ if (!PtraceRead(Tid(), addr, &data_word)) {
+ return bytes_read;
+ }
+ memcpy(buffer, &data_word, left_over);
+ bytes_read += left_over;
}
- return static_cast<size_t>(bytes_read);
+ return bytes_read;
#endif
}