summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2018-10-09 15:12:20 -0700
committerSteven Moreland <smoreland@google.com>2018-10-09 15:53:59 -0700
commit6d50315da66f54551ceb30eaa2ba0f1e5d94e61c (patch)
treea6ee9a20e8dc815d79506b46ba90d94cf877b47e
parentee65dc4c50362d34b6517a65c9953f72ac46b5df (diff)
downloadlibhidl-6d50315da66f54551ceb30eaa2ba0f1e5d94e61c.tar.gz
MQDescriptor: allow copies.
When scatter-gather is used in order to read an FMQ object from a binder buffer, we are left with a 'const MQDescriptor<...>*' which points into the binder buffer. When this descriptor is part of a struct which is returned, and this struct is returned using a copy (not scatter gather since the struct contains a non-fixed-width item like an interface), it must be copied into the default constructed member of that struct. Change-Id: Iafb3ecafc2822e90662d49e1d3d53b12ffde650b Fixes: 117239572 Test: hidl_test
-rw-r--r--base/include/hidl/MQDescriptor.h23
1 files changed, 15 insertions, 8 deletions
diff --git a/base/include/hidl/MQDescriptor.h b/base/include/hidl/MQDescriptor.h
index 23be971..a8a176b 100644
--- a/base/include/hidl/MQDescriptor.h
+++ b/base/include/hidl/MQDescriptor.h
@@ -69,8 +69,8 @@ struct MQDescriptor {
MQDescriptor();
~MQDescriptor();
- explicit MQDescriptor(const MQDescriptor &other);
- MQDescriptor &operator=(const MQDescriptor &other) = delete;
+ explicit MQDescriptor(const MQDescriptor& other) : MQDescriptor() { *this = other; }
+ MQDescriptor& operator=(const MQDescriptor& other);
size_t getSize() const;
@@ -213,12 +213,17 @@ MQDescriptor<T, flavor>::MQDescriptor(size_t bufferSize, native_handle_t *nHandl
}
}
-template<typename T, MQFlavor flavor>
-MQDescriptor<T, flavor>::MQDescriptor(const MQDescriptor<T, flavor> &other)
- : mGrantors(other.mGrantors),
- mHandle(nullptr),
- mQuantum(other.mQuantum),
- mFlags(other.mFlags) {
+template <typename T, MQFlavor flavor>
+MQDescriptor<T, flavor>& MQDescriptor<T, flavor>::operator=(const MQDescriptor& other) {
+ mGrantors = other.mGrantors;
+ if (mHandle != nullptr) {
+ native_handle_close(mHandle);
+ native_handle_delete(mHandle);
+ mHandle = nullptr;
+ }
+ mQuantum = other.mQuantum;
+ mFlags = other.mFlags;
+
if (other.mHandle != nullptr) {
mHandle = native_handle_create(
other.mHandle->numFds, other.mHandle->numInts);
@@ -231,6 +236,8 @@ MQDescriptor<T, flavor>::MQDescriptor(const MQDescriptor<T, flavor> &other)
&other.mHandle->data[other.mHandle->numFds],
other.mHandle->numInts * sizeof(int));
}
+
+ return *this;
}
template<typename T, MQFlavor flavor>