From f123d45ce15601f446eaac487431cd59e2cdccf5 Mon Sep 17 00:00:00 2001 From: Badhri Jagan Sridharan Date: Wed, 17 Oct 2018 18:26:37 -0700 Subject: [PATCH 1/3] usbd: Do not join the thread pool Work around for the following crash: 02-08 05:34:20.968 root 990 990 F DEBUG : #00 pc 000000000001447c /system/lib64/libhwbinder.so (android::hardware::IPCThreadState::joinThreadPool(bool)+28) 02-08 05:34:20.968 root 990 990 F DEBUG : #01 pc 000000000001c174 /system/lib64/libhwbinder.so (android::hardware::PoolThread::threadLoop()+24) 02-08 05:34:20.968 root 990 990 F DEBUG : #02 pc 000000000000f934 /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+280) 02-08 05:34:20.968 root 990 990 F DEBUG : #03 pc 00000000000821e0 /system/lib64/libc.so (__pthread_start(void*)+36) 02-08 05:34:20.968 root 990 990 F DEBUG : #04 pc 0000000000023178 /system/lib64/libc.so (__start_thread+68) Bug: 117470462 Change-Id: I1e8f28a7d0f3041d9be8138a3dc9ed9c74419f91 --- usbd/usbd.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/usbd/usbd.cpp b/usbd/usbd.cpp index 41cd8dd9b..191fb92fb 100644 --- a/usbd/usbd.cpp +++ b/usbd/usbd.cpp @@ -22,15 +22,20 @@ #include #include +#include + #define PERSISTENT_USB_CONFIG "persist.sys.usb.config" using android::base::GetProperty; using android::base::SetProperty; +using android::hardware::configureRpcThreadpool; using android::hardware::usb::gadget::V1_0::GadgetFunction; using android::hardware::usb::gadget::V1_0::IUsbGadget; using android::hardware::Return; int main(int /*argc*/, char** /*argv*/) { + configureRpcThreadpool(1, true /*callerWillJoin*/); + android::sp gadget = IUsbGadget::getService(); Return ret; From 02debfa2df1589c2f8e35cc2db93dd131f43f2db Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Wed, 5 Dec 2018 09:42:25 +0100 Subject: [PATCH 2/3] Export maximum number of fds/ints in a native_handle. So we can deserialize it consisently and safely. Bug: 120084106 Test: builds Change-Id: I0eafff70d3a7e4d732fe600a0052efb90108208d --- libcutils/include/cutils/native_handle.h | 3 +++ libcutils/native_handle.c | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libcutils/include/cutils/native_handle.h b/libcutils/include/cutils/native_handle.h index abe6dd614..c1c27f753 100644 --- a/libcutils/include/cutils/native_handle.h +++ b/libcutils/include/cutils/native_handle.h @@ -23,6 +23,9 @@ extern "C" { #endif +#define NATIVE_HANDLE_MAX_FDS 1024 +#define NATIVE_HANDLE_MAX_INTS 1024 + /* Declare a char array for use with native_handle_init */ #define NATIVE_HANDLE_DECLARE_STORAGE(name, maxFds, maxInts) \ alignas(native_handle_t) char name[ \ diff --git a/libcutils/native_handle.c b/libcutils/native_handle.c index 95bbc41c4..5cc1a9e6b 100644 --- a/libcutils/native_handle.c +++ b/libcutils/native_handle.c @@ -22,9 +22,6 @@ #include #include -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)) { errno = EINVAL; @@ -39,7 +36,8 @@ native_handle_t* native_handle_init(char* storage, int numFds, int numInts) { } native_handle_t* native_handle_create(int numFds, int numInts) { - if (numFds < 0 || numInts < 0 || numFds > kMaxNativeFds || numInts > kMaxNativeInts) { + if (numFds < 0 || numInts < 0 || numFds > NATIVE_HANDLE_MAX_FDS || + numInts > NATIVE_HANDLE_MAX_INTS) { errno = EINVAL; return NULL; } From c1cea05b5f052474d3df90adbe40f5796d950a6e Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Wed, 5 Dec 2018 09:42:25 +0100 Subject: [PATCH 3/3] Export maximum number of fds/ints in a native_handle. So we can deserialize it consisently and safely. Bug: 120084106 Test: builds Change-Id: I0eafff70d3a7e4d732fe600a0052efb90108208d Merged-In: I0eafff70d3a7e4d732fe600a0052efb90108208d --- libcutils/include/cutils/native_handle.h | 3 +++ libcutils/native_handle.c | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libcutils/include/cutils/native_handle.h b/libcutils/include/cutils/native_handle.h index 7d6a98802..5696edb97 100644 --- a/libcutils/include/cutils/native_handle.h +++ b/libcutils/include/cutils/native_handle.h @@ -23,6 +23,9 @@ extern "C" { #endif +#define NATIVE_HANDLE_MAX_FDS 1024 +#define NATIVE_HANDLE_MAX_INTS 1024 + /* Declare a char array for use with native_handle_init */ #define NATIVE_HANDLE_DECLARE_STORAGE(name, maxFds, maxInts) \ alignas(native_handle_t) char name[ \ diff --git a/libcutils/native_handle.c b/libcutils/native_handle.c index 9f4840a59..2a092dce8 100644 --- a/libcutils/native_handle.c +++ b/libcutils/native_handle.c @@ -25,9 +25,6 @@ #include #include -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)) { @@ -44,7 +41,8 @@ native_handle_t* native_handle_init(char* storage, int numFds, int numInts) native_handle_t* native_handle_create(int numFds, int numInts) { - if (numFds < 0 || numInts < 0 || numFds > kMaxNativeFds || numInts > kMaxNativeInts) { + if (numFds < 0 || numInts < 0 || numFds > NATIVE_HANDLE_MAX_FDS || + numInts > NATIVE_HANDLE_MAX_INTS) { return NULL; }