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

Commit 14e4cfae authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder: +2 bytes in BBinder from stability rep

sizeof(BBinder) may not be changed unless 1,000s of people in many
different companies fundamentally change the way they work. So, with
precious few bits to spare, we make room by changing the way that
binder stability reserves space on the wire. Now, it uses the least
significant 16-bits of the 32-bits which is reserved on the wire.

The sideeffect of this straightforward implementation is that the wire
protocol is slightly changed. This is an intentional change in order to
exercise its instability, perhaps as an early warning.

Bug: 166282674
Test: boot, binderLibTest

Change-Id: I654fcd2cc9d20cbac557d1a176a5095c491d88cf
parent 8617ad80
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -173,8 +173,8 @@ static void release_object(const sp<ProcessState>& proc,
status_t Parcel::finishFlattenBinder(const sp<IBinder>& binder)
{
    internal::Stability::tryMarkCompilationUnit(binder.get());
    auto category = internal::Stability::getCategory(binder.get());
    return writeInt32(category.repr());
    int16_t rep = internal::Stability::getCategory(binder.get()).repr();
    return writeInt32(rep);
}

status_t Parcel::finishUnflattenBinder(
@@ -184,7 +184,8 @@ status_t Parcel::finishUnflattenBinder(
    status_t status = readInt32(&stability);
    if (status != OK) return status;

    status = internal::Stability::setRepr(binder.get(), stability, true /*log*/);
    status = internal::Stability::setRepr(binder.get(), static_cast<int16_t>(stability),
                                          true /*log*/);
    if (status != OK) return status;

    *out = binder;
+0 −1
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ constexpr uint8_t kBinderWireFormatVersion = 1;
Stability::Category Stability::Category::currentFromLevel(Level level) {
    return {
        .version = kBinderWireFormatVersion,
        .reserved = {0},
        .level = level,
    };
}
+6 −4
Original line number Diff line number Diff line
@@ -119,10 +119,12 @@ private:
    std::atomic<Extras*> mExtras;

    friend ::android::internal::Stability;
    union {
        int32_t mStability;
        void* mReserved0;
    };
    int16_t mStability;
    int16_t mReserved0;

#ifdef __LP64__
    int32_t mReserved1;
#endif
};

// ---------------------------------------------------------------------------
+7 −8
Original line number Diff line number Diff line
@@ -136,14 +136,15 @@ private:
        VINTF = 0b111111,
    };

    // This is the format of stability passed on the wire.
    // This is the format of stability passed on the wire. It is only 2 bytes
    // long, but 2 bytes in addition to this are reserved here. The difference
    // in size is in order to free up space in BBinder, which is fixed by
    // prebuilts inheriting from it.
    struct Category {
        static inline Category fromRepr(int32_t representation) {
        static inline Category fromRepr(int16_t representation) {
            return *reinterpret_cast<Category*>(&representation);
        }
        int32_t repr() const {
            return *reinterpret_cast<const int32_t*>(this);
        }
        int16_t repr() const { return *reinterpret_cast<const int16_t*>(this); }
        static inline Category currentFromLevel(Level level);

        bool operator== (const Category& o) const {
@@ -161,12 +162,10 @@ private:
        // class must write parcels according to the version documented here.
        uint8_t version;

        uint8_t reserved[2];

        // bitmask of Stability::Level
        Level level;
    };
    static_assert(sizeof(Category) == sizeof(int32_t));
    static_assert(sizeof(Category) == sizeof(int16_t));

    // returns the stability according to how this was built
    static Level getLocalLevel();