Loading libs/binder/BpBinder.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -150,7 +150,7 @@ BpBinder::BpBinder(int32_t handle, int32_t trackedUid) ALOGV("Creating BpBinder %p handle %d\n", this, mHandle); ALOGV("Creating BpBinder %p handle %d\n", this, mHandle); extendObjectLifetime(OBJECT_LIFETIME_WEAK); extendObjectLifetime(OBJECT_LIFETIME_WEAK); IPCThreadState::self()->incWeakHandle(handle); IPCThreadState::self()->incWeakHandle(handle, this); } } bool BpBinder::isDescriptorCached() const { bool BpBinder::isDescriptorCached() const { Loading Loading @@ -412,7 +412,7 @@ void BpBinder::onFirstRef() { { ALOGV("onFirstRef BpBinder %p handle %d\n", this, mHandle); ALOGV("onFirstRef BpBinder %p handle %d\n", this, mHandle); IPCThreadState* ipc = IPCThreadState::self(); IPCThreadState* ipc = IPCThreadState::self(); if (ipc) ipc->incStrongHandle(mHandle); if (ipc) ipc->incStrongHandle(mHandle, this); } } void BpBinder::onLastStrongRef(const void* /*id*/) void BpBinder::onLastStrongRef(const void* /*id*/) Loading libs/binder/IPCThreadState.cpp +35 −3 Original line number Original line Diff line number Diff line Loading @@ -409,6 +409,15 @@ void IPCThreadState::flushCommands() if (mProcess->mDriverFD <= 0) if (mProcess->mDriverFD <= 0) return; return; talkWithDriver(false); talkWithDriver(false); // The flush could have caused post-write refcount decrements to have // been executed, which in turn could result in BC_RELEASE/BC_DECREFS // being queued in mOut. So flush again, if we need to. if (mOut.dataSize() > 0) { talkWithDriver(false); } if (mOut.dataSize() > 0) { ALOGW("mOut.dataSize() > 0 after flushCommands()"); } } } void IPCThreadState::blockUntilThreadAvailable() void IPCThreadState::blockUntilThreadAvailable() Loading Loading @@ -501,6 +510,21 @@ void IPCThreadState::processPendingDerefs() } } } } void IPCThreadState::processPostWriteDerefs() { for (size_t i = 0; i < mPostWriteWeakDerefs.size(); i++) { RefBase::weakref_type* refs = mPostWriteWeakDerefs[i]; refs->decWeak(mProcess.get()); } mPostWriteWeakDerefs.clear(); for (size_t i = 0; i < mPostWriteStrongDerefs.size(); i++) { RefBase* obj = mPostWriteStrongDerefs[i]; obj->decStrong(mProcess.get()); } mPostWriteStrongDerefs.clear(); } void IPCThreadState::joinThreadPool(bool isMain) void IPCThreadState::joinThreadPool(bool isMain) { { LOG_THREADPOOL("**** THREAD %p (PID %d) IS JOINING THE THREAD POOL\n", (void*)pthread_self(), getpid()); LOG_THREADPOOL("**** THREAD %p (PID %d) IS JOINING THE THREAD POOL\n", (void*)pthread_self(), getpid()); Loading Loading @@ -627,11 +651,14 @@ status_t IPCThreadState::transact(int32_t handle, return err; return err; } } void IPCThreadState::incStrongHandle(int32_t handle) void IPCThreadState::incStrongHandle(int32_t handle, BpBinder *proxy) { { LOG_REMOTEREFS("IPCThreadState::incStrongHandle(%d)\n", handle); LOG_REMOTEREFS("IPCThreadState::incStrongHandle(%d)\n", handle); mOut.writeInt32(BC_ACQUIRE); mOut.writeInt32(BC_ACQUIRE); mOut.writeInt32(handle); mOut.writeInt32(handle); // Create a temp reference until the driver has handled this command. proxy->incStrong(mProcess.get()); mPostWriteStrongDerefs.push(proxy); } } void IPCThreadState::decStrongHandle(int32_t handle) void IPCThreadState::decStrongHandle(int32_t handle) Loading @@ -641,11 +668,14 @@ void IPCThreadState::decStrongHandle(int32_t handle) mOut.writeInt32(handle); mOut.writeInt32(handle); } } void IPCThreadState::incWeakHandle(int32_t handle) void IPCThreadState::incWeakHandle(int32_t handle, BpBinder *proxy) { { LOG_REMOTEREFS("IPCThreadState::incWeakHandle(%d)\n", handle); LOG_REMOTEREFS("IPCThreadState::incWeakHandle(%d)\n", handle); mOut.writeInt32(BC_INCREFS); mOut.writeInt32(BC_INCREFS); mOut.writeInt32(handle); mOut.writeInt32(handle); // Create a temp reference until the driver has handled this command. proxy->getWeakRefs()->incWeak(mProcess.get()); mPostWriteWeakDerefs.push(proxy->getWeakRefs()); } } void IPCThreadState::decWeakHandle(int32_t handle) void IPCThreadState::decWeakHandle(int32_t handle) Loading Loading @@ -897,8 +927,10 @@ status_t IPCThreadState::talkWithDriver(bool doReceive) if (bwr.write_consumed > 0) { if (bwr.write_consumed > 0) { if (bwr.write_consumed < mOut.dataSize()) if (bwr.write_consumed < mOut.dataSize()) mOut.remove(0, bwr.write_consumed); mOut.remove(0, bwr.write_consumed); else else { mOut.setDataSize(0); mOut.setDataSize(0); processPostWriteDerefs(); } } } if (bwr.read_consumed > 0) { if (bwr.read_consumed > 0) { mIn.setDataSize(bwr.read_consumed); mIn.setDataSize(bwr.read_consumed); Loading libs/binder/include/binder/IPCThreadState.h +5 −3 Original line number Original line Diff line number Diff line Loading @@ -64,9 +64,9 @@ public: uint32_t code, const Parcel& data, uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); Parcel* reply, uint32_t flags); void incStrongHandle(int32_t handle); void incStrongHandle(int32_t handle, BpBinder *proxy); void decStrongHandle(int32_t handle); void decStrongHandle(int32_t handle); void incWeakHandle(int32_t handle); void incWeakHandle(int32_t handle, BpBinder *proxy); void decWeakHandle(int32_t handle); void decWeakHandle(int32_t handle); status_t attemptIncStrongHandle(int32_t handle); status_t attemptIncStrongHandle(int32_t handle); static void expungeHandle(int32_t handle, IBinder* binder); static void expungeHandle(int32_t handle, IBinder* binder); Loading Loading @@ -106,6 +106,7 @@ private: status_t getAndExecuteCommand(); status_t getAndExecuteCommand(); status_t executeCommand(int32_t command); status_t executeCommand(int32_t command); void processPendingDerefs(); void processPendingDerefs(); void processPostWriteDerefs(); void clearCaller(); void clearCaller(); Loading @@ -118,7 +119,8 @@ private: const sp<ProcessState> mProcess; const sp<ProcessState> mProcess; Vector<BBinder*> mPendingStrongDerefs; Vector<BBinder*> mPendingStrongDerefs; Vector<RefBase::weakref_type*> mPendingWeakDerefs; Vector<RefBase::weakref_type*> mPendingWeakDerefs; Vector<RefBase*> mPostWriteStrongDerefs; Vector<RefBase::weakref_type*> mPostWriteWeakDerefs; Parcel mIn; Parcel mIn; Parcel mOut; Parcel mOut; status_t mLastError; status_t mLastError; Loading Loading
libs/binder/BpBinder.cpp +2 −2 Original line number Original line Diff line number Diff line Loading @@ -150,7 +150,7 @@ BpBinder::BpBinder(int32_t handle, int32_t trackedUid) ALOGV("Creating BpBinder %p handle %d\n", this, mHandle); ALOGV("Creating BpBinder %p handle %d\n", this, mHandle); extendObjectLifetime(OBJECT_LIFETIME_WEAK); extendObjectLifetime(OBJECT_LIFETIME_WEAK); IPCThreadState::self()->incWeakHandle(handle); IPCThreadState::self()->incWeakHandle(handle, this); } } bool BpBinder::isDescriptorCached() const { bool BpBinder::isDescriptorCached() const { Loading Loading @@ -412,7 +412,7 @@ void BpBinder::onFirstRef() { { ALOGV("onFirstRef BpBinder %p handle %d\n", this, mHandle); ALOGV("onFirstRef BpBinder %p handle %d\n", this, mHandle); IPCThreadState* ipc = IPCThreadState::self(); IPCThreadState* ipc = IPCThreadState::self(); if (ipc) ipc->incStrongHandle(mHandle); if (ipc) ipc->incStrongHandle(mHandle, this); } } void BpBinder::onLastStrongRef(const void* /*id*/) void BpBinder::onLastStrongRef(const void* /*id*/) Loading
libs/binder/IPCThreadState.cpp +35 −3 Original line number Original line Diff line number Diff line Loading @@ -409,6 +409,15 @@ void IPCThreadState::flushCommands() if (mProcess->mDriverFD <= 0) if (mProcess->mDriverFD <= 0) return; return; talkWithDriver(false); talkWithDriver(false); // The flush could have caused post-write refcount decrements to have // been executed, which in turn could result in BC_RELEASE/BC_DECREFS // being queued in mOut. So flush again, if we need to. if (mOut.dataSize() > 0) { talkWithDriver(false); } if (mOut.dataSize() > 0) { ALOGW("mOut.dataSize() > 0 after flushCommands()"); } } } void IPCThreadState::blockUntilThreadAvailable() void IPCThreadState::blockUntilThreadAvailable() Loading Loading @@ -501,6 +510,21 @@ void IPCThreadState::processPendingDerefs() } } } } void IPCThreadState::processPostWriteDerefs() { for (size_t i = 0; i < mPostWriteWeakDerefs.size(); i++) { RefBase::weakref_type* refs = mPostWriteWeakDerefs[i]; refs->decWeak(mProcess.get()); } mPostWriteWeakDerefs.clear(); for (size_t i = 0; i < mPostWriteStrongDerefs.size(); i++) { RefBase* obj = mPostWriteStrongDerefs[i]; obj->decStrong(mProcess.get()); } mPostWriteStrongDerefs.clear(); } void IPCThreadState::joinThreadPool(bool isMain) void IPCThreadState::joinThreadPool(bool isMain) { { LOG_THREADPOOL("**** THREAD %p (PID %d) IS JOINING THE THREAD POOL\n", (void*)pthread_self(), getpid()); LOG_THREADPOOL("**** THREAD %p (PID %d) IS JOINING THE THREAD POOL\n", (void*)pthread_self(), getpid()); Loading Loading @@ -627,11 +651,14 @@ status_t IPCThreadState::transact(int32_t handle, return err; return err; } } void IPCThreadState::incStrongHandle(int32_t handle) void IPCThreadState::incStrongHandle(int32_t handle, BpBinder *proxy) { { LOG_REMOTEREFS("IPCThreadState::incStrongHandle(%d)\n", handle); LOG_REMOTEREFS("IPCThreadState::incStrongHandle(%d)\n", handle); mOut.writeInt32(BC_ACQUIRE); mOut.writeInt32(BC_ACQUIRE); mOut.writeInt32(handle); mOut.writeInt32(handle); // Create a temp reference until the driver has handled this command. proxy->incStrong(mProcess.get()); mPostWriteStrongDerefs.push(proxy); } } void IPCThreadState::decStrongHandle(int32_t handle) void IPCThreadState::decStrongHandle(int32_t handle) Loading @@ -641,11 +668,14 @@ void IPCThreadState::decStrongHandle(int32_t handle) mOut.writeInt32(handle); mOut.writeInt32(handle); } } void IPCThreadState::incWeakHandle(int32_t handle) void IPCThreadState::incWeakHandle(int32_t handle, BpBinder *proxy) { { LOG_REMOTEREFS("IPCThreadState::incWeakHandle(%d)\n", handle); LOG_REMOTEREFS("IPCThreadState::incWeakHandle(%d)\n", handle); mOut.writeInt32(BC_INCREFS); mOut.writeInt32(BC_INCREFS); mOut.writeInt32(handle); mOut.writeInt32(handle); // Create a temp reference until the driver has handled this command. proxy->getWeakRefs()->incWeak(mProcess.get()); mPostWriteWeakDerefs.push(proxy->getWeakRefs()); } } void IPCThreadState::decWeakHandle(int32_t handle) void IPCThreadState::decWeakHandle(int32_t handle) Loading Loading @@ -897,8 +927,10 @@ status_t IPCThreadState::talkWithDriver(bool doReceive) if (bwr.write_consumed > 0) { if (bwr.write_consumed > 0) { if (bwr.write_consumed < mOut.dataSize()) if (bwr.write_consumed < mOut.dataSize()) mOut.remove(0, bwr.write_consumed); mOut.remove(0, bwr.write_consumed); else else { mOut.setDataSize(0); mOut.setDataSize(0); processPostWriteDerefs(); } } } if (bwr.read_consumed > 0) { if (bwr.read_consumed > 0) { mIn.setDataSize(bwr.read_consumed); mIn.setDataSize(bwr.read_consumed); Loading
libs/binder/include/binder/IPCThreadState.h +5 −3 Original line number Original line Diff line number Diff line Loading @@ -64,9 +64,9 @@ public: uint32_t code, const Parcel& data, uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); Parcel* reply, uint32_t flags); void incStrongHandle(int32_t handle); void incStrongHandle(int32_t handle, BpBinder *proxy); void decStrongHandle(int32_t handle); void decStrongHandle(int32_t handle); void incWeakHandle(int32_t handle); void incWeakHandle(int32_t handle, BpBinder *proxy); void decWeakHandle(int32_t handle); void decWeakHandle(int32_t handle); status_t attemptIncStrongHandle(int32_t handle); status_t attemptIncStrongHandle(int32_t handle); static void expungeHandle(int32_t handle, IBinder* binder); static void expungeHandle(int32_t handle, IBinder* binder); Loading Loading @@ -106,6 +106,7 @@ private: status_t getAndExecuteCommand(); status_t getAndExecuteCommand(); status_t executeCommand(int32_t command); status_t executeCommand(int32_t command); void processPendingDerefs(); void processPendingDerefs(); void processPostWriteDerefs(); void clearCaller(); void clearCaller(); Loading @@ -118,7 +119,8 @@ private: const sp<ProcessState> mProcess; const sp<ProcessState> mProcess; Vector<BBinder*> mPendingStrongDerefs; Vector<BBinder*> mPendingStrongDerefs; Vector<RefBase::weakref_type*> mPendingWeakDerefs; Vector<RefBase::weakref_type*> mPendingWeakDerefs; Vector<RefBase*> mPostWriteStrongDerefs; Vector<RefBase::weakref_type*> mPostWriteWeakDerefs; Parcel mIn; Parcel mIn; Parcel mOut; Parcel mOut; status_t mLastError; status_t mLastError; Loading