File 0004-QPID-3650-Avoid-unaligned-memory-access.patch of Package qpid
From 19fb389223e423bb6c77b67c3a76718c295c40be Mon Sep 17 00:00:00 2001
From: Andrew Stitcher <astitcher@apache.org>
Date: Wed, 11 Jun 2014 17:47:37 +0000
Subject: [PATCH 4/4] QPID-3650: Avoid unaligned memory access
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1601969 13f79535-47bb-0310-9956-ffa450edef68
---
qpid/cpp/src/qpid/sys/rdma/RdmaClient.cpp | 8 ++++----
qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h | 11 +++++++++++
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/qpid/cpp/src/qpid/sys/rdma/RdmaClient.cpp b/qpid/cpp/src/qpid/sys/rdma/RdmaClient.cpp
index 38e9b59..504000a 100644
--- a/qpid/cpp/src/qpid/sys/rdma/RdmaClient.cpp
+++ b/qpid/cpp/src/qpid/sys/rdma/RdmaClient.cpp
@@ -97,8 +97,8 @@ void write(Rdma::AsynchIO& aio) {
Rdma::Buffer* b = aio.getSendBuffer();
if (!b) break;
b->dataCount(msgsize);
- uint32_t* ip = reinterpret_cast<uint32_t*>(b->bytes());
- uint32_t* lip = ip + b->dataCount() / sizeof(uint32_t);
+ uint32_t* ip = b->words();
+ uint32_t* lip = ip + b->wordCount();
while (ip != lip) {*ip++ = *output; ++output;}
aio.queueWrite(b);
++smsgs;
@@ -116,8 +116,8 @@ void data(Poller::shared_ptr p, Rdma::AsynchIO& aio, Rdma::Buffer* b) {
// Check message is unaltered
bool match = true;
- uint32_t* ip = reinterpret_cast<uint32_t*>(b->bytes());
- uint32_t* lip = ip + b->dataCount() / sizeof(uint32_t);
+ uint32_t* ip = b->words();
+ uint32_t* lip = ip + b->wordCount();
while (ip != lip) { if (*ip++ != *input) {match = false; break;} ++input;}
if (!match) {
cout << "Data doesn't match: at msg " << rmsgs << " byte " << rbytes-b->dataCount() << " (ish)\n";
diff --git a/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h b/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h
index 5f84793..5d9b681 100644
--- a/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h
+++ b/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h
@@ -53,7 +53,9 @@ namespace Rdma {
friend class QueuePairEvent;
char* bytes() const;
+ uint32_t* words() const;
int32_t byteCount() const;
+ int32_t wordCount() const;
int32_t dataCount() const;
void dataCount(int32_t);
@@ -68,11 +70,20 @@ namespace Rdma {
return (char*) sge.addr;
}
+ inline uint32_t* Buffer::words() const {
+ return (uint32_t*) sge.addr;
+ }
+
/** return the number of bytes available for application data */
inline int32_t Buffer::byteCount() const {
return bufferSize - reserved;
}
+ /** return the number of words available for application data */
+ inline int32_t Buffer::wordCount() const {
+ return (bufferSize - reserved) / sizeof(uint32_t);
+ }
+
inline int32_t Buffer::dataCount() const {
return sge.length;
}
--
1.9.3