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

Commit 4717a22f authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "media.bufferpool2: ensure message-ids are safe from overflow/underflow"...

Merge "media.bufferpool2: ensure message-ids are safe from overflow/underflow" into main am: 98aba894

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2981011



Change-Id: I798330344c3dc1c013f35ecc214e2bf393138eb4
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 56c20c88 98aba894
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -102,11 +102,11 @@ void BufferPool::Invalidation::onBufferInvalidated(
        if (it->isInvalidated(bufferId)) {
            uint32_t msgId = 0;
            if (it->mNeedsAck) {
                msgId = ++mInvalidationId;
                if (msgId == 0) {
                    // wrap happens
                    msgId = ++mInvalidationId;
                if (mInvalidationId == UINT_MAX) {
                    // wrap happens;
                    mInvalidationId = 0;
                }
                msgId = ++mInvalidationId;
            }
            channel.postInvalidation(msgId, it->mFrom, it->mTo);
            it = mPendings.erase(it);
@@ -125,11 +125,11 @@ void BufferPool::Invalidation::onInvalidationRequest(
        const std::shared_ptr<Accessor> &impl) {
        uint32_t msgId = 0;
    if (needsAck) {
        msgId = ++mInvalidationId;
        if (msgId == 0) {
        if (mInvalidationId == UINT_MAX) {
            //wrap happens
            msgId = ++mInvalidationId;
            mInvalidationId = 0;
        }
        msgId = ++mInvalidationId;
    }
    ALOGV("bufferpool2 invalidation requested and queued");
    if (left == 0) {
+10 −1
Original line number Diff line number Diff line
@@ -26,8 +26,17 @@ namespace aidl::android::hardware::media::bufferpool2::implementation {

using aidl::android::hardware::media::bufferpool2::BufferStatus;

uint32_t wrappedMinus(uint32_t a, uint32_t b) {
    if (a >= b) {
        return a - b;
    } else {
        return ~(b - a) + 1;
    }
}

bool isMessageLater(uint32_t curMsgId, uint32_t prevMsgId) {
    return curMsgId != prevMsgId && curMsgId - prevMsgId < prevMsgId - curMsgId;
    return curMsgId != prevMsgId &&
            wrappedMinus(curMsgId, prevMsgId) < wrappedMinus(prevMsgId, curMsgId);
}

bool isBufferInRange(BufferId from, BufferId to, BufferId bufferId) {