summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
author Steven Moreland <smoreland@google.com> 2021-06-03 21:40:45 +0000
committer Steven Moreland <smoreland@google.com> 2021-06-03 23:14:16 +0000
commit14e4cfae36aa878c6a9838299bc7b9aa42a16dfa (patch)
tree590d31fa3496c13af2ec5820a01f16229195161f /libs
parent8617ad805609e2d92de58b351342fc98aefa035c (diff)
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
Diffstat (limited to 'libs')
-rw-r--r--libs/binder/Parcel.cpp7
-rw-r--r--libs/binder/Stability.cpp1
-rw-r--r--libs/binder/include/binder/Binder.h10
-rw-r--r--libs/binder/include/binder/Stability.h15
4 files changed, 17 insertions, 16 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index d19b4d83fb..10188fee6e 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -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;
diff --git a/libs/binder/Stability.cpp b/libs/binder/Stability.cpp
index 601ce96db6..dac381974e 100644
--- a/libs/binder/Stability.cpp
+++ b/libs/binder/Stability.cpp
@@ -33,7 +33,6 @@ constexpr uint8_t kBinderWireFormatVersion = 1;
Stability::Category Stability::Category::currentFromLevel(Level level) {
return {
.version = kBinderWireFormatVersion,
- .reserved = {0},
.level = level,
};
}
diff --git a/libs/binder/include/binder/Binder.h b/libs/binder/include/binder/Binder.h
index 754f87cd7e..27db32c27d 100644
--- a/libs/binder/include/binder/Binder.h
+++ b/libs/binder/include/binder/Binder.h
@@ -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
};
// ---------------------------------------------------------------------------
diff --git a/libs/binder/include/binder/Stability.h b/libs/binder/include/binder/Stability.h
index 6bc607f298..629b565985 100644
--- a/libs/binder/include/binder/Stability.h
+++ b/libs/binder/include/binder/Stability.h
@@ -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();