diff options
author | Jon Spivack <spivack@google.com> | 2019-10-23 16:41:58 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-10-23 16:41:58 -0700 |
commit | 091d81511b92b0f38eb7068dbff3fa55b4645c63 (patch) | |
tree | 3dae9552c8fe39cdb1355b8bb7436dbb2b877771 | |
parent | f7ead637fb43f04a3c36c2ae57315cd1dadb6541 (diff) | |
parent | 73c91ae78a55cc6a64259a64b9fec6a584a4784c (diff) | |
download | native-b_141248619.tar.gz |
Merge "Add getStrongRefCountForNodeByHandle to ProcessState"b_141248619
am: 73c91ae78a
Change-Id: I96a71b7a888dac84188d7e546b0bfb9082711da8
-rw-r--r-- | libs/binder/ProcessState.cpp | 24 | ||||
-rw-r--r-- | libs/binder/include/binder/ProcessState.h | 8 |
2 files changed, 32 insertions, 0 deletions
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp index 0336d3ebd4..ea61dc5aff 100644 --- a/libs/binder/ProcessState.cpp +++ b/libs/binder/ProcessState.cpp @@ -188,6 +188,30 @@ ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf) return count; } +// Queries the driver for the current strong reference count of the node +// that the handle points to. Can only be used by the servicemanager. +// +// Returns -1 in case of failure, otherwise the strong reference count. +ssize_t ProcessState::getStrongRefCountForNodeByHandle(int32_t handle) { + binder_node_info_for_ref info; + memset(&info, 0, sizeof(binder_node_info_for_ref)); + + info.handle = handle; + + status_t result = ioctl(mDriverFD, BINDER_GET_NODE_INFO_FOR_REF, &info); + + if (result != OK) { + static bool logged = false; + if (!logged) { + ALOGW("Kernel does not support BINDER_GET_NODE_INFO_FOR_REF."); + logged = true; + } + return -1; + } + + return info.strong_count; +} + void ProcessState::setCallRestriction(CallRestriction restriction) { LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull() != nullptr, "Call restrictions must be set before the threadpool is started."); diff --git a/libs/binder/include/binder/ProcessState.h b/libs/binder/include/binder/ProcessState.h index f7c38f418d..e57ff1c260 100644 --- a/libs/binder/include/binder/ProcessState.h +++ b/libs/binder/include/binder/ProcessState.h @@ -69,6 +69,14 @@ public: ssize_t getKernelReferences(size_t count, uintptr_t* buf); + // Only usable by the context manager. + // This refcount includes: + // 1. Strong references to the node by this and other processes + // 2. Temporary strong references held by the kernel during a + // transaction on the node. + // It does NOT include local strong references to the node + ssize_t getStrongRefCountForNodeByHandle(int32_t handle); + enum class CallRestriction { // all calls okay NONE, |