From e839388aaf2aaf82d6a8a84aa4ffb673dc62287d Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Fri, 18 Dec 2020 02:27:20 +0000 Subject: BpBinder: hide 'handle' API The 'handle' API represents an internal 'address' for use with the kernel, and it shouldn't be exported from libbinder (currenlty it is used in Parcel). If any clients are using this API (they really shouldn't be), then this CL should expose them. This way, when/if binder supports communications over sockets, the format of this data can be changed without having to worry about changing this API (we're worrying about changing that API now). Possible solutions here: 1. Parcel should not read/write binder objects. Instead, these objects should implement Parcelable. This certainly sounds like an elegant solution. However, because of the way that flattenBinder/unflattenBinder interact with Parcel internal details ('objects') rather than being composed of other Parcel primitives, having Parcel expose 'handle' is probably the lesser of the two evils (not to mention, the sizeof(IBinder) and its virtual address table is frozen). 2. Use 'friend' (and this is the route this CL goes). However, in order to avoid exposing unnecessary internal details of BpBinder, this CL creates a header-only access function which limits the ability of Parcel to inspect BpBinder, and it makes the contract/relationship explicit. Assuming this CL lands, I want to change other uses of 'friend' here to use a similar accessor pattern. Bug: 167966510 Test: boot, aidl_lazy_test Change-Id: I5b21d15989f7ce7c45e44b33ed3bde45a63347a5 --- libs/binder/ProcessState.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libs/binder/ProcessState.cpp') diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp index 9aedf28964..6f26450275 100644 --- a/libs/binder/ProcessState.cpp +++ b/libs/binder/ProcessState.cpp @@ -204,11 +204,11 @@ ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf) // 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) { +ssize_t ProcessState::getStrongRefCountForNode(const sp& binder) { binder_node_info_for_ref info; memset(&info, 0, sizeof(binder_node_info_for_ref)); - info.handle = handle; + info.handle = binder->getPrivateAccessorForHandle().handle(); status_t result = ioctl(mDriverFD, BINDER_GET_NODE_INFO_FOR_REF, &info); -- cgit v1.2.3-59-g8ed1b