summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2014-11-11 16:44:25 -0800
committerJeff Brown <jeffbrown@google.com>2015-06-05 17:40:59 -0700
commit13b1604018968408bcc5553e1fa5ea9df3e4e009 (patch)
tree3ea640f1e7daaaa63a71fbe133729fba26bd95bd /include
parent9d2c5a7c678bd384df0fb29952cf8943e7b1b160 (diff)
downloadframeworks_native-13b1604018968408bcc5553e1fa5ea9df3e4e009.zip
frameworks_native-13b1604018968408bcc5553e1fa5ea9df3e4e009.tar.gz
frameworks_native-13b1604018968408bcc5553e1fa5ea9df3e4e009.tar.bz2
Enable more flexible usage of blobs in parcels.
Add functions to allow a client to take over the ashmem region that was transferred so that it can claim it for its own and reuse it. Add support for mutable ashmem regions too. Bug: 21428802 Change-Id: I16eca338cdb99b07d81fc43573d53ce86dbc60c8
Diffstat (limited to 'include')
-rw-r--r--include/binder/Parcel.h22
1 files changed, 17 insertions, 5 deletions
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h
index ddaf54f..3ada1e9 100644
--- a/include/binder/Parcel.h
+++ b/include/binder/Parcel.h
@@ -60,6 +60,7 @@ public:
status_t appendFrom(const Parcel *parcel,
size_t start, size_t len);
+ bool allowFds() const;
bool pushAllowFds(bool allowFds);
void restoreAllowFds(bool lastValue);
@@ -132,9 +133,16 @@ public:
// Writes a blob to the parcel.
// If the blob is small, then it is stored in-place, otherwise it is
- // transferred by way of an anonymous shared memory region.
+ // transferred by way of an anonymous shared memory region. Prefer sending
+ // immutable blobs if possible since they may be subsequently transferred between
+ // processes without further copying whereas mutable blobs always need to be copied.
// The caller should call release() on the blob after writing its contents.
- status_t writeBlob(size_t len, WritableBlob* outBlob);
+ status_t writeBlob(size_t len, bool mutableCopy, WritableBlob* outBlob);
+
+ // Write an existing immutable blob file descriptor to the parcel.
+ // This allows the client to send the same blob to multiple processes
+ // as long as it keeps a dup of the blob file descriptor handy for later.
+ status_t writeDupImmutableBlobFileDescriptor(int fd);
status_t writeObject(const flat_binder_object& val, bool nullMetaData);
@@ -270,16 +278,19 @@ private:
Blob();
~Blob();
+ void clear();
void release();
inline size_t size() const { return mSize; }
+ inline int fd() const { return mFd; };
+ inline bool isMutable() const { return mMutable; }
protected:
- void init(bool mapped, void* data, size_t size);
- void clear();
+ void init(int fd, void* data, size_t size, bool isMutable);
- bool mMapped;
+ int mFd; // owned by parcel so not closed when released
void* mData;
size_t mSize;
+ bool mMutable;
};
class FlattenableHelperInterface {
@@ -320,6 +331,7 @@ public:
friend class Parcel;
public:
inline const void* data() const { return mData; }
+ inline void* mutableData() { return isMutable() ? mData : NULL; }
};
class WritableBlob : public Blob {