Loading libs/binder/ProcessState.cpp +19 −76 Original line number Original line Diff line number Diff line Loading @@ -24,7 +24,6 @@ #include <cutils/atomic.h> #include <cutils/atomic.h> #include <utils/Log.h> #include <utils/Log.h> #include <utils/String8.h> #include <utils/String8.h> #include <utils/String8.h> #include <utils/threads.h> #include <utils/threads.h> #include <private/binder/binder_module.h> #include <private/binder/binder_module.h> Loading Loading @@ -108,58 +107,11 @@ sp<ProcessState> ProcessState::selfOrNull() return gProcess; return gProcess; } } void ProcessState::setContextObject(const sp<IBinder>& object) { setContextObject(object, String16("default")); } sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& /*caller*/) sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& /*caller*/) { { return getStrongProxyForHandle(0); return getStrongProxyForHandle(0); } } void ProcessState::setContextObject(const sp<IBinder>& object, const String16& name) { AutoMutex _l(mLock); mContexts.add(name, object); } sp<IBinder> ProcessState::getContextObject(const String16& name, const sp<IBinder>& caller) { mLock.lock(); sp<IBinder> object( mContexts.indexOfKey(name) >= 0 ? mContexts.valueFor(name) : nullptr); mLock.unlock(); //printf("Getting context object %s for %p\n", String8(name).string(), caller.get()); if (object != nullptr) return object; // Don't attempt to retrieve contexts if we manage them if (mManagesContexts) { ALOGE("getContextObject(%s) failed, but we manage the contexts!\n", String8(name).string()); return nullptr; } IPCThreadState* ipc = IPCThreadState::self(); { Parcel data, reply; // no interface token on this magic transaction data.writeString16(name); data.writeStrongBinder(caller); status_t result = ipc->transact(0 /*magic*/, 0, data, &reply, 0); if (result == NO_ERROR) { object = reply.readStrongBinder(); } } ipc->flushCommands(); if (object != nullptr) setContextObject(object, name); return object; } void ProcessState::startThreadPool() void ProcessState::startThreadPool() { { AutoMutex _l(mLock); AutoMutex _l(mLock); Loading @@ -169,14 +121,8 @@ void ProcessState::startThreadPool() } } } } bool ProcessState::isContextManager(void) const { return mManagesContexts; } bool ProcessState::becomeContextManager(context_check_func checkFunc, void* userData) bool ProcessState::becomeContextManager(context_check_func checkFunc, void* userData) { { if (!mManagesContexts) { AutoMutex _l(mLock); AutoMutex _l(mLock); mBinderContextCheckFunc = checkFunc; mBinderContextCheckFunc = checkFunc; mBinderContextUserData = userData; mBinderContextUserData = userData; Loading @@ -185,7 +131,7 @@ bool ProcessState::becomeContextManager(context_check_func checkFunc, void* user .flags = FLAT_BINDER_FLAG_TXN_SECURITY_CTX, .flags = FLAT_BINDER_FLAG_TXN_SECURITY_CTX, }; }; status_t result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR_EXT, &obj); int result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR_EXT, &obj); // fallback to original method // fallback to original method if (result != 0) { if (result != 0) { Loading @@ -195,15 +141,13 @@ bool ProcessState::becomeContextManager(context_check_func checkFunc, void* user result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy); result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy); } } if (result == 0) { if (result == -1) { mManagesContexts = true; } else if (result == -1) { mBinderContextCheckFunc = nullptr; mBinderContextCheckFunc = nullptr; mBinderContextUserData = nullptr; mBinderContextUserData = nullptr; ALOGE("Binder ioctl to become context manager failed: %s\n", strerror(errno)); ALOGE("Binder ioctl to become context manager failed: %s\n", strerror(errno)); } } } return mManagesContexts; return result == 0; } } // Get references to userspace objects held by the kernel binder driver // Get references to userspace objects held by the kernel binder driver Loading Loading @@ -430,7 +374,6 @@ ProcessState::ProcessState(const char *driver) , mExecutingThreadsCount(0) , mExecutingThreadsCount(0) , mMaxThreads(DEFAULT_MAX_BINDER_THREADS) , mMaxThreads(DEFAULT_MAX_BINDER_THREADS) , mStarvationStartTimeMs(0) , mStarvationStartTimeMs(0) , mManagesContexts(false) , mBinderContextCheckFunc(nullptr) , mBinderContextCheckFunc(nullptr) , mBinderContextUserData(nullptr) , mBinderContextUserData(nullptr) , mThreadPoolStarted(false) , mThreadPoolStarted(false) Loading libs/binder/include/binder/ProcessState.h +1 −15 Original line number Original line Diff line number Diff line Loading @@ -45,21 +45,14 @@ public: */ */ static sp<ProcessState> initWithDriver(const char *driver); static sp<ProcessState> initWithDriver(const char *driver); void setContextObject(const sp<IBinder>& object); sp<IBinder> getContextObject(const sp<IBinder>& caller); sp<IBinder> getContextObject(const sp<IBinder>& caller); void setContextObject(const sp<IBinder>& object, const String16& name); sp<IBinder> getContextObject(const String16& name, const sp<IBinder>& caller); void startThreadPool(); void startThreadPool(); typedef bool (*context_check_func)(const String16& name, typedef bool (*context_check_func)(const String16& name, const sp<IBinder>& caller, const sp<IBinder>& caller, void* userData); void* userData); bool isContextManager(void) const; bool becomeContextManager( bool becomeContextManager( context_check_func checkFunc, context_check_func checkFunc, void* userData); void* userData); Loading Loading @@ -121,19 +114,12 @@ private: int64_t mStarvationStartTimeMs; int64_t mStarvationStartTimeMs; mutable Mutex mLock; // protects everything below. mutable Mutex mLock; // protects everything below. // TODO: mManagesContexts is often accessed without the lock. // Explain why that's safe. Vector<handle_entry>mHandleToObject; Vector<handle_entry>mHandleToObject; bool mManagesContexts; context_check_func mBinderContextCheckFunc; context_check_func mBinderContextCheckFunc; void* mBinderContextUserData; void* mBinderContextUserData; KeyedVector<String16, sp<IBinder> > mContexts; String8 mRootDir; String8 mRootDir; bool mThreadPoolStarted; bool mThreadPoolStarted; volatile int32_t mThreadPoolSeq; volatile int32_t mThreadPoolSeq; Loading Loading
libs/binder/ProcessState.cpp +19 −76 Original line number Original line Diff line number Diff line Loading @@ -24,7 +24,6 @@ #include <cutils/atomic.h> #include <cutils/atomic.h> #include <utils/Log.h> #include <utils/Log.h> #include <utils/String8.h> #include <utils/String8.h> #include <utils/String8.h> #include <utils/threads.h> #include <utils/threads.h> #include <private/binder/binder_module.h> #include <private/binder/binder_module.h> Loading Loading @@ -108,58 +107,11 @@ sp<ProcessState> ProcessState::selfOrNull() return gProcess; return gProcess; } } void ProcessState::setContextObject(const sp<IBinder>& object) { setContextObject(object, String16("default")); } sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& /*caller*/) sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& /*caller*/) { { return getStrongProxyForHandle(0); return getStrongProxyForHandle(0); } } void ProcessState::setContextObject(const sp<IBinder>& object, const String16& name) { AutoMutex _l(mLock); mContexts.add(name, object); } sp<IBinder> ProcessState::getContextObject(const String16& name, const sp<IBinder>& caller) { mLock.lock(); sp<IBinder> object( mContexts.indexOfKey(name) >= 0 ? mContexts.valueFor(name) : nullptr); mLock.unlock(); //printf("Getting context object %s for %p\n", String8(name).string(), caller.get()); if (object != nullptr) return object; // Don't attempt to retrieve contexts if we manage them if (mManagesContexts) { ALOGE("getContextObject(%s) failed, but we manage the contexts!\n", String8(name).string()); return nullptr; } IPCThreadState* ipc = IPCThreadState::self(); { Parcel data, reply; // no interface token on this magic transaction data.writeString16(name); data.writeStrongBinder(caller); status_t result = ipc->transact(0 /*magic*/, 0, data, &reply, 0); if (result == NO_ERROR) { object = reply.readStrongBinder(); } } ipc->flushCommands(); if (object != nullptr) setContextObject(object, name); return object; } void ProcessState::startThreadPool() void ProcessState::startThreadPool() { { AutoMutex _l(mLock); AutoMutex _l(mLock); Loading @@ -169,14 +121,8 @@ void ProcessState::startThreadPool() } } } } bool ProcessState::isContextManager(void) const { return mManagesContexts; } bool ProcessState::becomeContextManager(context_check_func checkFunc, void* userData) bool ProcessState::becomeContextManager(context_check_func checkFunc, void* userData) { { if (!mManagesContexts) { AutoMutex _l(mLock); AutoMutex _l(mLock); mBinderContextCheckFunc = checkFunc; mBinderContextCheckFunc = checkFunc; mBinderContextUserData = userData; mBinderContextUserData = userData; Loading @@ -185,7 +131,7 @@ bool ProcessState::becomeContextManager(context_check_func checkFunc, void* user .flags = FLAT_BINDER_FLAG_TXN_SECURITY_CTX, .flags = FLAT_BINDER_FLAG_TXN_SECURITY_CTX, }; }; status_t result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR_EXT, &obj); int result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR_EXT, &obj); // fallback to original method // fallback to original method if (result != 0) { if (result != 0) { Loading @@ -195,15 +141,13 @@ bool ProcessState::becomeContextManager(context_check_func checkFunc, void* user result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy); result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy); } } if (result == 0) { if (result == -1) { mManagesContexts = true; } else if (result == -1) { mBinderContextCheckFunc = nullptr; mBinderContextCheckFunc = nullptr; mBinderContextUserData = nullptr; mBinderContextUserData = nullptr; ALOGE("Binder ioctl to become context manager failed: %s\n", strerror(errno)); ALOGE("Binder ioctl to become context manager failed: %s\n", strerror(errno)); } } } return mManagesContexts; return result == 0; } } // Get references to userspace objects held by the kernel binder driver // Get references to userspace objects held by the kernel binder driver Loading Loading @@ -430,7 +374,6 @@ ProcessState::ProcessState(const char *driver) , mExecutingThreadsCount(0) , mExecutingThreadsCount(0) , mMaxThreads(DEFAULT_MAX_BINDER_THREADS) , mMaxThreads(DEFAULT_MAX_BINDER_THREADS) , mStarvationStartTimeMs(0) , mStarvationStartTimeMs(0) , mManagesContexts(false) , mBinderContextCheckFunc(nullptr) , mBinderContextCheckFunc(nullptr) , mBinderContextUserData(nullptr) , mBinderContextUserData(nullptr) , mThreadPoolStarted(false) , mThreadPoolStarted(false) Loading
libs/binder/include/binder/ProcessState.h +1 −15 Original line number Original line Diff line number Diff line Loading @@ -45,21 +45,14 @@ public: */ */ static sp<ProcessState> initWithDriver(const char *driver); static sp<ProcessState> initWithDriver(const char *driver); void setContextObject(const sp<IBinder>& object); sp<IBinder> getContextObject(const sp<IBinder>& caller); sp<IBinder> getContextObject(const sp<IBinder>& caller); void setContextObject(const sp<IBinder>& object, const String16& name); sp<IBinder> getContextObject(const String16& name, const sp<IBinder>& caller); void startThreadPool(); void startThreadPool(); typedef bool (*context_check_func)(const String16& name, typedef bool (*context_check_func)(const String16& name, const sp<IBinder>& caller, const sp<IBinder>& caller, void* userData); void* userData); bool isContextManager(void) const; bool becomeContextManager( bool becomeContextManager( context_check_func checkFunc, context_check_func checkFunc, void* userData); void* userData); Loading Loading @@ -121,19 +114,12 @@ private: int64_t mStarvationStartTimeMs; int64_t mStarvationStartTimeMs; mutable Mutex mLock; // protects everything below. mutable Mutex mLock; // protects everything below. // TODO: mManagesContexts is often accessed without the lock. // Explain why that's safe. Vector<handle_entry>mHandleToObject; Vector<handle_entry>mHandleToObject; bool mManagesContexts; context_check_func mBinderContextCheckFunc; context_check_func mBinderContextCheckFunc; void* mBinderContextUserData; void* mBinderContextUserData; KeyedVector<String16, sp<IBinder> > mContexts; String8 mRootDir; String8 mRootDir; bool mThreadPoolStarted; bool mThreadPoolStarted; volatile int32_t mThreadPoolSeq; volatile int32_t mThreadPoolSeq; Loading