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

Commit 947c2038 authored by Robin Lee's avatar Robin Lee
Browse files

Print correctly-scrubbed number of binder proxies

currentValue is the version that doesn't include high bits dedicated
to warning/error flags. It's computed in both branches of an if-else
so let's unify it to avoid mistakes.

Fixes the following log message seen in the wild:

> Too many binder proxy objects sent to uid 1000 from uid 10285
> (1073747824 proxies held)

Bug: 411022463
Bug: 298263955
Test: WMShellUnitTests (see linked bug)
Flag: EXEMPT printing without the flag now
Change-Id: I94dc7263f5daff26b5ad730b82b024675389c20e
parent 91ae097a
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -164,28 +164,28 @@ sp<BpBinder> BpBinder::create(int32_t handle, std::function<void()>* postTask) {
    if (sCountByUidEnabled) {
        trackedUid = IPCThreadState::self()->getCallingUid();
        RpcMutexUniqueLock _l(sTrackingLock);
        uint32_t trackedValue = sTrackingMap[trackedUid];
        const uint32_t trackedValue = sTrackingMap[trackedUid];
        const uint32_t currentValue = trackedValue & COUNTING_VALUE_MASK;

        if (trackedValue & LIMIT_REACHED_MASK) [[unlikely]] {
            if (sBinderProxyThrottleCreate) {
                return nullptr;
            }
            trackedValue = trackedValue & COUNTING_VALUE_MASK;
            uint32_t lastLimitCallbackAt = sLastLimitCallbackMap[trackedUid];

            if (trackedValue > lastLimitCallbackAt &&
                (trackedValue - lastLimitCallbackAt > sBinderProxyCountHighWatermark)) {
            if (currentValue > lastLimitCallbackAt &&
                (currentValue - lastLimitCallbackAt > sBinderProxyCountHighWatermark)) {
                ALOGE("Still too many binder proxy objects sent to uid %d from uid %d (%d proxies "
                      "held)",
                      getuid(), trackedUid, trackedValue);
                      getuid(), trackedUid, currentValue);

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

                sLastLimitCallbackMap[trackedUid] = trackedValue;
                sLastLimitCallbackMap[trackedUid] = currentValue;
            }
        } else {
            uint32_t currentValue = trackedValue & COUNTING_VALUE_MASK;
            if (currentValue >= sBinderProxyCountWarningWatermark
                    && currentValue < sBinderProxyCountHighWatermark
                    && ((trackedValue & WARNING_REACHED_MASK) == 0)) [[unlikely]] {
@@ -195,14 +195,14 @@ sp<BpBinder> BpBinder::create(int32_t handle, std::function<void()>* postTask) {
                }
            } else if (currentValue >= sBinderProxyCountHighWatermark) {
                ALOGE("Too many binder proxy objects sent to uid %d from uid %d (%d proxies held)",
                      getuid(), trackedUid, trackedValue);
                      getuid(), trackedUid, currentValue);
                sTrackingMap[trackedUid] |= LIMIT_REACHED_MASK;

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

                sLastLimitCallbackMap[trackedUid] = trackedValue & COUNTING_VALUE_MASK;
                sLastLimitCallbackMap[trackedUid] = currentValue;
                if (sBinderProxyThrottleCreate) {
                    ALOGI("Throttling binder proxy creates from uid %d in uid %d until binder proxy"
                          " count drops below %d",