blob: 4d493dd8159c1af64f9d9ab9cd0fb58af5409983 [file] [log] [blame]
diff --git a/platform2/aosp/system/libfmq/include/fmq/MessageQueueBase.h b/platform2/aosp/system/libfmq/include/fmq/MessageQueueBase.h
index 0cb83a6..0df8104 100644
--- a/platform2/aosp/system/libfmq/include/fmq/MessageQueueBase.h
+++ b/platform2/aosp/system/libfmq/include/fmq/MessageQueueBase.h
@@ -19,6 +19,7 @@
#include <cutils/ashmem.h>
#include <fmq/EventFlag.h>
#include <sys/mman.h>
+#include <unistd.h>
#include <utils/Log.h>
#include <utils/SystemClock.h>
#include <atomic>
@@ -231,6 +232,10 @@ struct MessageQueueBase {
struct MemRegion {
MemRegion() : MemRegion(nullptr, 0) {}
+ MemRegion(const MemRegion& other) {
+ *this = other;
+ }
+
MemRegion(T* base, size_t size) : address(base), length(size) {}
MemRegion& operator=(const MemRegion& other) {
@@ -576,7 +581,9 @@ void MessageQueueBase<MQDescriptorType, T, flavor>::initMemory(bool resetPointer
const auto& grantors = mDesc->grantors();
for (const auto& grantor : grantors) {
if (hardware::details::isAlignedToWordBoundary(grantor.offset) == false) {
+#ifdef __BIONIC__
__assert(__FILE__, __LINE__, "Grantor offsets need to be aligned");
+#endif
}
}
@@ -661,9 +668,10 @@ MessageQueueBase<MQDescriptorType, T, flavor>::MessageQueueBase(size_t numElemen
* kQueueSizeBytes needs to be aligned to word boundary so that all offsets
* in the grantorDescriptor will be word aligned.
*/
+ size_t page_size = static_cast<size_t>(sysconf(_SC_PAGE_SIZE));
size_t kAshmemSizePageAligned = (hardware::details::alignToWordBoundary(kQueueSizeBytes) +
- kMetaDataSize + PAGE_SIZE - 1) &
- ~(PAGE_SIZE - 1);
+ kMetaDataSize + page_size - 1) &
+ ~(page_size - 1);
/*
* Create an ashmem region to map the memory for the ringbuffer,
@@ -1172,7 +1180,8 @@ void* MessageQueueBase<MQDescriptorType, T, flavor>::mapGrantorDescr(uint32_t gr
/*
* Offset for mmap must be a multiple of PAGE_SIZE.
*/
- int mapOffset = (grantors[grantorIdx].offset / PAGE_SIZE) * PAGE_SIZE;
+ size_t page_size = static_cast<size_t>(sysconf(_SC_PAGE_SIZE));
+ int mapOffset = (grantors[grantorIdx].offset / page_size) * page_size;
int mapLength = grantors[grantorIdx].offset - mapOffset + grantors[grantorIdx].extent;
void* address = mmap(0, mapLength, PROT_READ | PROT_WRITE, MAP_SHARED, handle->data[fdIndex],
@@ -1192,7 +1201,8 @@ void MessageQueueBase<MQDescriptorType, T, flavor>::unmapGrantorDescr(void* addr
return;
}
- int mapOffset = (grantors[grantorIdx].offset / PAGE_SIZE) * PAGE_SIZE;
+ size_t page_size = static_cast<size_t>(sysconf(_SC_PAGE_SIZE));
+ int mapOffset = (grantors[grantorIdx].offset / page_size) * page_size;
int mapLength = grantors[grantorIdx].offset - mapOffset + grantors[grantorIdx].extent;
void* baseAddress =
reinterpret_cast<uint8_t*>(address) - (grantors[grantorIdx].offset - mapOffset);