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

Commit 3537fc39 authored by Milo Sredkov's avatar Milo Sredkov
Browse files

Stability fix for Native Binder Stats

Ensure interfaceDescriptor is initialised in all code paths. Report
binder stats before sending the reply. This may delay some binder
responses but should reduce the chance of a race condition which
may be causing b/421429613.

Test: v2/pixel-pts/device-presubmit-new-global1
Bug: 421429613
Bug: 299356196
Flag: build.RELEASE_LIBBINDER_BINDER_OBSERVER
Change-Id: Ie6e392b6c5dde701f1ddb3993bc374db9e8e5b97
parent 62df6333
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -1505,6 +1505,10 @@ status_t IPCThreadState::executeCommand(int32_t cmd)
                    reinterpret_cast<BBinder*>(tr.cookie)->decStrong(this);
                } else {
                    error = UNKNOWN_TRANSACTION;
#ifdef BINDER_WITH_OBSERVERS
                    [[clang::no_destroy]] static StaticString16 kDeletedBinder(u"<deleted_binder>");
                    interfaceDescriptor = kDeletedBinder;
#endif
                }

            } else {
@@ -1515,6 +1519,15 @@ status_t IPCThreadState::executeCommand(int32_t cmd)
            }
#ifdef BINDER_WITH_OBSERVERS
            int64_t endTimeNanos = uptimeNanos();
            BinderCallData observerData = {
                    .interfaceDescriptor = interfaceDescriptor,
                    .transactionCode = tr.code,
                    .startTimeNanos = startTimeNanos,
                    .endTimeNanos = endTimeNanos,
                    .senderUid = tr.sender_euid,
            };
            ProcessState::self()->mBinderObserver->addStatMaybeFlush(mBinderStatsQueue,
                                                                     observerData);
#endif
            //ALOGI("<<<< TRANSACT from pid %d restore pid %d sid %s uid %d\n",
            //     mCallingPid, origPid, (origSid ? origSid : "<N/A>"), origUid);
@@ -1559,17 +1572,6 @@ status_t IPCThreadState::executeCommand(int32_t cmd)
                }
                LOG_ONEWAY("NOT sending reply to %d!", mCallingPid);
            }
#ifdef BINDER_WITH_OBSERVERS
            BinderCallData observerData = {
                    .interfaceDescriptor = interfaceDescriptor,
                    .transactionCode = tr.code,
                    .startTimeNanos = startTimeNanos,
                    .endTimeNanos = endTimeNanos,
                    .senderUid = tr.sender_euid,
            };
            ProcessState::self()->mBinderObserver->addStatMaybeFlush(mBinderStatsQueue,
                                                                     observerData);
#endif
            mServingStackPointer = origServingStackPointer;
            mCallingPid = origPid;
            mCallingSid = origSid;