Merge "Fallback to IPv6 when IPv4 is not available in adb"
diff --git a/include/cutils/native_handle.h b/include/cutils/native_handle.h
index 813dadc..7d6a988 100644
--- a/include/cutils/native_handle.h
+++ b/include/cutils/native_handle.h
@@ -17,10 +17,17 @@
#ifndef NATIVE_HANDLE_H_
#define NATIVE_HANDLE_H_
+#include <stdalign.h>
+
#ifdef __cplusplus
extern "C" {
#endif
+/* Declare a char array for use with native_handle_init */
+#define NATIVE_HANDLE_DECLARE_STORAGE(name, maxFds, maxInts) \
+ alignas(native_handle_t) char name[ \
+ sizeof(native_handle_t) + sizeof(int) * (maxFds + maxInts)]
+
typedef struct native_handle
{
int version; /* sizeof(native_handle_t) */
@@ -46,6 +53,14 @@
*/
int native_handle_close(const native_handle_t* h);
+/*
+ * native_handle_init
+ *
+ * Initializes a native_handle_t from storage. storage must be declared with
+ * NATIVE_HANDLE_DECLARE_STORAGE. numFds and numInts must not respectively
+ * exceed maxFds and maxInts used to declare the storage.
+ */
+native_handle_t* native_handle_init(char* storage, int numFds, int numInts);
/*
* native_handle_create
diff --git a/libbacktrace/BacktracePtrace.cpp b/libbacktrace/BacktracePtrace.cpp
index fd8b713..148c418 100644
--- a/libbacktrace/BacktracePtrace.cpp
+++ b/libbacktrace/BacktracePtrace.cpp
@@ -17,6 +17,7 @@
#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>
@@ -72,42 +73,20 @@
if (!BacktraceMap::IsValid(map) || !(map.flags & PROT_READ)) {
return 0;
}
-
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;
- }
- 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);
- }
+ struct iovec local_io;
+ local_io.iov_base = buffer;
+ local_io.iov_len = bytes;
- 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;
+ struct iovec remote_io;
+ remote_io.iov_base = reinterpret_cast<void*>(addr);
+ remote_io.iov_len = bytes;
+
+ ssize_t bytes_read = process_vm_readv(Tid(), &local_io, 1, &remote_io, 1, 0);
+ if (bytes_read == -1) {
+ return 0;
}
- return bytes_read;
+ return static_cast<size_t>(bytes_read);
#endif
}
diff --git a/libcutils/native_handle.c b/libcutils/native_handle.c
index cae146d..9f4840a 100644
--- a/libcutils/native_handle.c
+++ b/libcutils/native_handle.c
@@ -28,6 +28,20 @@
static const int kMaxNativeFds = 1024;
static const int kMaxNativeInts = 1024;
+native_handle_t* native_handle_init(char* storage, int numFds, int numInts)
+{
+ if ((uintptr_t) storage % alignof(native_handle_t)) {
+ return NULL;
+ }
+
+ native_handle_t* handle = (native_handle_t*) storage;
+ handle->version = sizeof(native_handle_t);
+ handle->numFds = numFds;
+ handle->numInts = numInts;
+
+ return handle;
+}
+
native_handle_t* native_handle_create(int numFds, int numInts)
{
if (numFds < 0 || numInts < 0 || numFds > kMaxNativeFds || numInts > kMaxNativeInts) {