summaryrefslogtreecommitdiff
path: root/libs/binder/ProcessState.cpp
diff options
context:
space:
mode:
author Jon Spivack <spivack@google.com> 2019-10-18 21:22:37 -0700
committer Jon Spivack <spivack@google.com> 2019-10-23 20:44:30 +0000
commit902e6fc6728ecfc16100de216e96c112422b9711 (patch)
treefbf0d1f83870cc56745f135bf85d44e5ee584a39 /libs/binder/ProcessState.cpp
parent64d536717b64b0db252e242ddea2e0e7b53b697f (diff)
Add getStrongRefCountForNodeByHandle to ProcessState
ServiceManager can use this function to query individual services for their ref counts. Bug: 143108344 Test: Manual (printed ref counts from servicemanager and confirmed that they matched the data in /d/binder/state) Change-Id: I8c84f4b10b1c2b7690b39d1c4f4f50abd7d715b0
Diffstat (limited to 'libs/binder/ProcessState.cpp')
-rw-r--r--libs/binder/ProcessState.cpp24
1 files changed, 24 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.");