Loading libs/binder/Binder.cpp +26 −10 Original line number Diff line number Diff line Loading @@ -179,6 +179,17 @@ status_t IBinder::setRpcClientDebug(android::base::unique_fd socketFd, return transact(SET_RPC_CLIENT_TRANSACTION, data, &reply); } void IBinder::withLock(const std::function<void()>& doWithLock) { BBinder* local = localBinder(); if (local) { local->withLock(doWithLock); return; } BpBinder* proxy = this->remoteBinder(); LOG_ALWAYS_FATAL_IF(proxy == nullptr, "binder object must be either local or remote"); proxy->withLock(doWithLock); } // --------------------------------------------------------------------------- class BBinder::RpcServerLink : public IBinder::DeathRecipient { Loading Loading @@ -311,15 +322,13 @@ status_t BBinder::dump(int /*fd*/, const Vector<String16>& /*args*/) return NO_ERROR; } void BBinder::attachObject( const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) { void* BBinder::attachObject(const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) { Extras* e = getOrCreateExtras(); if (!e) return; // out of memory if (!e) return nullptr; // out of memory AutoMutex _l(e->mLock); e->mObjects.attach(objectID, object, cleanupCookie, func); return e->mObjects.attach(objectID, object, cleanupCookie, func); } void* BBinder::findObject(const void* objectID) const Loading @@ -331,13 +340,20 @@ void* BBinder::findObject(const void* objectID) const return e->mObjects.find(objectID); } void BBinder::detachObject(const void* objectID) { void* BBinder::detachObject(const void* objectID) { Extras* e = mExtras.load(std::memory_order_acquire); if (!e) return; if (!e) return nullptr; AutoMutex _l(e->mLock); return e->mObjects.detach(objectID); } void BBinder::withLock(const std::function<void()>& doWithLock) { Extras* e = getOrCreateExtras(); LOG_ALWAYS_FATAL_IF(!e, "no memory"); AutoMutex _l(e->mLock); e->mObjects.detach(objectID); doWithLock(); } BBinder* BBinder::localBinder() Loading libs/binder/BpBinder.cpp +24 −20 Original line number Diff line number Diff line Loading @@ -61,22 +61,22 @@ BpBinder::ObjectManager::~ObjectManager() kill(); } void BpBinder::ObjectManager::attach( const void* objectID, void* object, void* cleanupCookie, IBinder::object_cleanup_func func) { void* BpBinder::ObjectManager::attach(const void* objectID, void* object, void* cleanupCookie, IBinder::object_cleanup_func func) { entry_t e; e.object = object; e.cleanupCookie = cleanupCookie; e.func = func; if (mObjects.indexOfKey(objectID) >= 0) { ALOGE("Trying to attach object ID %p to binder ObjectManager %p with object %p, but object ID already in use", if (ssize_t idx = mObjects.indexOfKey(objectID); idx >= 0) { ALOGI("Trying to attach object ID %p to binder ObjectManager %p with object %p, but object " "ID already in use", objectID, this, object); return; return mObjects[idx].object; } mObjects.add(objectID, e); return nullptr; } void* BpBinder::ObjectManager::find(const void* objectID) const Loading @@ -86,9 +86,12 @@ void* BpBinder::ObjectManager::find(const void* objectID) const return mObjects.valueAt(i).object; } void BpBinder::ObjectManager::detach(const void* objectID) { mObjects.removeItem(objectID); void* BpBinder::ObjectManager::detach(const void* objectID) { ssize_t idx = mObjects.indexOfKey(objectID); if (idx < 0) return nullptr; void* value = mObjects[idx].object; mObjects.removeItemsAt(idx, 1); return value; } void BpBinder::ObjectManager::kill() Loading Loading @@ -406,14 +409,11 @@ void BpBinder::reportOneDeath(const Obituary& obit) recipient->binderDied(wp<BpBinder>::fromExisting(this)); } void BpBinder::attachObject( const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) { void* BpBinder::attachObject(const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) { AutoMutex _l(mLock); ALOGV("Attaching object %p to binder %p (manager=%p)", object, this, &mObjects); mObjects.attach(objectID, object, cleanupCookie, func); return mObjects.attach(objectID, object, cleanupCookie, func); } void* BpBinder::findObject(const void* objectID) const Loading @@ -422,10 +422,14 @@ void* BpBinder::findObject(const void* objectID) const return mObjects.find(objectID); } void BpBinder::detachObject(const void* objectID) { void* BpBinder::detachObject(const void* objectID) { AutoMutex _l(mLock); return mObjects.detach(objectID); } void BpBinder::withLock(const std::function<void()>& doWithLock) { AutoMutex _l(mLock); mObjects.detach(objectID); doWithLock(); } BpBinder* BpBinder::remoteBinder() Loading libs/binder/TEST_MAPPING +1 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ "name": "binderTextOutputTest" }, { "name": "binderParcelTest" "name": "binderUnitTest" }, { "name": "binderLibTest" Loading libs/binder/include/binder/Binder.h +4 −5 Original line number Diff line number Diff line Loading @@ -54,12 +54,11 @@ public: uint32_t flags = 0, wp<DeathRecipient>* outRecipient = nullptr); virtual void attachObject( const void* objectID, void* object, void* cleanupCookie, virtual void* attachObject(const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) final; virtual void* findObject(const void* objectID) const final; virtual void detachObject(const void* objectID) final; virtual void* detachObject(const void* objectID) final; void withLock(const std::function<void()>& doWithLock); virtual BBinder* localBinder(); Loading libs/binder/include/binder/BpBinder.h +14 −19 Original line number Diff line number Diff line Loading @@ -72,12 +72,11 @@ public: uint32_t flags = 0, wp<DeathRecipient>* outRecipient = nullptr); virtual void attachObject( const void* objectID, void* object, void* cleanupCookie, virtual void* attachObject(const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) final; virtual void* findObject(const void* objectID) const final; virtual void detachObject(const void* objectID) final; virtual void* detachObject(const void* objectID) final; void withLock(const std::function<void()>& doWithLock); virtual BpBinder* remoteBinder(); Loading @@ -91,18 +90,15 @@ public: static void setLimitCallback(binder_proxy_limit_callback cb); static void setBinderProxyCountWatermarks(int high, int low); class ObjectManager { class ObjectManager { public: ObjectManager(); ~ObjectManager(); void attach( const void* objectID, void* object, void* cleanupCookie, void* attach(const void* objectID, void* object, void* cleanupCookie, IBinder::object_cleanup_func func); void* find(const void* objectID) const; void detach(const void* objectID); void* detach(const void* objectID); void kill(); Loading @@ -110,8 +106,7 @@ public: ObjectManager(const ObjectManager&); ObjectManager& operator=(const ObjectManager&); struct entry_t { struct entry_t { void* object; void* cleanupCookie; IBinder::object_cleanup_func func; Loading Loading
libs/binder/Binder.cpp +26 −10 Original line number Diff line number Diff line Loading @@ -179,6 +179,17 @@ status_t IBinder::setRpcClientDebug(android::base::unique_fd socketFd, return transact(SET_RPC_CLIENT_TRANSACTION, data, &reply); } void IBinder::withLock(const std::function<void()>& doWithLock) { BBinder* local = localBinder(); if (local) { local->withLock(doWithLock); return; } BpBinder* proxy = this->remoteBinder(); LOG_ALWAYS_FATAL_IF(proxy == nullptr, "binder object must be either local or remote"); proxy->withLock(doWithLock); } // --------------------------------------------------------------------------- class BBinder::RpcServerLink : public IBinder::DeathRecipient { Loading Loading @@ -311,15 +322,13 @@ status_t BBinder::dump(int /*fd*/, const Vector<String16>& /*args*/) return NO_ERROR; } void BBinder::attachObject( const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) { void* BBinder::attachObject(const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) { Extras* e = getOrCreateExtras(); if (!e) return; // out of memory if (!e) return nullptr; // out of memory AutoMutex _l(e->mLock); e->mObjects.attach(objectID, object, cleanupCookie, func); return e->mObjects.attach(objectID, object, cleanupCookie, func); } void* BBinder::findObject(const void* objectID) const Loading @@ -331,13 +340,20 @@ void* BBinder::findObject(const void* objectID) const return e->mObjects.find(objectID); } void BBinder::detachObject(const void* objectID) { void* BBinder::detachObject(const void* objectID) { Extras* e = mExtras.load(std::memory_order_acquire); if (!e) return; if (!e) return nullptr; AutoMutex _l(e->mLock); return e->mObjects.detach(objectID); } void BBinder::withLock(const std::function<void()>& doWithLock) { Extras* e = getOrCreateExtras(); LOG_ALWAYS_FATAL_IF(!e, "no memory"); AutoMutex _l(e->mLock); e->mObjects.detach(objectID); doWithLock(); } BBinder* BBinder::localBinder() Loading
libs/binder/BpBinder.cpp +24 −20 Original line number Diff line number Diff line Loading @@ -61,22 +61,22 @@ BpBinder::ObjectManager::~ObjectManager() kill(); } void BpBinder::ObjectManager::attach( const void* objectID, void* object, void* cleanupCookie, IBinder::object_cleanup_func func) { void* BpBinder::ObjectManager::attach(const void* objectID, void* object, void* cleanupCookie, IBinder::object_cleanup_func func) { entry_t e; e.object = object; e.cleanupCookie = cleanupCookie; e.func = func; if (mObjects.indexOfKey(objectID) >= 0) { ALOGE("Trying to attach object ID %p to binder ObjectManager %p with object %p, but object ID already in use", if (ssize_t idx = mObjects.indexOfKey(objectID); idx >= 0) { ALOGI("Trying to attach object ID %p to binder ObjectManager %p with object %p, but object " "ID already in use", objectID, this, object); return; return mObjects[idx].object; } mObjects.add(objectID, e); return nullptr; } void* BpBinder::ObjectManager::find(const void* objectID) const Loading @@ -86,9 +86,12 @@ void* BpBinder::ObjectManager::find(const void* objectID) const return mObjects.valueAt(i).object; } void BpBinder::ObjectManager::detach(const void* objectID) { mObjects.removeItem(objectID); void* BpBinder::ObjectManager::detach(const void* objectID) { ssize_t idx = mObjects.indexOfKey(objectID); if (idx < 0) return nullptr; void* value = mObjects[idx].object; mObjects.removeItemsAt(idx, 1); return value; } void BpBinder::ObjectManager::kill() Loading Loading @@ -406,14 +409,11 @@ void BpBinder::reportOneDeath(const Obituary& obit) recipient->binderDied(wp<BpBinder>::fromExisting(this)); } void BpBinder::attachObject( const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) { void* BpBinder::attachObject(const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) { AutoMutex _l(mLock); ALOGV("Attaching object %p to binder %p (manager=%p)", object, this, &mObjects); mObjects.attach(objectID, object, cleanupCookie, func); return mObjects.attach(objectID, object, cleanupCookie, func); } void* BpBinder::findObject(const void* objectID) const Loading @@ -422,10 +422,14 @@ void* BpBinder::findObject(const void* objectID) const return mObjects.find(objectID); } void BpBinder::detachObject(const void* objectID) { void* BpBinder::detachObject(const void* objectID) { AutoMutex _l(mLock); return mObjects.detach(objectID); } void BpBinder::withLock(const std::function<void()>& doWithLock) { AutoMutex _l(mLock); mObjects.detach(objectID); doWithLock(); } BpBinder* BpBinder::remoteBinder() Loading
libs/binder/TEST_MAPPING +1 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ "name": "binderTextOutputTest" }, { "name": "binderParcelTest" "name": "binderUnitTest" }, { "name": "binderLibTest" Loading
libs/binder/include/binder/Binder.h +4 −5 Original line number Diff line number Diff line Loading @@ -54,12 +54,11 @@ public: uint32_t flags = 0, wp<DeathRecipient>* outRecipient = nullptr); virtual void attachObject( const void* objectID, void* object, void* cleanupCookie, virtual void* attachObject(const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) final; virtual void* findObject(const void* objectID) const final; virtual void detachObject(const void* objectID) final; virtual void* detachObject(const void* objectID) final; void withLock(const std::function<void()>& doWithLock); virtual BBinder* localBinder(); Loading
libs/binder/include/binder/BpBinder.h +14 −19 Original line number Diff line number Diff line Loading @@ -72,12 +72,11 @@ public: uint32_t flags = 0, wp<DeathRecipient>* outRecipient = nullptr); virtual void attachObject( const void* objectID, void* object, void* cleanupCookie, virtual void* attachObject(const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) final; virtual void* findObject(const void* objectID) const final; virtual void detachObject(const void* objectID) final; virtual void* detachObject(const void* objectID) final; void withLock(const std::function<void()>& doWithLock); virtual BpBinder* remoteBinder(); Loading @@ -91,18 +90,15 @@ public: static void setLimitCallback(binder_proxy_limit_callback cb); static void setBinderProxyCountWatermarks(int high, int low); class ObjectManager { class ObjectManager { public: ObjectManager(); ~ObjectManager(); void attach( const void* objectID, void* object, void* cleanupCookie, void* attach(const void* objectID, void* object, void* cleanupCookie, IBinder::object_cleanup_func func); void* find(const void* objectID) const; void detach(const void* objectID); void* detach(const void* objectID); void kill(); Loading @@ -110,8 +106,7 @@ public: ObjectManager(const ObjectManager&); ObjectManager& operator=(const ObjectManager&); struct entry_t { struct entry_t { void* object; void* cleanupCookie; IBinder::object_cleanup_func func; Loading