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

Commit 3f3618b4 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

libaudiohal@aidl: Abort on data FMQ pointer corruption

Issue a fatal error when the data FMQ detects internal pointers
corruption. This condition indicates some low level problems
and should be diagnosed as fast as possible.

Bug: 338974476
Test: m
Change-Id: I8b9c9c9111ad0327db84ac3dc324e8a1cdf8c478
parent 0c88d1c5
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -323,8 +323,11 @@ status_t StreamHalAidl::transfer(void *buffer, size_t bytes, size_t *transferred
            return INVALID_OPERATION;
        }
    }
    StreamContextAidl::DataMQ::Error fmqError = StreamContextAidl::DataMQ::Error::NONE;
    std::string fmqErrorMsg;
    if (!mIsInput) {
        bytes = std::min(bytes, mContext.getDataMQ()->availableToWrite());
        bytes = std::min(bytes,
                mContext.getDataMQ()->availableToWrite(&fmqError, &fmqErrorMsg));
    }
    StreamDescriptor::Command burst =
            StreamDescriptor::Command::make<StreamDescriptor::Command::Tag::burst>(bytes);
@@ -341,12 +344,14 @@ status_t StreamHalAidl::transfer(void *buffer, size_t bytes, size_t *transferred
        LOG_ALWAYS_FATAL_IF(*transferred > bytes,
                "%s: HAL module read %zu bytes, which exceeds requested count %zu",
                __func__, *transferred, bytes);
        if (auto toRead = mContext.getDataMQ()->availableToRead();
        if (auto toRead = mContext.getDataMQ()->availableToRead(&fmqError, &fmqErrorMsg);
                toRead != 0 && !mContext.getDataMQ()->read(static_cast<int8_t*>(buffer), toRead)) {
            ALOGE("%s: failed to read %zu bytes to data MQ", __func__, toRead);
            return NOT_ENOUGH_DATA;
        }
    }
    LOG_ALWAYS_FATAL_IF(fmqError != StreamContextAidl::DataMQ::Error::NONE,
            "%s", fmqErrorMsg.c_str());
    mStreamPowerLog.log(buffer, *transferred);
    return OK;
}