Maintain Parcel ABI

Makes sure we don't change the memory layout of the Parcel class
to maintain binary compatibility with prebuilts linking against
libbinder.

Bug: 25004154
Change-Id: I656687497f08bb85cefda796aafa2341e601e30a
This commit is contained in:
Adrian Roos 2015-10-22 16:46:12 -07:00
parent cbf3726357
commit 6bb3114246
2 changed files with 34 additions and 18 deletions

View File

@ -341,10 +341,10 @@ public:
}; };
private: private:
size_t mBlobAshmemSize;
size_t mOpenAshmemSize; size_t mOpenAshmemSize;
public: public:
// TODO: Remove once ABI can be changed.
size_t getBlobAshmemSize() const; size_t getBlobAshmemSize() const;
size_t getOpenAshmemSize() const; size_t getOpenAshmemSize() const;
}; };
@ -414,9 +414,9 @@ inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel)
// Generic acquire and release of objects. // Generic acquire and release of objects.
void acquire_object(const sp<ProcessState>& proc, void acquire_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who, size_t* outAshmemSize); const flat_binder_object& obj, const void* who);
void release_object(const sp<ProcessState>& proc, void release_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who, size_t* outAshmemSize); const flat_binder_object& obj, const void* who);
void flatten_binder(const sp<ProcessState>& proc, void flatten_binder(const sp<ProcessState>& proc,
const sp<IBinder>& binder, flat_binder_object* out); const sp<IBinder>& binder, flat_binder_object* out);

View File

@ -124,10 +124,12 @@ void acquire_object(const sp<ProcessState>& proc,
} }
case BINDER_TYPE_FD: { case BINDER_TYPE_FD: {
if (obj.cookie != 0) { if (obj.cookie != 0) {
// If we own an ashmem fd, keep track of how much memory it refers to. if (outAshmemSize != NULL) {
int size = ashmem_get_size_region(obj.handle); // If we own an ashmem fd, keep track of how much memory it refers to.
if (size > 0) { int size = ashmem_get_size_region(obj.handle);
*outAshmemSize += size; if (size > 0) {
*outAshmemSize += size;
}
} }
} }
return; return;
@ -137,7 +139,13 @@ void acquire_object(const sp<ProcessState>& proc,
ALOGD("Invalid object type 0x%08x", obj.type); ALOGD("Invalid object type 0x%08x", obj.type);
} }
void release_object(const sp<ProcessState>& proc, void acquire_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who)
{
acquire_object(proc, obj, who, NULL);
}
static void release_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who, size_t* outAshmemSize) const flat_binder_object& obj, const void* who, size_t* outAshmemSize)
{ {
switch (obj.type) { switch (obj.type) {
@ -165,13 +173,15 @@ void release_object(const sp<ProcessState>& proc,
return; return;
} }
case BINDER_TYPE_FD: { case BINDER_TYPE_FD: {
if (obj.cookie != 0) { if (outAshmemSize != NULL) {
int size = ashmem_get_size_region(obj.handle); if (obj.cookie != 0) {
if (size > 0) { int size = ashmem_get_size_region(obj.handle);
*outAshmemSize -= size; if (size > 0) {
} *outAshmemSize -= size;
}
close(obj.handle); close(obj.handle);
}
} }
return; return;
} }
@ -180,6 +190,12 @@ void release_object(const sp<ProcessState>& proc,
ALOGE("Invalid object type 0x%08x", obj.type); ALOGE("Invalid object type 0x%08x", obj.type);
} }
void release_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who)
{
release_object(proc, obj, who, NULL);
}
inline static status_t finish_flatten_binder( inline static status_t finish_flatten_binder(
const sp<IBinder>& /*binder*/, const flat_binder_object& flat, Parcel* out) const sp<IBinder>& /*binder*/, const flat_binder_object& flat, Parcel* out)
{ {
@ -935,8 +951,6 @@ status_t Parcel::writeBlob(size_t len, bool mutableCopy, WritableBlob* outBlob)
int fd = ashmem_create_region("Parcel Blob", len); int fd = ashmem_create_region("Parcel Blob", len);
if (fd < 0) return NO_MEMORY; if (fd < 0) return NO_MEMORY;
mBlobAshmemSize += len;
int result = ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE); int result = ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE);
if (result < 0) { if (result < 0) {
status = result; status = result;
@ -1902,7 +1916,6 @@ void Parcel::initState()
mFdsKnown = true; mFdsKnown = true;
mAllowFds = true; mAllowFds = true;
mOwner = NULL; mOwner = NULL;
mBlobAshmemSize = 0;
mOpenAshmemSize = 0; mOpenAshmemSize = 0;
} }
@ -1923,7 +1936,10 @@ void Parcel::scanForFds() const
size_t Parcel::getBlobAshmemSize() const size_t Parcel::getBlobAshmemSize() const
{ {
return mBlobAshmemSize; // This used to return the size of all blobs that were written to ashmem, now we're returning
// the ashmem currently referenced by this Parcel, which should be equivalent.
// TODO: Remove method once ABI can be changed.
return mOpenAshmemSize;
} }
size_t Parcel::getOpenAshmemSize() const size_t Parcel::getOpenAshmemSize() const