Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d768b6a authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "libbinder: don't hold global locks for callbacks.." into main am: 2a98830a

parents 18b15cce 2a98830a
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -160,11 +160,12 @@ void BpBinder::ObjectManager::kill()

// ---------------------------------------------------------------------------

sp<BpBinder> BpBinder::create(int32_t handle) {
sp<BpBinder> BpBinder::create(int32_t handle, std::function<void()>* postTask) {
    if constexpr (!kEnableKernelIpc) {
        LOG_ALWAYS_FATAL("Binder kernel driver disabled at build time");
        return nullptr;
    }
    LOG_ALWAYS_FATAL_IF(postTask == nullptr, "BAD STATE");

    int32_t trackedUid = -1;
    if (sCountByUidEnabled) {
@@ -183,7 +184,11 @@ sp<BpBinder> BpBinder::create(int32_t handle) {
                ALOGE("Still too many binder proxy objects sent to uid %d from uid %d (%d proxies "
                      "held)",
                      getuid(), trackedUid, trackedValue);
                if (sLimitCallback) sLimitCallback(trackedUid);

                if (sLimitCallback) {
                    *postTask = [=]() { sLimitCallback(trackedUid); };
                }

                sLastLimitCallbackMap[trackedUid] = trackedValue;
            }
        } else {
@@ -197,7 +202,11 @@ sp<BpBinder> BpBinder::create(int32_t handle) {
                ALOGE("Too many binder proxy objects sent to uid %d from uid %d (%d proxies held)",
                      getuid(), trackedUid, trackedValue);
                sTrackingMap[trackedUid] |= LIMIT_REACHED_MASK;
                if (sLimitCallback) sLimitCallback(trackedUid);

                if (sLimitCallback) {
                    *postTask = [=]() { sLimitCallback(trackedUid); };
                }

                sLastLimitCallbackMap[trackedUid] = trackedValue & COUNTING_VALUE_MASK;
                if (sBinderProxyThrottleCreate) {
                    ALOGI("Throttling binder proxy creates from uid %d in uid %d until binder proxy"
+6 −1
Original line number Diff line number Diff line
@@ -310,6 +310,7 @@ extern sp<BBinder> the_context_object;
sp<IBinder> ProcessState::getStrongProxyForHandle(int32_t handle)
{
    sp<IBinder> result;
    std::function<void()> postTask;

    std::unique_lock<std::mutex> _l(mLock);

@@ -357,7 +358,7 @@ sp<IBinder> ProcessState::getStrongProxyForHandle(int32_t handle)
                   return nullptr;
            }

            sp<BpBinder> b = BpBinder::PrivateAccessor::create(handle);
            sp<BpBinder> b = BpBinder::PrivateAccessor::create(handle, &postTask);
            e->binder = b.get();
            if (b) e->refs = b->getWeakRefs();
            result = b;
@@ -370,6 +371,10 @@ sp<IBinder> ProcessState::getStrongProxyForHandle(int32_t handle)
        }
    }

    _l.unlock();

    if (postTask) postTask();

    return result;
}

+4 −2
Original line number Diff line number Diff line
@@ -134,7 +134,9 @@ public:
        friend class ::android::RpcState;
        explicit PrivateAccessor(const BpBinder* binder) : mBinder(binder) {}

        static sp<BpBinder> create(int32_t handle) { return BpBinder::create(handle); }
        static sp<BpBinder> create(int32_t handle, std::function<void()>* postTask) {
            return BpBinder::create(handle, postTask);
        }
        static sp<BpBinder> create(const sp<RpcSession>& session, uint64_t address) {
            return BpBinder::create(session, address);
        }
@@ -156,7 +158,7 @@ private:
    friend PrivateAccessor;
    friend class sp<BpBinder>;

    static sp<BpBinder> create(int32_t handle);
    static sp<BpBinder> create(int32_t handle, std::function<void()>* postTask);
    static sp<BpBinder> create(const sp<RpcSession>& session, uint64_t address);

    struct BinderHandle {